Initial import

This commit is contained in:
Justine Tunney 2020-06-15 07:18:57 -07:00
commit c91b3c5006
14915 changed files with 590219 additions and 0 deletions

32
libc/stubs/abort.S Normal file
View file

@ -0,0 +1,32 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/macros.h"
.real
.code16 # .code32 .code64
/ Most basic tier of program self-termination.
/
/ @mode long,legacy,real
abort: push %bp
mov %sp,%bp
rlcall panic
int3
.endfn abort,weak,protected
.yoink __FILE__

41
libc/stubs/addvdi3.S Normal file
View file

@ -0,0 +1,41 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
/ Returns 𝑥+𝑦, aborting on overflow.
/
/ @param rdi is int64 𝑥
/ @param rsi is int64 𝑦
/ @return rax is 𝑥+𝑦
/ @see -ftrapv
__addvdi3:
mov %rdi,%rax
add %rsi,%rax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __addvdi3,globl
.yoink __FILE__

41
libc/stubs/addvsi3.S Normal file
View file

@ -0,0 +1,41 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥+𝑦, aborting on overflow.
/
/ @param edi is int32 𝑥
/ @param esi is int32 𝑦
/ @return eax is 𝑥+𝑦
/ @see -ftrapv
__addvsi3:
mov %edi,%eax
add %esi,%eax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __addvsi3,globl

42
libc/stubs/addvti3.S Normal file
View file

@ -0,0 +1,42 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥+𝑦, aborting on overflow.
/
/ @param rdi:rsi is int128 𝑥
/ @param rdx:rcx is int128 𝑦
/ @return rdx:rax is 𝑥+𝑦
/ @see -ftrapv
__addvti3:
mov %rdi,%rax
add %rsi,%rax
adc %rdi,%rdx
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __addvti3,globl

54
libc/stubs/asan.greg.S Normal file
View file

@ -0,0 +1,54 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
__asan_addr_is_in_fake_stack:
__asan_alloca_poison:
__asan_allocas_unpoison:
__asan_get_current_fake_stack:
__asan_handle_no_return:
__asan_init:
__asan_loadN:
__asan_register_globals:
__asan_report_load_n:
__asan_report_store_n:
__asan_stack_free:
__asan_stack_malloc:
__asan_storeN:
__asan_unregister_globals:
__asan_version_mismatch_check_v8:
xor %eax,%eax
ret
.endfn __asan_addr_is_in_fake_stack,globl,weak
.endfn __asan_alloca_poison,globl,weak
.endfn __asan_allocas_unpoison,globl,weak
.endfn __asan_get_current_fake_stack,globl,weak
.endfn __asan_handle_no_return,globl,weak
.endfn __asan_init,globl,weak
.endfn __asan_loadN,globl,weak
.endfn __asan_register_globals,globl,weak
.endfn __asan_report_load_n,globl,weak
.endfn __asan_report_store_n,globl,weak
.endfn __asan_stack_free,globl,weak
.endfn __asan_stack_malloc,globl,weak
.endfn __asan_storeN,globl,weak
.endfn __asan_unregister_globals,globl,weak
.endfn __asan_version_mismatch_check_v8,globl,weak

260
libc/stubs/asanjmp.greg.S Normal file
View file

@ -0,0 +1,260 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.privileged
.yoink __FILE__
__asan_load1:
push $1
jmp OnLoad
.endfn __asan_load1,globl
__asan_load2:
push $2
jmp OnLoad
.endfn __asan_load2,globl
__asan_load4:
push $4
jmp OnLoad
.endfn __asan_load4,globl
__asan_load8:
push $8
jmp OnLoad
.endfn __asan_load8,globl
__asan_load16:
push $16
jmp OnLoad
.endfn __asan_load16,globl
__asan_load32:
push $32
/ fallthrough
.endfn __asan_load32,globl
OnLoad: pop %rsi
.globl __asan_loadN
.weak __asan_loadN
ezlea __asan_loadN,ax
jmp OnAsan
.endfn OnStore
__asan_store1:
push $1
jmp OnStore
.endfn __asan_store1,globl
__asan_store2:
push $2
jmp OnStore
.endfn __asan_store2,globl
__asan_store4:
push $4
jmp OnStore
.endfn __asan_store4,globl
__asan_store8:
push $8
jmp OnStore
.endfn __asan_store8,globl
__asan_store16:
push $16
jmp OnStore
.endfn __asan_store16,globl
__asan_store32:
push $32
/ fallthrough
.endfn __asan_store32,globl
OnStore:pop %rsi
.globl __asan_storeN
.weak __asan_storeN
ezlea __asan_storeN,ax
jmp OnAsan
.endfn OnStore
__asan_report_load1:
push $1
jmp OnReportLoad
.endfn __asan_report_load1,globl
__asan_report_load2:
push $2
jmp OnReportLoad
.endfn __asan_report_load2,globl
__asan_report_load4:
push $4
jmp OnReportLoad
.endfn __asan_report_load4,globl
__asan_report_load8:
push $8
jmp OnReportLoad
.endfn __asan_report_load8,globl
__asan_report_load16:
push $16
/ fallthrough
.endfn __asan_report_load16,globl
OnReportLoad:
pop %rsi
.globl __asan_report_load_n
.weak __asan_report_load_n
ezlea __asan_report_load_n,ax
jmp OnAsan
.endfn OnReportLoad
__asan_report_store1:
push $1
jmp ReportStore
.endfn __asan_report_store1,globl
__asan_report_store2:
push $2
jmp ReportStore
.endfn __asan_report_store2,globl
__asan_report_store4:
push $4
jmp ReportStore
.endfn __asan_report_store4,globl
__asan_report_store8:
push $8
jmp ReportStore
.endfn __asan_report_store8,globl
__asan_report_store16:
push $16
jmp ReportStore
.endfn __asan_report_store16,globl
__asan_report_store32:
push $32
/ fallthrough
.endfn __asan_report_store32,globl
ReportStore:
pop %rsi
.globl __asan_report_store_n
.weak __asan_report_store_n
ezlea __asan_report_store_n,ax
/ fallthrough
.endfn ReportStore
OnAsan: test %rax,%rax
jz 1f
jmp *%rax
1: ret
.endfn OnAsan
__asan_stack_free_0:
push $0
/ fallthrough
.endfn __asan_stack_free_0,globl
OnStackFree:
pop %rdx
.globl __asan_stack_free
.weak __asan_stack_free
ezlea __asan_stack_free,ax
jmp OnAsan
.endfn OnStackFree
__asan_stack_free_1:
push $1
jmp OnStackFree
.endfn __asan_stack_free_1,globl
__asan_stack_free_2:
push $2
jmp OnStackFree
.endfn __asan_stack_free_2,globl
__asan_stack_free_3:
push $3
jmp OnStackFree
.endfn __asan_stack_free_3,globl
__asan_stack_free_4:
push $4
jmp OnStackFree
.endfn __asan_stack_free_4,globl
__asan_stack_free_5:
push $5
jmp OnStackFree
.endfn __asan_stack_free_5,globl
__asan_stack_free_6:
push $6
jmp OnStackFree
.endfn __asan_stack_free_6,globl
__asan_stack_free_7:
push $7
jmp OnStackFree
.endfn __asan_stack_free_7,globl
__asan_stack_free_8:
push $8
jmp OnStackFree
.endfn __asan_stack_free_8,globl
__asan_stack_free_9:
push $9
jmp OnStackFree
.endfn __asan_stack_free_9,globl
__asan_stack_free_10:
push $10
jmp OnStackFree
.endfn __asan_stack_free_10,globl
__asan_stack_malloc_0:
push $0
/ fallthrough
.endfn __asan_stack_malloc_0,globl
OnStackMalloc:
pop %rsi
.globl __asan_stack_malloc
.weak __asan_stack_malloc
ezlea __asan_stack_malloc,ax
jmp OnAsan
.endfn OnStackMalloc
__asan_stack_malloc_1:
push $1
jmp OnStackMalloc
.endfn __asan_stack_malloc_1,globl
__asan_stack_malloc_2:
push $2
jmp OnStackMalloc
.endfn __asan_stack_malloc_2,globl
__asan_stack_malloc_3:
push $3
jmp OnStackMalloc
.endfn __asan_stack_malloc_3,globl
__asan_stack_malloc_4:
push $4
jmp OnStackMalloc
.endfn __asan_stack_malloc_4,globl
__asan_stack_malloc_5:
push $5
jmp OnStackMalloc
.endfn __asan_stack_malloc_5,globl
__asan_stack_malloc_6:
push $6
jmp OnStackMalloc
.endfn __asan_stack_malloc_6,globl
__asan_stack_malloc_7:
push $7
jmp OnStackMalloc
.endfn __asan_stack_malloc_7,globl
__asan_stack_malloc_8:
push $8
jmp OnStackMalloc
.endfn __asan_stack_malloc_8,globl
__asan_stack_malloc_9:
push $9
jmp OnStackMalloc
.endfn __asan_stack_malloc_9,globl
__asan_stack_malloc_10:
push $10
jmp OnStackMalloc
.endfn __asan_stack_malloc_10,globl
.rodata.cst4
__asan_option_detect_stack_use_after_return:
.long 1
.endobj __asan_option_detect_stack_use_after_return,globl
.previous

35
libc/stubs/assertfail.S Normal file
View file

@ -0,0 +1,35 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/macros.h"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Lightweight universal overridable assert() macro support.
/
/ @see libc/log/__assert_fail.c
/ @mode long,legacy,real
/ @noreturn
__assert_fail:
push %bp
mov %sp,%bp
rlcall panic
int3
.endfn __assert_fail,weak

View file

@ -0,0 +1,31 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
/ Did you call a virtual method from a destructor?
__cxa_pure_virtual:
push %rbp
mov %rsp,%rbp
.profilable
call abort
pop %rbp
ret
.endfn __cxa_pure_virtual,globl

33
libc/stubs/debugbreak.S Normal file
View file

@ -0,0 +1,33 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Triggers breakpoint in software debugger.
/
/ This should work with GDB, Bochs, WinDbg, etc.
/
/ @mode long,legacy,real
DebugBreak:
.softicebp
ret
.endfn DebugBreak,weak

37
libc/stubs/errno.S Normal file
View file

@ -0,0 +1,37 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.yoink __FILE__
/ Global variable for last error.
/
/ The system call wrappers update this with WIN32 error codes.
/ Unlike traditional libraries, Cosmopolitan error codes are
/ defined as variables. By convention, system calls and other
/ functions do not update this variable when nothing's broken.
/
/ @see libc/sysv/consts.sh
/ @see libc/sysv/errfuns.h
/ @see __errno_location() stable abi
.bss
.align 4
errno: .long 0
.endobj errno,globl
yoink __errno_location

View file

@ -0,0 +1,30 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.keep.text # gdb needs it
/ Returns address of errno variable.
/ @note this isn't a universal definition
__errno_location:
.leafprologue
lea errno(%rip),%rax
.leafepilogue
.endfn __errno_location,globl,hidden

37
libc/stubs/exit.S Normal file
View file

@ -0,0 +1,37 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/macros.h"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Linkable delegate for traditional Unix user process termination.
/
/ @param edi is exit code ∈ [0,256)
/ @note cosmopolitan headers obfuscate this indirection
/ @see libc/runtime/runtime.h
/ @mode long,legacy,real
/ @asyncsignalsafe
/ @noreturn
_exit: push %bp
mov %sp,%bp
rlcall _Exit
int3
.endfn _exit,weak,protected

36
libc/stubs/exit11.S Normal file
View file

@ -0,0 +1,36 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/macros.h"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Thrice re-imagined Unix user process termination API stub.
/
/ @param edi is exit code ∈ [0,256)
/ @see libc/runtime/_exit.c
/ @mode long,legacy,real
/ @asyncsignalsafe
/ @noreturn
_Exit: push %bp
mov %sp,%bp
rlcall panic
int3
.endfn _Exit,weak,protected

32
libc/stubs/fentry.S Normal file
View file

@ -0,0 +1,32 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Function entry hook stub.
/
/ @note cc -pg -mfentry adds this to the start of every function
/ @see libc/log/shadowargs.ncabi.c
/ @mode long,legacy,real
__fentry__:
ret
.endfn __fentry__,weak

63
libc/stubs/gcov.S Normal file
View file

@ -0,0 +1,63 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
/ Magic words to unbreak build if GCOV flags are passed.
__gcov_init:
ret
.endfn __gcov_init,globl,weak
__gcov_exit:
ret
.endfn __gcov_exit,globl,weak
__gcov_merge_add:
ret
.endfn __gcov_merge_add,globl,weak
__gcov_fork:
ret
.endfn __gcov_fork,globl,weak
__gcov_execle:
ret
.endfn __gcov_execle,globl,weak
__gcov_execlp:
ret
.endfn __gcov_execlp,globl,weak
__gcov_execl:
ret
.endfn __gcov_execl,globl,weak
__gcov_execv:
ret
.endfn __gcov_execv,globl,weak
__gcov_execvp:
ret
.endfn __gcov_execvp,globl,weak
__gcov_execve:
ret
.endfn __gcov_execve,globl,weak

View file

@ -0,0 +1,34 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.yoink __FILE__
/ @fileoverview Function Instrumentation No-Op Runtime
/
/ The compiler generates synthetic calls to these functions when
/ the -finstrument-functions flag is passed.
__cyg_profile_func_enter:
ret
.endfn __cyg_profile_func_enter,weak
__cyg_profile_func_exit:
ret
.endfn __cyg_profile_func_exit,weak

67
libc/stubs/ld.S Normal file
View file

@ -0,0 +1,67 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/ Traditional executable boundaries defined by linker.
/ @see man etext
_etext = 0
_edata = 0
_end = 0
/ Cosmopolitan executable boundaries defined by linker script.
/ @see libc/elf/elf.lds
/ @see ape/ape.lds
_base = 0
ape.xlm = 0
_ehead = 0
_ereal = 0
__privileged_start = 0
__test_start = 0
__ro = 0
__piro_start = 0
__relo_end = 0
__piro_end = 0
.globl _base
.globl ape.xlm
.globl __piro_start
.globl __relo_end
.globl __piro_end
.globl __privileged_start
.globl __ro
.globl __test_start
.globl _edata
.globl _ehead
.globl _end
.globl _ereal
.globl _etext
.weak _base
.weak ape.xlm
.weak __piro_start
.weak __relo_end
.weak __piro_end
.weak __privileged_start
.weak __ro
.weak __test_start
.weak _edata
.weak _ehead
.weak _end
.weak _ereal
.weak _etext

28
libc/stubs/mcount.S Normal file
View file

@ -0,0 +1,28 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Function Profiling Hook.
/ cc -pg adds this to the start of global functions.
mcount: ret
.endfn mcount,weak

29
libc/stubs/missingno.S Normal file
View file

@ -0,0 +1,29 @@
/*-*- mode:asm; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Optional function stub.
missingno:
xor %ax,%ax
ret
.endfn missingno,globl,hidden

36
libc/stubs/mulvdi3.S Normal file
View file

@ -0,0 +1,36 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥*𝑦, aborting on overflow.
/
/ @param rdi is int64 𝑥
/ @param rdi is int64 𝑦
/ @return rax is 𝑥*𝑦
/ @see -ftrapv
__mulvdi3:
mov %rdi,%rax
imul %rsi
jc __on_arithmetic_overflow
ret
.endfn __mulvdi3,globl

36
libc/stubs/mulvsi3.S Normal file
View file

@ -0,0 +1,36 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥*𝑦, aborting on overflow.
/
/ @param edi is int32 𝑥
/ @param esi is int32 𝑦
/ @return eax is 𝑥*𝑦
/ @see -ftrapv
__mulvsi3:
mov %edi,%eax
imul %esi
jc __on_arithmetic_overflow
ret
.endfn __mulvsi3,globl

44
libc/stubs/mulvti3.S Normal file
View file

@ -0,0 +1,44 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥*𝑦, aborting on overflow.
/
/ TODO(jart): is this ok?
/
/ @param rdi:rsi is int128 𝑥
/ @param rdx:rcx is int128 𝑦
/ @return rdx:rax is 𝑥*𝑦
/ @see -ftrapv
__mulvti3:
mov %rdi,%rax
imul %rdx,%rsi
imul %rdi,%rcx
add %rsi,%rcx
mul %rdx
jc 1f
add %rcx,%rdx
jo 1f
ret
1: jmp __on_arithmetic_overflow
.endfn __mulvti3,globl

40
libc/stubs/negvdi2.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns -𝑥, aborting on overflow (two's complement bane).
/
/ @param rdi is int64 𝑥
/ @return rax is -𝑥
/ @see -ftrapv
__negvdi2:
mov %rdi,%rax
neg %rax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __negvdi2,globl

40
libc/stubs/negvsi2.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns -𝑥, aborting on overflow (two's complement bane).
/
/ @param edi is int32 𝑥
/ @return eax is -𝑥
/ @see -ftrapv
__negvsi2:
mov %edi,%eax
neg %eax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __negvsi2,globl

41
libc/stubs/negvti2.S Normal file
View file

@ -0,0 +1,41 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns -𝑥, aborting on overflow.
/
/ @param rdi:rsi is int128 𝑥
/ @return rdx:rax is -𝑥
/ @see -ftrapv
__negvti2:
mov %rdi,%rax
mov %rsi,%rdx
neg %rax
adc $0,%rdx
/ TODO(jart): Make sure this is correct.
jo 1f
neg %rdx
jo 1f
ret
1: jmp __on_arithmetic_overflow
.endfn __negvti2,globl

View file

@ -0,0 +1,33 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.text.unlikely
.yoink __FILE__
/ Arithmetic overflow handler.
/
/ @see libc/testlib/arithmeticoverflowhook.S
/ @see -ftrapv
__on_arithmetic_overflow:
push %rbp
mov %rsp,%rbp
int3
call abort
.endfn __on_arithmetic_overflow,weak

33
libc/stubs/panic.S Normal file
View file

@ -0,0 +1,33 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Aborts or hard blocks instruction pointer.
/ @mode long,legacy,real
panic: push %bp
mov %sp,%bp
.softicebp
cli
1: hlt
jmp 1b
.endfn panic,weak,protected

46
libc/stubs/stackguard.S Normal file
View file

@ -0,0 +1,46 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/macros.h"
.real
.yoink __FILE__
.code16 # .code32 .code64
/**
* @fileoverview Overridable stubs for synthetic stack protector calls.
*/
__stack_chk_fail_local:
nop
/ fallthrough
.endfn __stack_chk_fail_local,weak,hidden
__stack_chk_fail:
push %bp
mov %sp,%bp
rlcall abort
nop
.endfn __stack_chk_fail,weak
.bss
.align 8
__stack_chk_guard:
.quad 0
.endobj __stack_chk_guard,weak
.previous

53
libc/stubs/stubs.mk Normal file
View file

