libc

package
v0.0.0-...-f2053fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

The libc package implements various functions from the C standard library in Go.

Index

Constants

This section is empty.

Variables

View Source
var (
	ClassTypeInfoVT    [4]unsafe.Pointer
	SIClassTypeInfoVT  [4]unsafe.Pointer
	VMIClassTypeInfoVT [4]unsafe.Pointer
)

Itanium type_info vtables. User IR stores GEP(@VT, 2) as the type_info vptr. DynamicCast compares that word to identify class / si / vmi.

Functions

func Abort

func Abort()

Abort is C abort(): no-return process abort.

func AbsI32

func AbsI32(x int32) int32

AbsI32 is llvm.abs.i32. INT_MIN stays INT_MIN (two's complement wrap).

func AbsI64

func AbsI64(x int64) int64

AbsI64 is llvm.abs.i64 (INT64_MIN stays).

func AddPointer

func AddPointer[T any](ptr *T, offset int) *T

AddPointer is p + i (C pointer arithmetic, scaled).

func Addr

func Addr[T any](p *T) uintptr

Addr is (uintptr)p. Map keys, nil-safe.

func Alloca

func Alloca[T any](count, size int64) *T

Alloca is LLVM alloca: mmap bump stack, not the malloc slab. Sharing malloc's freelist zeroed a still-referenced object (Darwin seed 42: Expression vptr=0, virtual call at +0x50). Codegen defers AllocaFree (LIFO, same as C stack).

func AllocaFree

func AllocaFree(p *byte)

AllocaFree pops one Alloca. Must be LIFO (defer).

func Arc4randomBuf

func Arc4randomBuf(buf *byte, n int64)

Arc4randomBuf is BSD arc4random_buf(buf, n): fill n bytes from the CSPRNG.

func Argv

func Argv() unsafe.Pointer

Argv is C argv: pointer to a nil-terminated list of *byte (os.Args).

func As

func As[T any](p unsafe.Pointer) *T

As is (T *)p.

func AssertFail

func AssertFail(expr, file *byte, line int32, function *byte)

AssertFail is glibc/clang __assert_fail(expr, file, line, function). Noreturn in C; panic in Go so control-flow after it typechecks.

func AssertRtn

func AssertRtn(function, file *byte, line int32, expr *byte)

AssertRtn is Darwin __assert_rtn(func, file, line, expr).

func AtomicAddI8

func AtomicAddI8(addr *byte, delta byte) byte

AtomicAddI8 is atomicrmw add on i8. Returns the new value (like AddInt32).

func AtomicCASI8

func AtomicCASI8(addr *byte, old, neu byte) bool

AtomicCASI8 is cmpxchg on i8 (returns whether the swap happened).

func AtomicLoadI8

func AtomicLoadI8(addr *byte) byte

AtomicLoadI8 is the load half of a failed cmpxchg on i8.

func AtomicSwapI8

func AtomicSwapI8(addr *byte, neu byte) byte

AtomicSwapI8 is atomicrmw xchg on i8. Go has no SwapInt8; CAS the aligned 32-bit word that holds the byte (same approach as LLVM on targets without native 8-bit atomics).

func Bytes

func Bytes(p *byte, n int) []byte

Bytes is a C buffer (p, n). n<=0 yields nil.

func Calloc

func Calloc[T any](count, size int64) *T

Calloc allocates count*size zeroed bytes (C calloc).

func Close

func Close(fd int32) int32

Close is close(fd).

func CtypeBLoc

func CtypeBLoc() **int16

CtypeBLoc is glibc __ctype_b_loc(): returns a pointer to the ctype bitmask table.

func CtypeWiden

func CtypeWiden(this unsafe.Pointer, c byte) byte

CtypeWiden is ctype<char>::widen. Identity; this may be nil when use_facet was inlined against a dummy locale.

func CtypeWidenInit

func CtypeWidenInit(this *byte)

CtypeWidenInit is ctype<char>::_M_widen_init. Identity table, widen_ok=1.

func CxaAtexit

func CxaAtexit(fn, arg, dso *byte) int32

CxaAtexit is __cxa_atexit(fn, arg, dso). C++ static dtors register here from llvm.global_ctors. dso is ignored: we never unload.

func CxxNoop

func CxxNoop(this *byte) unsafe.Pointer

CxxNoop is a declare-only C++ dtor we never constructed a real object for (locale, ios_base, __basic_file).

func Dlsym

func Dlsym(handle, name *byte) *byte

Dlsym is dlsym(3). Always nil so rust getrandom uses the file backend (calling a Go func through a C fnptr cast is not defined).

func Dup

func Dup(fd int32) int32

Dup is C dup(fd). Pure-Go: only maps 0/1/2 to themselves; other FDs return -1 (tree-sitter uses this for print-dot-graph on std FDs).

func DynamicCast

func DynamicCast(src, srcType, dstType *byte, src2dst int64) *byte

DynamicCast is Itanium __dynamic_cast(src, src_type, dst_type, src2dst). Null src is a null result (ABI). A missing vtable or unknown type_info kind panics so the unsatisfied signal is not turned into a silent null.

func ErrnoLocation

func ErrnoLocation() *int32

ErrnoLocation is __errno_location.

func Exit

func Exit(status int32)

Exit is C exit(status). Runs __cxa_atexit handlers first.

func Fclose

func Fclose(f *os.File) int32

Fclose is C fclose. Does not close stdin/stdout/stderr.

func Fcntl

func Fcntl(fd int32, cmd int32, args ...any) int32

Fcntl is fcntl(2). The libc fd is looked up, then the host fcntl runs on that *os.File (unix.FcntlInt via SyscallConn).

func Fdopen

func Fdopen(fd int32, mode *byte) *os.File

Fdopen is C fdopen(fd, mode). Maps 0/1/2 to stdin/stdout/stderr; other FDs use os.NewFile. Mode is accepted but not fully applied.

func Fence

func Fence()

Fence is LLVM `fence <ordering>`. rustc emits `fence acquire` before Arc::drop_slow so the last refcount decrement is visible. Same barrier as empty asm ~{memory}.

func FilebufClose

func FilebufClose(this *byte) unsafe.Pointer

FilebufClose is basic_filebuf::close. O2 inlines ifstream::close as filebuf::close(this+16). Return this (non-null) on success.

func FilebufOpen

func FilebufOpen(this *byte, path *byte, mode int32) unsafe.Pointer

FilebufOpen is basic_filebuf::open. Slurps the file into the get area so inlined sgetc/getline can read without underflow. Returns this on success, nil on failure (libc++).

func FilebufUnderflow

func FilebufUnderflow(this *byte) int32

FilebufUnderflow is basic_filebuf::underflow. Get area already holds the file; empty means EOF.

func Fprintf

func Fprintf(stream *os.File, format *byte, args ...any) int32

Fprintf is C fprintf(stream, format, ...).

func Fputc

func Fputc(c int32, stream *os.File) int32

Fputc is C fputc(c, stream).

func Fputs

func Fputs(s *byte, stream *os.File) int32

Fputs is C fputs(s, stream).

func Free

func Free(p *byte)

Free is C free(p). All heap traffic (malloc, RustAlloc, operator new with align≤16) shares the modernc slab.

func Fstat64

func Fstat64(fd int32, st *byte) int32

Fstat64 is fstat64 — zero-fill and succeed (size fields left 0).

func FuncCode

func FuncCode[F any](fn F) unsafe.Pointer

FuncCode is the code word of a Go func. Inverse of FuncFromCode. Used for C++ atexit slots and rustc vtable method pointers.

func FuncFromCode

func FuncFromCode[F any](code unsafe.Pointer) F

FuncFromCode rebuilds a Go func from a code word (nil closure data).

func Getauxval

func Getauxval(typ int64) int64

Getauxval is getauxval(3). AT_MINSIGSTKSZ=51, AT_PAGESIZE=6.

func Getchar

func Getchar() int32

func Getcwd

func Getcwd(buf *byte, size int64) *byte

Getcwd is getcwd(3).

func Getentropy

func Getentropy(buf *byte, n int64) int32

Getentropy is getentropy(2). n must be ≤ 256.

func Getenv

func Getenv(name *byte) *byte

Getenv is getenv(3). Always nil (no process env for fixtures).

func Getpid

func Getpid() int32

Getpid is getpid(2).

func Getrandom

func Getrandom(buf *byte, buflen int64, flags int32) int64

Getrandom is getrandom(2).

func Gettid

func Gettid() int32

Gettid is gettid(2). Single-threaded: same as pid 1 stand-in.

func GoString

func GoString(s *byte) string

GoString returns s converted from a C string to a Go string.

func I1Pack8

func I1Pack8(v [8]bool) byte

I1Pack8 packs <8 x i1> (lane 0 = low bit) to i8. rustc SIMD icmp masks.

func I1Pack16

func I1Pack16(v [16]bool) int16

I1Pack16 packs <16 x i1> to i16.

func I1Pack32

func I1Pack32(v [32]bool) int32

I1Pack32 packs <32 x i1> to i32.

func I1Pack64

func I1Pack64(v [64]bool) int64

I1Pack64 packs <64 x i1> to i64.

func I1Unpack8

func I1Unpack8(m byte) (v [8]bool)

I1Unpack8 is bitcast i8 to <8 x i1>.

func I1Unpack16

func I1Unpack16(m int16) (v [16]bool)

I1Unpack16 is bitcast i16 to <16 x i1>.

func I1Unpack32

func I1Unpack32(m int32) (v [32]bool)

I1Unpack32 is bitcast i32 to <32 x i1>.

func I1Unpack64

func I1Unpack64(m int64) (v [64]bool)

I1Unpack64 is bitcast i64 to <64 x i1>.

func I128Eq

func I128Eq(a, b I128) bool

func I128Ne

func I128Ne(a, b I128) bool

func I128Sge

func I128Sge(a, b I128) bool

func I128Sgt

func I128Sgt(a, b I128) bool

func I128Sle

func I128Sle(a, b I128) bool

func I128Slt

func I128Slt(a, b I128) bool

func I128TruncI1

func I128TruncI1(a I128) bool

func I128TruncI8

func I128TruncI8(a I128) byte

func I128TruncI16

func I128TruncI16(a I128) int16

func I128TruncI32

func I128TruncI32(a I128) int32

func I128TruncI64

func I128TruncI64(a I128) int64

func I128Uge

func I128Uge(a, b I128) bool

func I128Ugt

func I128Ugt(a, b I128) bool

func I128Ule

func I128Ule(a, b I128) bool

func I128Ult

func I128Ult(a, b I128) bool

func I256Eq

func I256Eq(a, b I256) bool

func I256Ne

func I256Ne(a, b I256) bool

func I256Sge

func I256Sge(a, b I256) bool

func I256Sgt

func I256Sgt(a, b I256) bool

func I256Sle

func I256Sle(a, b I256) bool

func I256Slt

func I256Slt(a, b I256) bool

func I256TruncI1

func I256TruncI1(a I256) bool

func I256TruncI8

func I256TruncI8(a I256) byte

func I256TruncI16

func I256TruncI16(a I256) int16

func I256TruncI32

func I256TruncI32(a I256) int32

func I256TruncI64

func I256TruncI64(a I256) int64

func I256Uge

func I256Uge(a, b I256) bool

func I256Ugt

func I256Ugt(a, b I256) bool

func I256Ule

func I256Ule(a, b I256) bool

func I256Ult

func I256Ult(a, b I256) bool

func IfstreamClose

func IfstreamClose(this *byte) unsafe.Pointer

IfstreamClose is ifstream::close / D1 destructor.

func IfstreamCloseVTT

func IfstreamCloseVTT(this *byte, vtt *byte) unsafe.Pointer

IfstreamCloseVTT is D2(this, vtt).

func IfstreamOpen

func IfstreamOpen(this *byte, path *byte, mode int32) unsafe.Pointer

IfstreamOpen is basic_ifstream::basic_ifstream(char const*, ios_openmode). Opens the path for real. fail is set if open fails. mode is recorded only as in/out; unknown bits fail the stream instead of pretending.

func InitOstream

func InitOstream(this unsafe.Pointer)

InitOstream writes the stand-in Itanium vptr and ctype<char>. clang++ -O2 endl: off = *(vptr-24); ios = this+off; ctype = *(ios+240); null ctype → __throw_bad_cast (OutputMgr::OutputHeader).

func InlineAsm

func InlineAsm(asm, constraint string)

InlineAsm is LLVM `call asm`. The rustc compiler barrier (`""` / `~{memory}`) is an atomic fence so the call is not deleted. Any other template panics with the asm text.

func IosBaseCtor

func IosBaseCtor(this *byte) unsafe.Pointer

IosBaseCtor is std::ios_base::ios_base() / _M_init / basic_ios::init. gensym's stack ostringstream calls this before operator<< / str(). Same stand-in vptr and ctype as cout so inlined fail/endl stay honest.

func IosBool

func IosBool(this *byte) bool

IosBool is basic_ios::operator bool (true if the stream is good).

func IosClear

func IosClear(this *byte, state int32)

IosClear is basic_ios::clear(iostate). Writes the inlined iostate slot and updates the side table so later fail/eof loads stay honest.

func IosEof

func IosEof(this *byte) bool

IosEof is basic_ios::eof.

func IosFail

func IosFail(this *byte) bool

IosFail is basic_ios::fail.

func IosGetloc

func IosGetloc(ret *byte, _ ...any) unsafe.Pointer

IosGetloc is ios_base::getloc(). Writes a dummy locale into the sret slot (first arg) when clang returns locale by value.

func IosNot

func IosNot(this *byte) bool

IosNot is basic_ios::operator!.

func IosPrecisionSet

func IosPrecisionSet(this *byte, n int64) int64

IosPrecisionSet is ios_base::precision(streamsize).

func IstreamApplyIosManip

func IstreamApplyIosManip(is *byte, _ *byte) *byte

IstreamApplyIosManip is istream::operator>>(ios_base&(*)(ios_base&)). str2int only feeds std::hex; set base 16. The function pointer is ignored.

func IstreamExtractI32

func IstreamExtractI32(is *byte, out *byte) *byte

IstreamExtractI32 is istream::operator>>(int&). Parses the next integer from the stringstream side table with the current base. out is the address of an i32 (opaque ptr in IR → *byte here).

func IstreamGetline

func IstreamGetline(is, str *byte) *byte

IstreamGetline is std::getline(istream&, string&). Reads one line from the ifstream side table into a libstdc++ string. Missing stream fails (no fake success). Existing fail/eof bits are kept; eof is set when extraction stops at EOF or the stream was already bad.

func IstreamSentryCtor

func IstreamSentryCtor(this *byte, is *byte, _ bool) unsafe.Pointer

IstreamSentryCtor is basic_istream::sentry::sentry(istream&, bool).

func Iswalnum

func Iswalnum(c int32) int32

Iswalnum is C iswalnum(c) from <wctype.h>.

func Iswalpha

func Iswalpha(c int32) int32

Iswalpha is C iswalpha(c) from <wctype.h>.

func Iswblank

func Iswblank(c int32) int32

Iswblank is C iswblank(c) from <wctype.h>.

func Iswcntrl

func Iswcntrl(c int32) int32

Iswcntrl is C iswcntrl(c) from <wctype.h>.

func Iswdigit

func Iswdigit(c int32) int32

Iswdigit is C iswdigit(c) from <wctype.h>.

func Iswlower

func Iswlower(c int32) int32

Iswlower is C iswlower(c) from <wctype.h>.

func Iswspace

func Iswspace(c int32) int32

Iswspace is C iswspace(c) from <wctype.h>.

func Iswupper

func Iswupper(c int32) int32

Iswupper is C iswupper(c) from <wctype.h>.

func Iswxdigit

func Iswxdigit(c int32) int32

Iswxdigit is C iswxdigit(c) from <wctype.h>.

func LibcxxTreeConstructFromTree

func LibcxxTreeConstructFromTree(tree, src, construct *byte) *byte

LibcxxTreeConstructFromTree is __tree::__construct_from_tree. tree and construct are unused (allocator / lambda); we malloc and memcpy the pair ourselves.

Inlined insert may write pair<K,V> at +0, so __right_ is a small integer and __left_ is the key pointer. Do not walk those; copy the pair onto dest+32 and emit a leaf.

func LibcxxTreeGetValue

func LibcxxTreeGetValue(this *byte) *byte

LibcxxTreeGetValue is __tree_node::__get_value. Returns this+32, or nil when this is not a user pointer (so a leftover unsigned in a child slot does not SEGV).

func LibcxxTreeMin

func LibcxxTreeMin(x *byte) *byte

LibcxxTreeMin is std::__tree_min.

func LibcxxTreeNext

func LibcxxTreeNext(x *byte) *byte

LibcxxTreeNext is std::__tree_next. Bad child pointers (overlay unsigned / key) are treated as null so increment cannot hang.

func LibcxxTreePrev

func LibcxxTreePrev(x *byte) *byte

LibcxxTreePrev is std::__tree_prev_iter. x may be the end node (only __left_ is meaningful).

func Load

func Load[T any](p unsafe.Pointer, off int) T

Load is *(T *)((char *)p + off).

func LoadRelativeI64

func LoadRelativeI64(p unsafe.Pointer, off int64) unsafe.Pointer

LoadRelativeI64 is llvm.load.relative.i64: load i32 at ptr+offset, return ptr+i32.

func LocaleCtor

func LocaleCtor(this *byte) unsafe.Pointer

LocaleCtor is std::locale::locale() (default and copy). gensym's ostringstream constructs a locale after ios_base; we do not reconstruct facets (ctype is already on the ios object).

func LocaleDtor

func LocaleDtor(this *byte) unsafe.Pointer

LocaleDtor is libc++ locale::~locale.

func LocaleUseFacet

func LocaleUseFacet(loc *byte, id *byte) unsafe.Pointer

LocaleUseFacet is locale::use_facet(id&). Returns the stand-in ctype.

func Lrand48

func Lrand48() int64

Lrand48 is POSIX lrand48(3): bits 47..1 of the next Xi (31 bits).

func Lseek64

func Lseek64(fd int32, offset int64, whence int32) int64

Lseek64 is lseek64.

func Malloc

func Malloc[T any](n int64) *T

Malloc allocates n bytes (C malloc). n==0 allocates 1 byte, like musl/gnulib.

func MarkStdoutStream

func MarkStdoutStream(this unsafe.Pointer)

MarkStdoutStream records cout/cerr so writeOstream does not capture them.

func MaximumNumF64

func MaximumNumF64(a, b float64) float64

MaximumNumF64 is llvm.maximumnum.f64 (IEEE 754-2019 maximumNumber). rustc emits this for f64::max: NaN is ignored; -0.0 is less than +0.0.

func Memchr

func Memchr(s *byte, c int32, n int64) *byte

Memchr returns a pointer to the first occurrence of c in string s. It returns nil if no such byte exists within n bytes.

func Memcmp

func Memcmp(s1 *byte, s2 *byte, n int64) int32

func MemcpyChk

func MemcpyChk(dest *byte, src *byte, length int64, destlen int64) *byte

MemcpyChk copies length bytes from src to dest. If length is greater than destlen (interpreted as unsigned integers), it will panic.

func Memmove

func Memmove(dst *byte, src *byte, length int64) *byte

Memmove copies length bytes from src to dst. The blocks of memory may overlap.

func Memset

func Memset(b *byte, c byte, length int64) *byte

Memset fills the memory at b with bytes of the value c.

func MemsetChk

func MemsetChk(b *byte, c byte, length int64, destlen int64) *byte

MemsetChk fills the memory at b with bytes of the value c. If length is greater than destlen (interpreted as unsigned integers), it will panic.

func MemsetPattern16

func MemsetPattern16(b *byte, pattern16 *byte, length int64)

MemsetPattern16 fills the memory at b with a 16-byte pattern.

func Mmap

func Mmap(addr any, length int64, prot, flags, fd int32, offset int64) unsafe.Pointer

Mmap is mmap(2). Same as Mmap64.

func Mmap64

func Mmap64(addr any, length int64, prot, flags, fd int32, offset int64) unsafe.Pointer

Mmap64 is mmap64. addr is taken as an integer so a non-heap MAP_FIXED address is not a Go *byte the GC can nil.

func Mprotect

func Mprotect(addr *byte, length int64, prot int32) int32

Mprotect is mprotect(2). Always succeeds in this model.

func Munmap

func Munmap(addr *byte, length int64) int32

Munmap is munmap(2).

func NSGetArgc

func NSGetArgc() unsafe.Pointer

NSGetArgc is Darwin _NSGetArgc. Returns *int.

func NSGetArgv

func NSGetArgv() unsafe.Pointer

NSGetArgv is Darwin _NSGetArgv. Returns char ***.

func NSGetEnviron

func NSGetEnviron() unsafe.Pointer

NSGetEnviron is Darwin _NSGetEnviron. Returns char *** (empty).

func NSGetProgname

func NSGetProgname() unsafe.Pointer

NSGetProgname is Darwin _NSGetProgname. Returns char **.

func OStringStreamClose

func OStringStreamClose(this *byte) unsafe.Pointer

OStringStreamClose is basic_ostringstream dtor.

func OStringStreamCtor

func OStringStreamCtor(this *byte) unsafe.Pointer

OStringStreamCtor is basic_ostringstream default ctor (gensym). Object is ~112 bytes; do not InitOstream (ctype at +240).

func OStringStreamStr

func OStringStreamStr(ret, this *byte)

OStringStreamStr is basic_ostringstream::str() / stringstream::str() → string.

func Off

func Off(p unsafe.Pointer, n int) unsafe.Pointer

Off is (char *)p + n.

func Open

func Open(path *byte, flags int32, mode ...int32) int32

Open is open/open64(path, flags[, mode]). Returns fd or -1.

func Open64

func Open64(path *byte, flags int32, mode ...int32) int32

Open64 is open64 — same as Open.

func OssVptr

func OssVptr() unsafe.Pointer

OssVptr is the ostringstream/stringstream vptr (vbase offset 112).

func OstreamEndl

func OstreamEndl(out *byte) *byte

OstreamEndl is std::endl. Writes '\n'; flush is a no-op on stdout.

func OstreamFlush

func OstreamFlush(out *byte) *byte

OstreamFlush is ostream::flush. stdout is unbuffered here.

func OstreamInsert

func OstreamInsert(out *byte, s *byte, n int64) *byte

OstreamInsert is std::__ostream_insert<char>(ostream&, char const*, long). csmith OutputMgr::OutputHeader writes the generated program header through this. Unknown streams go to stdout (DefaultOutputMgr::get_main_out is cout); registered ostringstreams append.

func OstreamInsertBool

func OstreamInsertBool(out *byte, v bool) *byte

OstreamInsertBool is operator<<(ostream&, bool) without boolalpha.

func OstreamInsertF64

func OstreamInsertF64(out *byte, x float64) *byte

OstreamInsertF64 is operator<<(ostream&, double) / float.

func OstreamInsertI64

func OstreamInsertI64(out *byte, n int64) *byte

OstreamInsertI64 is ostream::_M_insert<long> / operator<<(long).

func OstreamInsertPtr

func OstreamInsertPtr(out *byte, p unsafe.Pointer) *byte

OstreamInsertPtr is operator<<(ostream&, void const*). libstdc++ prints the address as hex with a 0x prefix.

func OstreamInsertU64

func OstreamInsertU64(out *byte, n uint64) *byte

OstreamInsertU64 is ostream::_M_insert<unsigned long>.

func OstreamLsCStr

func OstreamLsCStr(out *byte, s *byte) *byte

OstreamLsCStr is operator<<(ostream&, char const*).

func OstreamLsString

func OstreamLsString(out *byte, s *byte) *byte

OstreamLsString is operator<<(ostream&, basic_string const&).

func OstreamPut

func OstreamPut(out *byte, c byte) *byte

OstreamPut is ostream::put(char) / operator<<(char).

func OstreamSentryCtor

func OstreamSentryCtor(this *byte, os *byte) unsafe.Pointer

OstreamSentryCtor is basic_ostream::sentry::sentry(ostream&).

func OstreamSentryDestroy

func OstreamSentryDestroy(this *byte) unsafe.Pointer

OstreamSentryDestroy is basic_ostream::sentry::~sentry.

func Poll

func Poll(fds *byte, nfds int64, timeout int32) int32

Poll is poll(2). pollfd is {i32 fd; i16 events; i16 revents} (8 bytes). Marks every slot ready (revents=events) so rhai-run stdin checks proceed.

func Printf

func Printf(format *byte, args ...any) int32

func PthreadAttrDestroy

func PthreadAttrDestroy(attr *byte) int32

PthreadAttrDestroy is a no-op for the dummy attr.

func PthreadAttrGetstack

func PthreadAttrGetstack(attr, stackaddr *byte, stacksize *byte) int32

PthreadAttrGetstack reports a synthetic stack for stack-overflow guards.

func PthreadGetStackaddrNp

func PthreadGetStackaddrNp(thread int64) unsafe.Pointer

PthreadGetStackaddrNp is Darwin pthread_get_stackaddr_np. Darwin returns the top of the stack (highest address); rustc subtracts get_stacksize_np to find the bottom before mmap MAP_FIXED of the guard.

func PthreadGetStacksizeNp

func PthreadGetStacksizeNp(thread int64) int64

PthreadGetStacksizeNp is Darwin pthread_get_stacksize_np.

func PthreadGetattrNp

func PthreadGetattrNp(thread int64, attr *byte) int32

PthreadGetattrNp fills a dummy attr (stack base/size via getstack).

func PthreadMutexDestroy

func PthreadMutexDestroy(m *byte) int32

func PthreadMutexInit

func PthreadMutexInit(m, attr *byte) int32

func PthreadMutexLock

func PthreadMutexLock(m *byte) int32

func PthreadMutexTrylock

func PthreadMutexTrylock(m *byte) int32

func PthreadMutexUnlock

func PthreadMutexUnlock(m *byte) int32

func PthreadMutexattrDestroy

func PthreadMutexattrDestroy(attr *byte) int32

func PthreadMutexattrInit

func PthreadMutexattrInit(attr *byte) int32

Single-threaded: mutex/attr calls succeed and do nothing.

func PthreadMutexattrSettype

func PthreadMutexattrSettype(attr *byte, typ int32) int32

func PthreadSelf

func PthreadSelf() int64

PthreadSelf is pthread_self. Single-threaded: fixed non-zero id.

func PthreadSetnameNp

func PthreadSetnameNp(_ ...any) int32

PthreadSetnameNp is Darwin pthread_setname_np(name) or POSIX (thread, name).

func PthreadThreadidNp

func PthreadThreadidNp(_ any, id *byte) int32

PthreadThreadidNp is Darwin pthread_threadid_np. Writes 1 into *id.

func Ptr

func Ptr[T any](p *T) unsafe.Pointer

Ptr is (void *)p.

func PtrMask

func PtrMask(p unsafe.Pointer, mask int64) unsafe.Pointer

PtrMask is llvm.ptrmask. mask is i64 so a constant -16 is a legal Go arg.

func Putc

func Putc(c int32, stream *os.File) int32

func Putchar

func Putchar(c int32) int32

func Puts

func Puts(s *byte) int32

func RbTreeDecrement

func RbTreeDecrement(x *byte) *byte

RbTreeDecrement is std::_Rb_tree_decrement.

func RbTreeIncrement

func RbTreeIncrement(x *byte) *byte

RbTreeIncrement is std::_Rb_tree_increment.

func RbTreeInit

func RbTreeInit(tree *byte)

RbTreeInit is the empty map / _Rb_tree default ctor. `tree` points at the _Rb_tree / map object (impl start). Header is at +8; left/right self-ref the header node (libstdc++ _Rb_tree_header::_M_reset).

func RbTreeInsertAndRebalance

func RbTreeInsertAndRebalance(insertLeft bool, x, p, header *byte)

RbTreeInsertAndRebalance is std::_Rb_tree_insert_and_rebalance (gcc libstdc++-v3/src/c++98/tree.cc).

func RbTreeRebalanceForErase

func RbTreeRebalanceForErase(z, header *byte) *byte

RbTreeRebalanceForErase is std::_Rb_tree_rebalance_for_erase (gcc libstdc++-v3/src/c++98/tree.cc). Returns the node to free (z). header is _M_header of the tree.

func Read

func Read(fd int32, buf *byte, n int64) int64

Read is read(fd, buf, n).

func Realloc

func Realloc(p *byte, n int64) *byte

Realloc is C realloc. n==0 frees p and returns nil. Grows via malloc+copy+free so the old block goes through freeQuarantine (modernc UintptrRealloc freelist-scribbles the old block immediately).

func Realpath

func Realpath(path *byte, resolved *byte) *byte

Realpath is realpath(3). resolved nil → malloc; else write into pathMax buf.

func RustAlloc

func RustAlloc(size, align int64) unsafe.Pointer

RustAlloc is __rust_alloc(size, align) and C++ operator new. Uses the same modernc slab as Malloc/Free (no Go-heap make+pin). size==0 returns a non-null dangling pointer (rustc / C++ convention).

func RustAllocZeroed

func RustAllocZeroed(size, align int64) unsafe.Pointer

RustAllocZeroed is __rust_alloc_zeroed: slab alloc then clear.

func RustDealloc

func RustDealloc(p unsafe.Pointer, size, align int64)

RustDealloc is __rust_dealloc / operator delete. Same slab as Free.

func RustFmtI32

func RustFmtI32(val, _ unsafe.Pointer) bool

RustFmtI32 is <i32 as core::fmt::Display>::fmt. Ok is false (i1 0).

func RustFmtUsize

func RustFmtUsize(val, _ unsafe.Pointer) bool

RustFmtUsize is <usize as core::fmt::Display>::fmt.

func RustPrint

func RustPrint(tmpl, args unsafe.Pointer)

RustPrint is std::io::stdio::_print(template, args). Template encoding: rustc 1.97 fmt::Arguments (byte pieces + 0xC0 placeholders).

func RustRealloc

func RustRealloc(p unsafe.Pointer, oldSize, align, newSize int64) unsafe.Pointer

RustRealloc is __rust_realloc(ptr, oldSize, align, newSize).

func SAddWithOverflowI32

func SAddWithOverflowI32(a, b int32) struct {
	F0 int32
	F1 bool
}

SAddWithOverflowI32 is llvm.sadd.with.overflow.i32: wrapping sum and signed overflow.

func SMaxI32

func SMaxI32(a, b int32) int32

SMaxI32 is llvm.smax.i32.

func SMaxI64

func SMaxI64(a, b int64) int64

SMaxI64 is llvm.smax.i64.

func SMinI32

func SMinI32(a, b int32) int32

SMinI32 is llvm.smin.i32.

func SMinI64

func SMinI64(a, b int64) int64

SMinI64 is llvm.smin.i64.

func Scanf

func Scanf(format *byte, args ...any) int32

func Sigaction

func Sigaction(signum int32, act, oldact *byte) int32

Sigaction is sigaction(2). No-op success for rhai-run startup.

func Sigaltstack

func Sigaltstack(ss, oss *byte) int32

Sigaltstack is sigaltstack(2). Report existing stack (flags=0, not SS_DISABLE) so rustc stack_overflow::make_handler skips mmap. stack_t: { void *ss_sp; int ss_flags; size_t ss_size } @0,8,16.

func Signal

func Signal(sig int32, handler int64) int64

Signal is signal(2). Returns previous disposition (pretend SIG_DFL=0). rhai-run ignores SIGPIPE (13) with SIG_IGN (1).

func Snprintf

func Snprintf(buf *byte, n int64, format *byte, args ...any) int32

Snprintf is C snprintf(buf, n, format, ...).

func Srand48

func Srand48(seed int64)

Srand48 is POSIX srand48(3): Xi = (uint32(seed) << 16) | 0x330e.

func Sscanf

func Sscanf(str *byte, format *byte, args ...any) int32

Sscanf is C sscanf / glibc __isoc23_sscanf. Dest pointers from opaque-ptr IR arrive as *byte; write the scanned value through them.

func StandinVptr

func StandinVptr() unsafe.Pointer

StandinVptr is an Itanium vptr into ifstreamVT. vptr-24 is slot 0 (0). Declare-only VTTs store these so inlined dtors do not load nil-24.

func Stat64

func Stat64(path *byte, st *byte) int32

Stat64 is stat64 — same as fstat for our needs.

func Statx

func Statx(dirfd int32, pathname *byte, flags int32, mask int32, buf *byte) int32

Statx is Linux statx(2). rustc std FileAttr declares `extern_weak ... @statx` and calls it when the symbol exists. Fills Linux statx_t (stx_size at offset 40) from os.FileInfo.

func StdStringAppendCStr

func StdStringAppendCStr(s, cstr *byte, n int64) unsafe.Pointer

StdStringAppendCStr is libc++ string::append(char const*) / append(char const*, n). n<0 means strlen.

func StdStringAssign

func StdStringAssign(this *byte, other *byte) unsafe.Pointer

StdStringAssign is libc++ basic_string::operator=(basic_string const&).

func StdStringAssignCStr

func StdStringAssignCStr(s, cstr *byte, n int64) unsafe.Pointer

StdStringAssignCStr is libc++ string::assign(char const*) / assign(char const*, n). n<0 means strlen.

func StdStringCompareCStr

func StdStringCompareCStr(s *byte, pos, n int64, cstr *byte, n2 int64) int32

StdStringCompareCStr is libc++ string::compare(pos, n, cstr, n2).

func StdStringCopy

func StdStringCopy(this *byte, other *byte) unsafe.Pointer

StdStringCopy is libc++ basic_string(basic_string const&).

func StdStringDestroy

func StdStringDestroy(this *byte) unsafe.Pointer

StdStringDestroy is libc++ basic_string::~basic_string.

func StdStringEqCStr

func StdStringEqCStr(s, cstr *byte) bool

StdStringEqCStr is libc++ string == const char*.

func StdStringErase

func StdStringErase(s *byte, pos, n int64) unsafe.Pointer

StdStringErase is libc++ string::erase(pos, n). n<0 is npos.

func StdStringInit

func StdStringInit(this *byte, s *byte, n int64) unsafe.Pointer

StdStringInit is libc++ basic_string::__init(char const*, size_t).

func StdStringInsertCStr

func StdStringInsertCStr(s *byte, pos int64, cstr *byte, n int64) unsafe.Pointer

StdStringInsertCStr is libc++ string::insert(pos, char const*) / insert(pos, char const*, n). n<0 means strlen.

func StdStringPlusCStrLeft

func StdStringPlusCStrLeft(ret, cstr, s *byte)

StdStringPlusCStrLeft is operator+(char const*, string const&).

func StdStringPlusCStrRight

func StdStringPlusCStrRight(ret, s, cstr *byte)

StdStringPlusCStrRight is operator+(string const&, char const*).

func StdStringPushBack

func StdStringPushBack(s *byte, c byte) unsafe.Pointer

StdStringPushBack is libc++ string::push_back(char).

func StdStringSubstr

func StdStringSubstr(this, other *byte, pos, n int64, alloc *byte) unsafe.Pointer

StdStringSubstr is libc++ basic_string(s, pos, n, alloc). n<0 is npos.

func StdToString

func StdToString(ret *byte, v uint64)

StdToString is std::to_string(unsigned long) and the other unsigned integer overloads. ret is the LLVM sret string.

func StdToStringI

func StdToStringI(ret *byte, v int64)

StdToStringI is std::to_string(long) and the other signed overloads.

func Store

func Store[T any](p unsafe.Pointer, off int, v T)

Store is *(T *)((char *)p + off) = v.

func StrcatChk

func StrcatChk(dest *byte, src *byte, destlen int64) *byte

StrcatChk concatenates two C strings. It panics if the space required is more than destlen bytes.

func Strchr

func Strchr(s *byte, c int32) *byte

func Strcmp

func Strcmp(s1 *byte, s2 *byte) int32

func Strcpy

func Strcpy(s1 *byte, s2 *byte) *byte

func Strcspn

func Strcspn(s1 *byte, s2 *byte) int64

func StreambufCtor

func StreambufCtor(this *byte) unsafe.Pointer

StreambufCtor is basic_streambuf / basic_filebuf default ctor.

func StreambufSgetc

func StreambufSgetc(this *byte) int32

StreambufSgetc is basic_streambuf::sgetc. Reads the get area.

func StrerrorR

func StrerrorR(errnum int32, buf *byte, buflen int64) int32

StrerrorR is POSIX strerror_r (XSI: returns 0 or -1). Darwin rustc uses this for errno text; a short message in buf is enough.

func StringbufCtor

func StringbufCtor(this *byte) unsafe.Pointer

StringbufCtor is basic_stringbuf(openmode). Inlined stringstream ctor calls this; new_ctrl_vars then << 'i' into the put-area.

func StringbufStr

func StringbufStr(this, s *byte)

StringbufStr is libc++ basic_stringbuf::str(string const&). Fills the get area (inlined sgetc) and the stringstream table (>>).

func StringstreamClose

func StringstreamClose(this *byte) unsafe.Pointer

StringstreamClose is stringstream::~stringstream / D1.

func StringstreamCtor

func StringstreamCtor(this *byte, str *byte, mode int32) unsafe.Pointer

StringstreamCtor is basic_stringstream(string const&, ios_openmode). csmith StringUtils::str2int builds one to parse an int (dec or hex). Object is ~128 bytes; do not write ostream ctype at +240.

func StringstreamDefaultClose

func StringstreamDefaultClose(this *byte) unsafe.Pointer

StringstreamDefaultClose is basic_stringstream dtor (default or string ctor).

func StringstreamDefaultCtor

func StringstreamDefaultCtor(this *byte) unsafe.Pointer

StringstreamDefaultCtor is basic_stringstream() used by Variable::new_ctrl_vars. Registers both the object and the ostream subobject (+16) for <<.

func StringstreamStr

func StringstreamStr(ret, this *byte)

StringstreamStr is an alias of OStringStreamStr for mangling tables.

func Strlen

func Strlen(s *byte) int64

func Strncat

func Strncat(s1 *byte, s2 *byte, n int64) *byte

func Strncmp

func Strncmp(s1 *byte, s2 *byte, n int64) int32

func Strncpy

func Strncpy(s1 *byte, s2 *byte, n int64) *byte

func Strpbrk

func Strpbrk(s1 *byte, s2 *byte) *byte

func Strrchr

func Strrchr(s *byte, c int32) *byte

func Strspn

func Strspn(s1 *byte, s2 *byte) int64

func Strstr

func Strstr(s1 *byte, s2 *byte) *byte

func Syscall

func Syscall(nr int64, args ...interface{}) int64

Syscall is the libc syscall(2) shim for a few numbers rustc needs. Single-threaded: futex wait/wake are no-ops that succeed.

func Sysconf

func Sysconf(name int32) int64

Sysconf is sysconf(3). Darwin _SC_PAGESIZE is 29; Linux is 30.

func Towlower

func Towlower(c int32) int32

Towlower is C towlower(c) from <wctype.h>.

func Towupper

func Towupper(c int32) int32

Towupper is C towupper(c) from <wctype.h>.

func UAddSatU64

func UAddSatU64(a, b uint64) uint64

UAddSatU64 is llvm.uadd.sat for integer widths ≤64.

func UMaxU32

func UMaxU32(a, b int32) int32

UMaxU32 is llvm.umax.i32.

func UMaxU64

func UMaxU64(a, b int64) int64

UMaxU64 is llvm.umax.i64.

func UMinU32

func UMinU32(a, b int32) int32

UMinU32 is llvm.umin.i32.

func UMinU64

func UMinU64(a, b int64) int64

UMinU64 is llvm.umin.i64 (unsigned compare, i64 bit pattern).

func UMulWithOverflowU64

func UMulWithOverflowU64(a, b int64) struct {
	F0 int64
	F1 bool
}

UMulWithOverflowU64 is llvm.umul.with.overflow.i64.

func USubSatU64

func USubSatU64(a, b uint64) uint64

USubSatU64 is llvm.usub.sat for integer widths ≤64.

func VAArg

func VAArg(list *byte) *byte

VAArg returns a pointer to the next argument in a varargs list. The actual type of list is *[]interface{}, but it is declared as void * in C.

func VecReduceAddV4I32

func VecReduceAddV4I32(v [4]int32) int32

VecReduceAddV4I32 is llvm.vector.reduce.add.v4i32.

func Vsnprintf

func Vsnprintf(buf *byte, n int64, format *byte, ap *byte) int32

Vsnprintf is C vsnprintf. ap points at system va_list storage (__va_list_tag); llvm.va_start stores &varargs at overflow_arg_area (offset 8).

func Wmemchr

func Wmemchr(s *byte, c int32, n int64) *byte

Wmemchr is C wmemchr. wchar_t is 4 bytes except on Windows (2).

func Write

func Write(fd int32, buf *byte, n int64) int64

Write is write(fd, buf, n).

Types

type I128

type I128 struct {
	Lo uint64
	Hi uint64
}

I128 is LLVM i128 as two little-endian two's-complement limbs. rustc TypeId and i128 math use the full width; this is not int64.

func I128AShr

func I128AShr(a, n I128) I128

func I128Add

func I128Add(a, b I128) I128

func I128And

func I128And(a, b I128) I128

func I128FromI64

func I128FromI64(x int64) I128

I128FromI64 is sext of a 64-bit signed value to i128.

func I128FromU64

func I128FromU64(x uint64) I128

I128FromU64 is zext of a 64-bit unsigned value to i128.

func I128LShr

func I128LShr(a, n I128) I128

func I128Mul

func I128Mul(a, b I128) I128

func I128Or

func I128Or(a, b I128) I128

func I128SDiv

func I128SDiv(a, b I128) I128

func I128SRem

func I128SRem(a, b I128) I128

func I128Shl

func I128Shl(a, n I128) I128

func I128Sub

func I128Sub(a, b I128) I128

func I128UDiv

func I128UDiv(a, b I128) I128

func I128URem

func I128URem(a, b I128) I128

func I128Xor

func I128Xor(a, b I128) I128

func I256TruncI128

func I256TruncI128(a I256) I128

type I256

type I256 struct {
	Lo I128
	Hi I128
}

I256 is LLVM i256 as two little-endian I128 limbs. rustc core::fmt::num::__fmt_inner widens u128 to i256.

func I256AShr

func I256AShr(a, n I256) I256

func I256Add

func I256Add(a, b I256) I256

func I256And

func I256And(a, b I256) I256

func I256FromI64

func I256FromI64(x int64) I256

I256FromI64 is sext of a 64-bit signed value to i256.

func I256FromI128

func I256FromI128(x I128) I256

I256FromI128 is zext of i128 to i256.

func I256FromI128S

func I256FromI128S(x I128) I256

I256FromI128S is sext of i128 to i256.

func I256FromU64

func I256FromU64(x uint64) I256

I256FromU64 is zext of a 64-bit unsigned value to i256.

func I256LShr

func I256LShr(a, n I256) I256

func I256Mul

func I256Mul(a, b I256) I256

func I256Or

func I256Or(a, b I256) I256

func I256SDiv

func I256SDiv(a, b I256) I256

func I256SRem

func I256SRem(a, b I256) I256

func I256Shl

func I256Shl(a, n I256) I256

func I256Sub

func I256Sub(a, b I256) I256

func I256UDiv

func I256UDiv(a, b I256) I256

func I256URem

func I256URem(a, b I256) I256

func I256Xor

func I256Xor(a, b I256) I256

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL