mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Expose public garbage collector API for C language
You can now do epic things like this: puts(_gc(xasprintf("%d", 123))); The _gc() API is shorthand for _defer() which works like Go's keyword: const char *s = xasprintf("%d", 123); _defer(free, s); puts(s); Be sure to always use -fno-omit-frame-pointer which makes code fast too. Enjoy! See also #114
This commit is contained in:
parent
0ad609268f
commit
33e8fc8687
26 changed files with 192 additions and 182 deletions
|
@ -50,21 +50,22 @@ privileged noasan void __stack_chk_fail(void) {
|
|||
: "=S"(si), "=c"(cx)
|
||||
: "0"(msg), "1"(len), "d"(0x3F8 /* COM1 */)
|
||||
: "memory");
|
||||
triplf();
|
||||
asm("push\t$0\n\t"
|
||||
"push\t$0\n\t"
|
||||
"cli\n\t"
|
||||
"lidt\t(%rsp)");
|
||||
for (;;) asm("ud2");
|
||||
}
|
||||
if (NtGetVersion() < kNtVersionFuture) {
|
||||
do {
|
||||
asm volatile(
|
||||
"syscall"
|
||||
: "=a"(ax), "=c"(cx)
|
||||
: "0"(NtGetVersion() < kNtVersionWindows8
|
||||
? 0x0029
|
||||
: NtGetVersion() < kNtVersionWindows81
|
||||
? 0x002a
|
||||
: NtGetVersion() < kNtVersionWindows10 ? 0x002b
|
||||
: 0x002c),
|
||||
"1"(pushpop(-1L)), "d"(42)
|
||||
: "r11", "cc", "memory");
|
||||
asm volatile("syscall"
|
||||
: "=a"(ax), "=c"(cx)
|
||||
: "0"(NtGetVersion() < kNtVersionWindows8 ? 0x0029
|
||||
: NtGetVersion() < kNtVersionWindows81 ? 0x002a
|
||||
: NtGetVersion() < kNtVersionWindows10 ? 0x002b
|
||||
: 0x002c),
|
||||
"1"(pushpop(-1L)), "d"(42)
|
||||
: "r11", "cc", "memory");
|
||||
} while (!ax);
|
||||
}
|
||||
for (;;) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue