mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Make more functions friendly to Address Sanitizer
This commit is contained in:
parent
3ab76b2312
commit
cbfd4ccd1e
70 changed files with 1267 additions and 291 deletions
|
@ -18,8 +18,8 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Half size of level 3 cache in bytes.
|
||||
.initbss 202,_init_kHalfCache3
|
||||
/ Half size of level 3 cache in bytes.
|
||||
kHalfCache3:
|
||||
.quad 0
|
||||
.endobj kHalfCache3,globl
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern long kHalfCache3;
|
||||
|
||||
void imapxlatab(void *);
|
||||
void insertionsort(int32_t *, size_t);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ LIBC_NEXGEN32E = $(LIBC_NEXGEN32E_A_DEPS) $(LIBC_NEXGEN32E_A)
|
|||
LIBC_NEXGEN32E_A = o/$(MODE)/libc/nexgen32e/nexgen32e.a
|
||||
LIBC_NEXGEN32E_A_FILES := $(wildcard libc/nexgen32e/*)
|
||||
LIBC_NEXGEN32E_A_HDRS = $(filter %.h,$(LIBC_NEXGEN32E_A_FILES))
|
||||
LIBC_NEXGEN32E_A_INCS = $(filter %.inc,$(LIBC_NEXGEN32E_A_FILES))
|
||||
LIBC_NEXGEN32E_A_SRCS_A = $(filter %.s,$(LIBC_NEXGEN32E_A_FILES))
|
||||
LIBC_NEXGEN32E_A_SRCS_S = $(filter %.S,$(LIBC_NEXGEN32E_A_FILES))
|
||||
LIBC_NEXGEN32E_A_SRCS_C = $(filter %.c,$(LIBC_NEXGEN32E_A_FILES))
|
||||
|
@ -49,6 +50,7 @@ o/$(MODE)/libc/nexgen32e/tinystrncmp.ncabi.o: \
|
|||
LIBC_NEXGEN32E_LIBS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)))
|
||||
LIBC_NEXGEN32E_SRCS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_SRCS))
|
||||
LIBC_NEXGEN32E_HDRS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_HDRS))
|
||||
LIBC_NEXGEN32E_INCS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_INCS))
|
||||
LIBC_NEXGEN32E_CHECKS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_CHECKS))
|
||||
LIBC_NEXGEN32E_OBJS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_OBJS))
|
||||
$(LIBC_NEXGEN32E_OBJS): $(BUILD_FILES) libc/nexgen32e/nexgen32e.mk
|
||||
|
|
|
@ -21,71 +21,6 @@
|
|||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Returns pointer to first instance of character.
|
||||
/
|
||||
/ @param rdi is a non-null NUL-terminated string pointer
|
||||
/ @param esi is the search byte
|
||||
/ @return rax points to character, or to NUL byte if not found
|
||||
/ @note this won't return NULL if search character is NUL
|
||||
strchrnul:
|
||||
.leafprologue
|
||||
.profilable
|
||||
or $-1,%r9
|
||||
jmp 0f
|
||||
.endfn strchrnul,globl
|
||||
|
||||
/ Returns pointer to first instance of character, the BSD way.
|
||||
/
|
||||
/ @param rdi is a non-null NUL-terminated string pointer
|
||||
/ @param esi is the search byte
|
||||
/ @return rax points to first result, or NULL if not found
|
||||
/ @note this won't return NULL if search character is NUL
|
||||
index: nop
|
||||
/ 𝑠𝑙𝑖𝑑𝑒
|
||||
.endfn index,globl
|
||||
|
||||
/ Returns pointer to first instance of character.
|
||||
/
|
||||
/ @param rdi is a non-null NUL-terminated string pointer
|
||||
/ @param esi is the search byte
|
||||
/ @return rax points to first result, or NULL if not found
|
||||
/ @note this won't return NULL if search character is NUL
|
||||
/ @asyncsignalsafe
|
||||
strchr: .leafprologue
|
||||
.profilable
|
||||
xor %r9d,%r9d
|
||||
0: movzbl %sil,%edx
|
||||
or $-1,%rsi
|
||||
xor %r8,%r8
|
||||
jmp strsak
|
||||
.endfn strchr,globl
|
||||
|
||||
/ Returns pointer to first instance of character in range.
|
||||
/
|
||||
/ @param rdi is a non-null pointer to memory
|
||||
/ @param esi is the search byte
|
||||
/ @return rax points to byte if found, or else undefined behavior
|
||||
rawmemchr:
|
||||
or $-1,%rdx
|
||||
/ 𝑠𝑙𝑖𝑑𝑒
|
||||
.endfn rawmemchr,globl
|
||||
|
||||
/ Returns pointer to first instance of character in range.
|
||||
/
|
||||
/ @param rdi is a non-null pointer to memory
|
||||
/ @param esi is the search byte
|
||||
/ @param rdx is length of memory in bytes
|
||||
/ @return rax points to byte if found or NULL
|
||||
/ @asyncsignalsafe
|
||||
memchr: .leafprologue
|
||||
.profilable
|
||||
xchg %rsi,%rdx
|
||||
mov %dl,%dh
|
||||
xor %r8,%r8
|
||||
xor %r10,%r10
|
||||
jmp strsak
|
||||
.endfn memchr,globl
|
||||
|
||||
/ Returns length of NUL-terminated string w/ security blankets.
|
||||
/
|
||||
/ This is like strnlen() except it'll return 0 if (1) RDI is NULL
|
||||
|
@ -102,24 +37,13 @@ strnlen_s:
|
|||
test %rdi,%rdi
|
||||
jnz 0f
|
||||
.leafepilogue
|
||||
.endfn strnlen_s,globl
|
||||
|
||||
/ Returns length of NUL-terminated memory, with limit.
|
||||
/
|
||||
/ @param rdi is non-null memory
|
||||
/ @param rsi is the maximum number of bytes to consider
|
||||
/ @return rax is the number of bytes, excluding the NUL
|
||||
/ @asyncsignalsafe
|
||||
strnlen:.leafprologue
|
||||
.profilable
|
||||
or $-1,%r10
|
||||
0: xor %edx,%edx
|
||||
mov %rdi,%r8
|
||||
/ 𝑠𝑙𝑖𝑑𝑒
|
||||
.endfn strnlen,globl
|
||||
.endfn strnlen_s,globl
|
||||
|
||||
/ Swiss army knife of string character scanning.
|
||||
/ Fourteen fast functions in one.
|
||||
/ Used to be fourteen fast functions in one.
|
||||
/
|
||||
/ @param rdi is non-null string memory
|
||||
/ @param rsi is max number of bytes to consider
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue