mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 12:18: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
|
@ -29,7 +29,7 @@
|
|||
// @assume system five nexgen32e abi conformant
|
||||
// @see examples/ctrlc.c
|
||||
// @noreturn
|
||||
gclongjmp:
|
||||
_gclongjmp:
|
||||
.leafprologue
|
||||
.profilable
|
||||
.weak __garbage
|
||||
|
@ -57,5 +57,4 @@ gclongjmp:
|
|||
2: pop %rsi
|
||||
pop %rdi
|
||||
jmp 0b
|
||||
.endfn gclongjmp,globl
|
||||
.source __FILE__
|
||||
.endfn _gclongjmp,globl
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
//
|
||||
// @param %rdi points to &(forcealign(16) uint8_t[256])[128]
|
||||
// @note modern cpus have out-of-order execution engines
|
||||
loadxmm:
|
||||
_loadxmm:
|
||||
.leafprologue
|
||||
movaps -0x80(%rdi),%xmm0
|
||||
movaps -0x70(%rdi),%xmm1
|
||||
|
@ -42,5 +42,4 @@ loadxmm:
|
|||
movaps 0x60(%rdi),%xmm14
|
||||
movaps 0x70(%rdi),%xmm15
|
||||
.leafepilogue
|
||||
.endfn loadxmm,globl,hidden
|
||||
.source __FILE__
|
||||
.endfn _loadxmm,globl,hidden
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// @noreturn
|
||||
// @assume system five nexgen32e abi conformant
|
||||
// @note code built w/ microsoft abi compiler can't call this
|
||||
// @see gclongjmp() unwinds gc() destructors
|
||||
// @see _gclongjmp() unwinds _gc() destructors
|
||||
longjmp:mov %esi,%eax
|
||||
test %eax,%eax
|
||||
jnz 1f
|
||||
|
|
|
@ -40,14 +40,14 @@ __nt2sysv:
|
|||
pushf
|
||||
ezlea _base,bx
|
||||
lea -0x80(%rbp),%rdi
|
||||
call savexmm
|
||||
call _savexmm
|
||||
mov %rcx,%rdi
|
||||
mov %rdx,%rsi
|
||||
mov %r8,%rdx
|
||||
mov %r9,%rcx
|
||||
call *%rax
|
||||
lea -0x80(%rbp),%rdi
|
||||
call loadxmm
|
||||
call _loadxmm
|
||||
popf
|
||||
pop %rsi
|
||||
pop %rdi
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
//
|
||||
// @param %rdi points to &(forcealign(16) uint8_t[256])[128]
|
||||
// @note modern cpus have out-of-order execution engines
|
||||
savexmm:
|
||||
_savexmm:
|
||||
.leafprologue
|
||||
movaps %xmm0,-0x80(%rdi)
|
||||
movaps %xmm1,-0x70(%rdi)
|
||||
|
@ -42,5 +42,4 @@ savexmm:
|
|||
movaps %xmm14,0x60(%rdi)
|
||||
movaps %xmm15,0x70(%rdi)
|
||||
.leafepilogue
|
||||
.endfn savexmm,globl,hidden
|
||||
.source __FILE__
|
||||
.endfn _savexmm,globl,hidden
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
// @returnstwice
|
||||
// @assume system five nexgen32e abi conformant
|
||||
// @note code built w/ microsoft abi compiler can't call this
|
||||
// @see longjmp(), gclongjmp()
|
||||
// @see longjmp(), _gclongjmp()
|
||||
setjmp: lea 8(%rsp),%rax
|
||||
mov %rax,(%rdi)
|
||||
mov %rbx,8(%rdi)
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/macros.internal.h"
|
||||
.real
|
||||
.source __FILE__
|
||||
.code16 # ∩ .code32 ∩ .code64
|
||||
|
||||
// Hoses interrupt descriptor table and triple-faults the system.
|
||||
//
|
||||
// @see youtu.be/GIKfEAF2Yhw?t=67
|
||||
// @mode long,legacy,real
|
||||
triplf: ud2
|
||||
push %bp
|
||||
mov %sp,%bp
|
||||
sub $8,%sp
|
||||
movpp %bp,%si
|
||||
lea -8(%bp),%di
|
||||
pushpop 8,%cx
|
||||
xor %ax,%ax
|
||||
rep stosb
|
||||
0: cli
|
||||
lidt -8(%bp)
|
||||
ud2
|
||||
jmp 0b
|
||||
.endfn triplf,globl,protected
|
Loading…
Add table
Add a link
Reference in a new issue