@ -0,0 +1,53 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Universally Linkable Weak Functions
#
# DESCRIPTION
#
# This package contains no-op implementations for (1) synthetic
# compiler surprises and (2) mission-critical core functions, e.g.
# abort(). These functions are designed to work in all addressing
# modes, including real mode. Every package links this. It's at the
# base of the topological order of things.
PKGS += LIBC_STUBS
LIBC_STUBS_ARTIFACTS += LIBC_STUBS_A
LIBC_STUBS = $(LIBC_STUBS_A)
LIBC_STUBS_A = o/libc/stubs/stubs.a
LIBC_STUBS_A_FILES := $(wildcard libc/stubs/*.S)
LIBC_STUBS_A_HDRS = \
$(filter %.h,$(LIBC_STUBS_A_FILES))
LIBC_STUBS_A_SRCS = \
$(filter %.S,$(LIBC_STUBS_A_FILES))
LIBC_STUBS_A_OBJS = \
$(LIBC_STUBS_A_SRCS:%=o/$(MODE)/%.zip.o) \
$(LIBC_STUBS_A_SRCS:%.S=o/%.o)
LIBC_STUBS_A_CHECKS = \
$(LIBC_STUBS_A).pkg \
$(LIBC_STUBS_A_HDRS:%=o/%.ok)
$(LIBC_STUBS_A): \
libc/stubs/ \
$(LIBC_STUBS_A).pkg \
$(LIBC_STUBS_A_OBJS)
$(LIBC_STUBS_A).pkg: \
$(LIBC_STUBS_A_OBJS) \
$(foreach x,$(LIBC_STUBS_A_DIRECTDEPS),$($(x)_A).pkg)
LIBC_STUBS_LIBS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x)))
LIBC_STUBS_SRCS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x)_SRCS))
LIBC_STUBS_CHECKS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x)_CHECKS))
LIBC_STUBS_OBJS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x)_OBJS))
$(LIBC_STUBS_OBJS): $(BUILD_FILES) libc/stubs/stubs.mk
.PHONY: o/libc/stubs
o/libc/stubs: $(LIBC_STUBS_CHECKS)

41
libc/stubs/subvdi3.S Normal file
View file

@ -0,0 +1,41 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥-𝑦, aborting on overflow.
/
/ @param rdi is int64 𝑥
/ @param rsi is int64 𝑦
/ @return rax is 𝑥-𝑦
/ @see -ftrapv
__subvdi3:
mov %rdi,%rax
sub %rsi,%rax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __subvdi3,globl

40
libc/stubs/subvsi3.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥-𝑦, aborting on overflow.
/
/ @param edi is int32 𝑥
/ @param esi is int32 𝑦
/ @see -ftrapv
__subvsi3:
mov %edi,%eax
sub %esi,%eax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __subvsi3,globl

42
libc/stubs/subvti3.S Normal file
View file

@ -0,0 +1,42 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.align 16
.text.likely
.yoink __FILE__
/ Returns 𝑥-𝑦, aborting on overflow.
/
/ @param rdi:rsi is int128 𝑥
/ @param rdx:rcx is int128 𝑦
/ @return rdx:rax is 𝑥-𝑦
/ @see -ftrapv
__subvti3:
mov %rdi,%rax
sub %rsi,%rax
sbb %rdi,%rdx
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __subvti3,globl

42
libc/stubs/triplf.S Normal file
View file

@ -0,0 +1,42 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/macros.h"
#include "ape/config.h"
.real
.yoink __FILE__
.code16 # .code32 .code64
/ Hoses interrupt descriptor table and triple-faults the system.
/
/ @see youtu.be/GIKfEAF2Yhw?t=67
/ @mode long,legacy,real
triplf: 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

28
libc/stubs/typeinfo.S Normal file
View file

@ -0,0 +1,28 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
/ __cxxabiv1::__function_type_info (?)
/ Because Clang in MODE=dbg doesn't respect -fno-rtti
.align 8
_ZTVN10__cxxabiv120__function_type_infoE:
.quad 0
.endobj _ZTVN10__cxxabiv120__function_type_infoE,globl
.yoink __FILE__

312
libc/stubs/ubsan.S Normal file
View file

@ -0,0 +1,312 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/macros.h"
.real
.code16 # .code32 .code64
.yoink __FILE__
/**
* @fileoverview Overridable stubs for synthetic sanitizer calls.
*/
__ubsan_default_options:
ret
.endfn __ubsan_default_options,weak
__ubsan_get_current_report_data:
ret
.endfn __ubsan_get_current_report_data,weak
__ubsan_handle_add_overflow:
nop
/ fallthrough
.endfn __ubsan_handle_add_overflow,weak
__ubsan_handle_add_overflow_abort:
nop
/ fallthrough
.endfn __ubsan_handle_add_overflow_abort,weak
__ubsan_handle_alignment_assumption:
nop
/ fallthrough
.endfn __ubsan_handle_alignment_assumption,weak
__ubsan_handle_alignment_assumption_abort:
nop
/ fallthrough
.endfn __ubsan_handle_alignment_assumption_abort,weak
__ubsan_handle_builtin_unreachable:
nop
/ fallthrough
.endfn __ubsan_handle_builtin_unreachable,weak
__ubsan_handle_builtin_unreachable_abort:
nop
/ fallthrough
.endfn __ubsan_handle_builtin_unreachable_abort,weak
__ubsan_handle_cfi_bad_type:
nop
/ fallthrough
.endfn __ubsan_handle_cfi_bad_type,weak
__ubsan_handle_cfi_bad_type_abort:
nop
/ fallthrough
.endfn __ubsan_handle_cfi_bad_type_abort,weak
__ubsan_handle_cfi_check_fail:
nop
/ fallthrough
.endfn __ubsan_handle_cfi_check_fail,weak
__ubsan_handle_cfi_check_fail_abort:
nop
/ fallthrough
.endfn __ubsan_handle_cfi_check_fail_abort,weak
__ubsan_handle_divrem_overflow:
nop
/ fallthrough
.endfn __ubsan_handle_divrem_overflow,weak
__ubsan_handle_divrem_overflow_abort:
nop
/ fallthrough
.endfn __ubsan_handle_divrem_overflow_abort,weak
__ubsan_handle_dynamic_type_cache_miss:
nop
/ fallthrough
.endfn __ubsan_handle_dynamic_type_cache_miss,weak
__ubsan_handle_dynamic_type_cache_miss_abort:
nop
/ fallthrough
.endfn __ubsan_handle_dynamic_type_cache_miss_abort,weak
__ubsan_handle_float_cast_overflow:
nop
/ fallthrough
.endfn __ubsan_handle_float_cast_overflow,weak
__ubsan_handle_float_cast_overflow_abort:
nop
/ fallthrough
.endfn __ubsan_handle_float_cast_overflow_abort,weak
__ubsan_handle_function_type_mismatch:
nop
/ fallthrough
.endfn __ubsan_handle_function_type_mismatch,weak
__ubsan_handle_function_type_mismatch_abort:
nop
/ fallthrough
.endfn __ubsan_handle_function_type_mismatch_abort,weak
__ubsan_handle_implicit_conversion:
nop
/ fallthrough
.endfn __ubsan_handle_implicit_conversion,weak
__ubsan_handle_implicit_conversion_abort:
nop
/ fallthrough
.endfn __ubsan_handle_implicit_conversion_abort,weak
__ubsan_handle_invalid_builtin:
nop
/ fallthrough
.endfn __ubsan_handle_invalid_builtin,weak
__ubsan_handle_invalid_builtin_abort:
nop
/ fallthrough
.endfn __ubsan_handle_invalid_builtin_abort,weak
__ubsan_handle_load_invalid_value:
nop
/ fallthrough
.endfn __ubsan_handle_load_invalid_value,weak
__ubsan_handle_load_invalid_value_abort:
nop
/ fallthrough
.endfn __ubsan_handle_load_invalid_value_abort,weak
__ubsan_handle_missing_return:
nop
/ fallthrough
.endfn __ubsan_handle_missing_return,weak
__ubsan_handle_missing_return_abort:
nop
/ fallthrough
.endfn __ubsan_handle_missing_return_abort,weak
__ubsan_handle_mul_overflow:
nop
/ fallthrough
.endfn __ubsan_handle_mul_overflow,weak
__ubsan_handle_mul_overflow_abort:
nop
/ fallthrough
.endfn __ubsan_handle_mul_overflow_abort,weak
__ubsan_handle_negate_overflow:
nop
/ fallthrough
.endfn __ubsan_handle_negate_overflow,weak
__ubsan_handle_negate_overflow_abort:
nop
/ fallthrough
.endfn __ubsan_handle_negate_overflow_abort,weak
__ubsan_handle_nonnull_arg:
nop
/ fallthrough
.endfn __ubsan_handle_nonnull_arg,weak
__ubsan_handle_nonnull_arg_abort:
nop
/ fallthrough
.endfn __ubsan_handle_nonnull_arg_abort,weak
__ubsan_handle_nonnull_return:
nop
/ fallthrough
.endfn __ubsan_handle_nonnull_return,weak
__ubsan_handle_nonnull_return_abort:
nop
/ fallthrough
.endfn __ubsan_handle_nonnull_return_abort,weak
__ubsan_handle_nonnull_return_v1:
nop
/ fallthrough
.endfn __ubsan_handle_nonnull_return_v1,weak
__ubsan_handle_nonnull_return_v1_abort:
nop
/ fallthrough
.endfn __ubsan_handle_nonnull_return_v1_abort,weak
__ubsan_handle_nullability_arg:
nop
/ fallthrough
.endfn __ubsan_handle_nullability_arg,weak
__ubsan_handle_nullability_arg_abort:
nop
/ fallthrough
.endfn __ubsan_handle_nullability_arg_abort,weak
__ubsan_handle_nullability_return_v1:
nop
/ fallthrough
.endfn __ubsan_handle_nullability_return_v1,weak
__ubsan_handle_nullability_return_v1_abort:
nop
/ fallthrough
.endfn __ubsan_handle_nullability_return_v1_abort,weak
__ubsan_handle_out_of_bounds:
nop
/ fallthrough
.endfn __ubsan_handle_out_of_bounds,weak
__ubsan_handle_out_of_bounds_abort:
nop
/ fallthrough
.endfn __ubsan_handle_out_of_bounds_abort,weak
__ubsan_handle_pointer_overflow:
nop
/ fallthrough
.endfn __ubsan_handle_pointer_overflow,weak
__ubsan_handle_pointer_overflow_abort:
nop
/ fallthrough
.endfn __ubsan_handle_pointer_overflow_abort,weak
__ubsan_handle_shift_out_of_bounds:
nop
/ fallthrough
.endfn __ubsan_handle_shift_out_of_bounds,weak
__ubsan_handle_shift_out_of_bounds_abort:
nop
/ fallthrough
.endfn __ubsan_handle_shift_out_of_bounds_abort,weak
__ubsan_handle_sub_overflow:
nop
/ fallthrough
.endfn __ubsan_handle_sub_overflow,weak
__ubsan_handle_sub_overflow_abort:
nop
/ fallthrough
.endfn __ubsan_handle_sub_overflow_abort,weak
__ubsan_handle_type_mismatch:
nop
/ fallthrough
.endfn __ubsan_handle_type_mismatch,weak
__ubsan_handle_type_mismatch_abort:
nop
/ fallthrough
.endfn __ubsan_handle_type_mismatch_abort,weak
__ubsan_handle_type_mismatch_v1:
nop
/ fallthrough
.endfn __ubsan_handle_type_mismatch_v1,weak
__ubsan_handle_type_mismatch_v1_abort:
nop
/ fallthrough
.endfn __ubsan_handle_type_mismatch_v1_abort,weak
__ubsan_handle_vla_bound_not_positive:
nop
/ fallthrough
.endfn __ubsan_handle_vla_bound_not_positive,weak
__ubsan_handle_vla_bound_not_positive_abort:
nop
/ fallthrough
.endfn __ubsan_handle_vla_bound_not_positive_abort,weak
__ubsan_abort_stub:
push %bp
mov %sp,%bp
1: int3
jmp 1b
.endfn __ubsan_abort_stub

31
libc/stubs/unprovable.S Normal file
View file

@ -0,0 +1,31 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.inc"
.real
.code16 # .code32 .code64
__unprovable:
push %bp
mov %sp,%bp
.softicebp
pop %bp
ret
.endfn __unprovable,globl,hidden
.yoink __FILE__

25
libc/stubs/xnu.S Normal file
View file

@ -0,0 +1,25 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
_start_xnu:
jmp abort
.endfn _start_xnu,weak
.yoink __FILE__

26
libc/stubs/zip.S Normal file
View file

@ -0,0 +1,26 @@
/*-*- mode:asm; 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
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
__zip_start:
.endfn __zip_start,weak
__zip_end:
.endfn __zip_end,weak