mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 04:08:32 +00:00
Make some quick fixes and cleanup
This commit is contained in:
parent
fa5c2a24b5
commit
61257d48d4
63 changed files with 275 additions and 257 deletions
|
@ -200,6 +200,15 @@ static char *__asan_utf8cpy(char *p, unsigned c) {
|
|||
return p;
|
||||
}
|
||||
|
||||
static char *__asan_stpcpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0;; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __asan_memset(void *p, char c, size_t n) {
|
||||
char *b;
|
||||
size_t i;
|
||||
|
@ -645,9 +654,9 @@ static char *__asan_format_section(char *p, const void *p1, const void *p2,
|
|||
intptr_t a, b;
|
||||
if ((a = (intptr_t)p1) < (b = (intptr_t)p2)) {
|
||||
p = __asan_format_interval(p, a, b), *p++ = ' ';
|
||||
p = __stpcpy(p, name);
|
||||
p = __asan_stpcpy(p, name);
|
||||
if (a <= (intptr_t)addr && (intptr_t)addr <= b) {
|
||||
p = __stpcpy(p, " ←address");
|
||||
p = __asan_stpcpy(p, " ←address");
|
||||
}
|
||||
*p++ = '\n';
|
||||
}
|
||||
|
@ -822,9 +831,9 @@ dontdiscard static __asan_die_f *__asan_report(const void *addr, int size,
|
|||
y = m->p[i].y;
|
||||
p = __asan_format_interval(p, x << 16, (y << 16) + (FRAMESIZE - 1));
|
||||
z = (intptr_t)addr >> 16;
|
||||
if (x <= z && z <= y) p = __stpcpy(p, " ←address");
|
||||
if (x <= z && z <= y) p = __asan_stpcpy(p, " ←address");
|
||||
z = (((intptr_t)addr >> 3) + 0x7fff8000) >> 16;
|
||||
if (x <= z && z <= y) p = __stpcpy(p, " ←shadow");
|
||||
if (x <= z && z <= y) p = __asan_stpcpy(p, " ←shadow");
|
||||
*p++ = '\n';
|
||||
}
|
||||
__mmi_unlock();
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/runtime/cxaatexit.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
|
37
libc/intrin/cxaatexit.internal.h
Normal file
37
libc/intrin/cxaatexit.internal.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_
|
||||
#define COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_
|
||||
#include "libc/intrin/nopl.h"
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct CxaAtexitBlocks {
|
||||
struct CxaAtexitBlock {
|
||||
unsigned mask;
|
||||
struct CxaAtexitBlock *next;
|
||||
struct CxaAtexit {
|
||||
void *fp;
|
||||
void *arg;
|
||||
void *pred;
|
||||
} p[ATEXIT_MAX];
|
||||
} * p, root;
|
||||
};
|
||||
|
||||
extern struct CxaAtexitBlocks __cxa_blocks;
|
||||
|
||||
void __cxa_lock(void);
|
||||
void __cxa_unlock(void);
|
||||
void __cxa_printexits(FILE *, void *);
|
||||
|
||||
#ifdef _NOPL0
|
||||
#define __cxa_lock() _NOPL0("__threadcalls", __cxa_lock)
|
||||
#define __cxa_unlock() _NOPL0("__threadcalls", __cxa_unlock)
|
||||
#else
|
||||
#define __cxa_lock() (__threaded ? __cxa_lock() : 0)
|
||||
#define __cxa_unlock() (__threaded ? __cxa_unlock() : 0)
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_ */
|
|
@ -16,6 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/cxaatexit.internal.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
|
||||
struct CxaAtexitBlocks __cxa_blocks;
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/bsf.h"
|
||||
#include "libc/runtime/cxaatexit.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/intrin/pthread.h"
|
||||
#include "libc/runtime/cxaatexit.internal.h"
|
||||
|
||||
static pthread_mutex_t __cxa_lock_obj;
|
||||
|
||||
|
|
|
@ -16,39 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sol.h"
|
||||
|
||||
static inline char *StpCpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0;; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes clock_gettime() clock argument.
|
||||
*/
|
||||
const char *(DescribeClockName)(char buf[32], int x) {
|
||||
int i;
|
||||
char *s, *p;
|
||||
if ((s = GetMagnumStr(kClockNames, x))) {
|
||||
p = buf;
|
||||
*p++ = 'C';
|
||||
*p++ = 'L';
|
||||
*p++ = 'O';
|
||||
*p++ = 'C';
|
||||
*p++ = 'K';
|
||||
*p++ = '_';
|
||||
StpCpy(p, s);
|
||||
return buf;
|
||||
} else {
|
||||
FormatInt32(buf, x);
|
||||
return buf;
|
||||
}
|
||||
return DescribeMagnum(buf, kClockNames, "CLOCK_", x);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ const char *DescribePrctlOperation(int);
|
|||
const char *DescribeProtFlags(char[48], int);
|
||||
const char *DescribeRemapFlags(char[48], int);
|
||||
const char *DescribeRlimit(char[64], int, const struct rlimit *);
|
||||
const char *DescribeRlimitName(char[12], int);
|
||||
const char *DescribeRlimitName(char[20], int);
|
||||
const char *DescribeSeccompOperation(int);
|
||||
const char *DescribeSigaction(char[128], int, const struct sigaction *);
|
||||
const char *DescribeSigaltstk(char[128], int, const struct sigaltstack *);
|
||||
|
@ -94,7 +94,7 @@ void DescribeIovNt(const struct NtIovec *, uint32_t, ssize_t);
|
|||
#define DescribeProtFlags(dirfd) DescribeProtFlags(alloca(48), dirfd)
|
||||
#define DescribeRemapFlags(dirfd) DescribeRemapFlags(alloca(48), dirfd)
|
||||
#define DescribeRlimit(rc, rl) DescribeRlimit(alloca(64), rc, rl)
|
||||
#define DescribeRlimitName(rl) DescribeRlimitName(alloca(12), rl)
|
||||
#define DescribeRlimitName(rl) DescribeRlimitName(alloca(20), rl)
|
||||
#define DescribeSigaction(rc, sa) DescribeSigaction(alloca(128), rc, sa)
|
||||
#define DescribeSigaltstk(rc, ss) DescribeSigaltstk(alloca(128), rc, ss)
|
||||
#define DescribeSigset(rc, ss) DescribeSigset(alloca(64), rc, ss)
|
||||
|
|
32
libc/intrin/describemagnums.c
Normal file
32
libc/intrin/describemagnums.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 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 "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p, int x) {
|
||||
char *s;
|
||||
if ((s = GetMagnumStr(m, x))) {
|
||||
stpcpy(stpcpy(b, p), s);
|
||||
return b;
|
||||
} else {
|
||||
FormatInt32(b, x);
|
||||
return b;
|
||||
}
|
||||
}
|
|
@ -16,31 +16,13 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
|
||||
const char *(DescribeRlimitName)(char buf[12], int resource) {
|
||||
if (resource == 127) return "n/a";
|
||||
if (resource == RLIMIT_AS) return "RLIMIT_AS";
|
||||
if (resource == RLIMIT_CPU) return "RLIMIT_CPU";
|
||||
if (resource == RLIMIT_FSIZE) return "RLIMIT_FSIZE";
|
||||
if (resource == RLIMIT_NPROC) return "RLIMIT_NPROC";
|
||||
if (resource == RLIMIT_NOFILE) return "RLIMIT_NOFILE";
|
||||
if (resource == RLIMIT_RSS) return "RLIMIT_RSS";
|
||||
if (resource == RLIMIT_DATA) return "RLIMIT_DATA";
|
||||
if (resource == RLIMIT_CORE) return "RLIMIT_CORE";
|
||||
if (resource == RLIMIT_STACK) return "RLIMIT_STACK";
|
||||
if (resource == RLIMIT_SIGPENDING) return "RLIMIT_SIGPENDING";
|
||||
if (resource == RLIMIT_MEMLOCK) return "RLIMIT_MEMLOCK";
|
||||
if (resource == RLIMIT_LOCKS) return "RLIMIT_LOCKS";
|
||||
if (resource == RLIMIT_MSGQUEUE) return "RLIMIT_MSGQUEUE";
|
||||
if (resource == RLIMIT_NICE) return "RLIMIT_NICE";
|
||||
if (resource == RLIMIT_RTPRIO) return "RLIMIT_RTPRIO";
|
||||
if (resource == RLIMIT_RTTIME) return "RLIMIT_RTTIME";
|
||||
if (resource == RLIMIT_SWAP) return "RLIMIT_SWAP";
|
||||
if (resource == RLIMIT_SBSIZE) return "RLIMIT_SBSIZE";
|
||||
if (resource == RLIMIT_NPTS) return "RLIMIT_NPTS";
|
||||
FormatInt32(buf, resource);
|
||||
return buf;
|
||||
/**
|
||||
* Describes setrlimit() / getrlimit() argument.
|
||||
*/
|
||||
const char *(DescribeRlimitName)(char buf[20], int x) {
|
||||
if (x == 127) return "n/a";
|
||||
return DescribeMagnum(buf, kRlimitNames, "RLIMIT_", x);
|
||||
}
|
|
@ -21,34 +21,25 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
|
||||
static char *StpCpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0;; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *(DescribeSocketType)(char buf[64], int type) {
|
||||
int x;
|
||||
char *p;
|
||||
p = buf;
|
||||
x = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK);
|
||||
if (x == SOCK_STREAM) {
|
||||
p = StpCpy(p, "SOCK_STREAM");
|
||||
p = stpcpy(p, "SOCK_STREAM");
|
||||
} else if (x == SOCK_DGRAM) {
|
||||
p = StpCpy(p, "SOCK_DGRAM");
|
||||
p = stpcpy(p, "SOCK_DGRAM");
|
||||
} else if (x == SOCK_RAW) {
|
||||
p = StpCpy(p, "SOCK_RAW");
|
||||
p = stpcpy(p, "SOCK_RAW");
|
||||
} else if (x == SOCK_RDM) {
|
||||
p = StpCpy(p, "SOCK_RDM");
|
||||
p = stpcpy(p, "SOCK_RDM");
|
||||
} else if (x == SOCK_SEQPACKET) {
|
||||
p = StpCpy(p, "SOCK_SEQPACKET");
|
||||
p = stpcpy(p, "SOCK_SEQPACKET");
|
||||
} else {
|
||||
p = FormatInt32(p, x);
|
||||
}
|
||||
if (type & SOCK_CLOEXEC) p = StpCpy(p, "|SOCK_CLOEXEC");
|
||||
if (type & SOCK_NONBLOCK) p = StpCpy(p, "|SOCK_NONBLOCK");
|
||||
if (type & SOCK_CLOEXEC) p = stpcpy(p, "|SOCK_CLOEXEC");
|
||||
if (type & SOCK_NONBLOCK) p = stpcpy(p, "|SOCK_NONBLOCK");
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -22,15 +22,6 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sol.h"
|
||||
|
||||
static inline char *StpCpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0;; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes setsockopt() optname arguments.
|
||||
*/
|
||||
|
@ -65,7 +56,7 @@ const char *(DescribeSockOptname)(char buf[32], int l, int x) {
|
|||
ms = 0;
|
||||
}
|
||||
if (ms && (s = GetMagnumStr(ms, x))) {
|
||||
StpCpy(p, s);
|
||||
stpcpy(p, s);
|
||||
} else {
|
||||
FormatInt32(p, x);
|
||||
}
|
||||
|
|
55
libc/intrin/krlimitnames.S
Normal file
55
libc/intrin/krlimitnames.S
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*-*- 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 2021 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 "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
.macro .e e s
|
||||
.long \e - kRlimitNames
|
||||
.long 1f - kRlimitNames
|
||||
.rodata.str1.1
|
||||
1: .string "\s"
|
||||
.previous
|
||||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.underrun
|
||||
kRlimitNames:
|
||||
.e RLIMIT_AS,"AS"
|
||||
.e RLIMIT_CPU,"CPU"
|
||||
.e RLIMIT_FSIZE,"FSIZE"
|
||||
.e RLIMIT_NPROC,"NPROC"
|
||||
.e RLIMIT_NOFILE,"NOFILE"
|
||||
.e RLIMIT_RSS,"RSS"
|
||||
.e RLIMIT_DATA,"DATA"
|
||||
.e RLIMIT_CORE,"CORE"
|
||||
.e RLIMIT_STACK,"STACK"
|
||||
.e RLIMIT_SIGPENDING,"SIGPENDING"
|
||||
.e RLIMIT_MEMLOCK,"MEMLOCK"
|
||||
.e RLIMIT_LOCKS,"LOCKS"
|
||||
.e RLIMIT_MSGQUEUE,"MSGQUEUE"
|
||||
.e RLIMIT_NICE,"NICE"
|
||||
.e RLIMIT_RTPRIO,"RTPRIO"
|
||||
.e RLIMIT_RTTIME,"RTTIME"
|
||||
.e RLIMIT_SWAP,"SWAP"
|
||||
.e RLIMIT_SBSIZE,"SBSIZE"
|
||||
.e RLIMIT_NPTS,"NPTS"
|
||||
.long MAGNUM_TERMINATOR
|
||||
.endobj kRlimitNames,globl,hidden
|
||||
.overrun
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__GNUC__) && \
|
||||
!defined(__llvm__) && !defined(__chibicc__) && !defined(__STRICT_ANSI__)
|
||||
|
||||
/**
|
||||
* @fileoverview Turns CALLs into NOPs that are fixupable at runtime.
|
||||
|
@ -66,5 +67,5 @@
|
|||
0; \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* !ASSEMBLER && !LINKER && GNUC && !CHIBICC && !LLVM && !ANSI */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_NOPL_H_ */
|
||||
|
|
61
libc/intrin/stpcpy.c
Normal file
61
libc/intrin/stpcpy.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 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 "libc/str/str.h"
|
||||
|
||||
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
||||
static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
||||
xmm_t v, z = {0};
|
||||
for (;;) {
|
||||
v = *(xmm_t *)(s + i);
|
||||
if (!__builtin_ia32_pmovmskb128(v == z)) {
|
||||
*(xmm_u *)(d + i) = v;
|
||||
i += 16;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
||||
*
|
||||
* @param 𝑑 is destination memory
|
||||
* @param 𝑠 is a NUL-terminated string
|
||||
* @note 𝑑 and 𝑠 can't overlap
|
||||
* @return pointer to nul byte
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
char *stpcpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
}
|
||||
i = stpcpy_sse2(d, s, i);
|
||||
for (;;) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
61
libc/intrin/strcpy.c
Normal file
61
libc/intrin/strcpy.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 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 "libc/str/str.h"
|
||||
|
||||
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
||||
static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
||||
xmm_t v, z = {0};
|
||||
for (;;) {
|
||||
v = *(xmm_t *)(s + i);
|
||||
if (!__builtin_ia32_pmovmskb128(v == z)) {
|
||||
*(xmm_u *)(d + i) = v;
|
||||
i += 16;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
||||
*
|
||||
* @param 𝑑 is destination memory
|
||||
* @param 𝑠 is a NUL-terminated string
|
||||
* @note 𝑑 and 𝑠 can't overlap
|
||||
* @return original dest
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
char *strcpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
i = strcpy_sse2(d, s, i);
|
||||
for (;;) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
|
@ -204,6 +204,15 @@ static void __ubsan_exit(void) {
|
|||
_Exit(99);
|
||||
}
|
||||
|
||||
static char *__ubsan_stpcpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0;; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dontdiscard static __ubsan_die_f *__ubsan_die(void) {
|
||||
if (weaken(__die)) {
|
||||
return weaken(__die);
|
||||
|
@ -246,11 +255,11 @@ static char *__ubsan_describe_shift_out_of_bounds(
|
|||
char *p = buf;
|
||||
lhs = __ubsan_extend(info->lhs_type, lhs);
|
||||
rhs = __ubsan_extend(info->rhs_type, rhs);
|
||||
p = __stpcpy(p, __ubsan_describe_shift(info, lhs, rhs)), *p++ = ' ';
|
||||
p = __ubsan_stpcpy(p, __ubsan_describe_shift(info, lhs, rhs)), *p++ = ' ';
|
||||
p = __ubsan_itpcpy(p, info->lhs_type, lhs), *p++ = ' ';
|
||||
p = __stpcpy(p, info->lhs_type->name), *p++ = ' ';
|
||||
p = __ubsan_stpcpy(p, info->lhs_type->name), *p++ = ' ';
|
||||
p = __ubsan_itpcpy(p, info->rhs_type, rhs), *p++ = ' ';
|
||||
p = __stpcpy(p, info->rhs_type->name);
|
||||
p = __ubsan_stpcpy(p, info->rhs_type->name);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -272,12 +281,12 @@ void __ubsan_handle_shift_out_of_bounds_abort(
|
|||
void __ubsan_handle_out_of_bounds(struct UbsanOutOfBoundsInfo *info,
|
||||
uintptr_t index) {
|
||||
char buf[512], *p = buf;
|
||||
p = __stpcpy(p, info->index_type->name);
|
||||
p = __stpcpy(p, " index ");
|
||||
p = __ubsan_stpcpy(p, info->index_type->name);
|
||||
p = __ubsan_stpcpy(p, " index ");
|
||||
p = __ubsan_itpcpy(p, info->index_type, index);
|
||||
p = __stpcpy(p, " into ");
|
||||
p = __stpcpy(p, info->array_type->name);
|
||||
p = __stpcpy(p, " out of bounds");
|
||||
p = __ubsan_stpcpy(p, " into ");
|
||||
p = __ubsan_stpcpy(p, info->array_type->name);
|
||||
p = __ubsan_stpcpy(p, " out of bounds");
|
||||
__ubsan_abort(&info->location, buf)();
|
||||
__ubsan_unreachable();
|
||||
}
|
||||
|
@ -294,19 +303,19 @@ static __ubsan_die_f *__ubsan_type_mismatch_handler(
|
|||
if (!pointer) return __ubsan_abort(&info->location, "null pointer access");
|
||||
kind = __ubsan_dubnul(kUbsanTypeCheckKinds, info->type_check_kind);
|
||||
if (info->alignment && (pointer & (info->alignment - 1))) {
|
||||
p = __stpcpy(p, "unaligned ");
|
||||
p = __stpcpy(p, kind), *p++ = ' ';
|
||||
p = __stpcpy(p, info->type->name), *p++ = ' ', *p++ = '@';
|
||||
p = __ubsan_stpcpy(p, "unaligned ");
|
||||
p = __ubsan_stpcpy(p, kind), *p++ = ' ';
|
||||
p = __ubsan_stpcpy(p, info->type->name), *p++ = ' ', *p++ = '@';
|
||||
p = __ubsan_itpcpy(p, info->type, pointer);
|
||||
p = __stpcpy(p, " align ");
|
||||
p = __ubsan_stpcpy(p, " align ");
|
||||
p = __intcpy(p, info->alignment);
|
||||
} else {
|
||||
p = __stpcpy(p, "insufficient size ");
|
||||
p = __stpcpy(p, kind);
|
||||
p = __stpcpy(p, " address 0x");
|
||||
p = __ubsan_stpcpy(p, "insufficient size ");
|
||||
p = __ubsan_stpcpy(p, kind);
|
||||
p = __ubsan_stpcpy(p, " address 0x");
|
||||
p = __fixcpy(p, pointer, sizeof(pointer) * CHAR_BIT);
|
||||
p = __stpcpy(p, " with insufficient space for object of type ");
|
||||
p = __stpcpy(p, info->type->name);
|
||||
p = __ubsan_stpcpy(p, " with insufficient space for object of type ");
|
||||
p = __ubsan_stpcpy(p, info->type->name);
|
||||
}
|
||||
return __ubsan_abort(&info->location, buf);
|
||||
}
|
||||
|
|
|
@ -20,9 +20,14 @@
|
|||
#include "tool/decode/lib/x86idnames.h"
|
||||
|
||||
const struct IdName kX86GradeNames[] = {
|
||||
{X86_GRADE_UNKNOWN, "Unknown"}, {X86_GRADE_APPLIANCE, "Appliance"},
|
||||
{X86_GRADE_MOBILE, "Mobile"}, {X86_GRADE_TABLET, "Tablet"},
|
||||
{X86_GRADE_DESKTOP, "Desktop"}, {X86_GRADE_CLIENT, "Client"},
|
||||
{X86_GRADE_DENSITY, "Density"}, {X86_GRADE_SERVER, "Server"},
|
||||
{X86_GRADE_SCIENCE, "Science"}, {0, 0},
|
||||
{X86_GRADE_UNKNOWN, "Unknown"}, //
|
||||
{X86_GRADE_APPLIANCE, "Appliance"}, //
|
||||
{X86_GRADE_MOBILE, "Mobile"}, //
|
||||
{X86_GRADE_TABLET, "Tablet"}, //
|
||||
{X86_GRADE_DESKTOP, "Desktop"}, //
|
||||
{X86_GRADE_CLIENT, "Client"}, //
|
||||
{X86_GRADE_DENSITY, "Density"}, //
|
||||
{X86_GRADE_SERVER, "Server"}, //
|
||||
{X86_GRADE_SCIENCE, "Science"}, //
|
||||
{0}, //
|
||||
};
|
||||
|
|
|
@ -20,27 +20,27 @@
|
|||
#include "tool/decode/lib/x86idnames.h"
|
||||
|
||||
const struct IdName kX86MarchNames[] = {
|
||||
{X86_MARCH_UNKNOWN, "Unknown"},
|
||||
{X86_MARCH_CORE2, "Core 2"},
|
||||
{X86_MARCH_NEHALEM, "Nehalem"},
|
||||
{X86_MARCH_WESTMERE, "Westmere"},
|
||||
{X86_MARCH_SANDYBRIDGE, "Sandybridge"},
|
||||
{X86_MARCH_IVYBRIDGE, "Ivybridge"},
|
||||
{X86_MARCH_HASWELL, "Haswell"},
|
||||
{X86_MARCH_BROADWELL, "Broadwell"},
|
||||
{X86_MARCH_SKYLAKE, "Skylake"},
|
||||
{X86_MARCH_KABYLAKE, "Kabylake"},
|
||||
{X86_MARCH_CANNONLAKE, "Cannonlake"},
|
||||
{X86_MARCH_ICELAKE, "Icelake"},
|
||||
{X86_MARCH_TIGERLAKE, "Tigerlake"},
|
||||
{X86_MARCH_BONNELL, "Bonnell"},
|
||||
{X86_MARCH_SALTWELL, "Saltwell"},
|
||||
{X86_MARCH_SILVERMONT, "Silvermont"},
|
||||
{X86_MARCH_AIRMONT, "Airmont"},
|
||||
{X86_MARCH_GOLDMONT, "Goldmont"},
|
||||
{X86_MARCH_GOLDMONTPLUS, "Goldmont Plus"},
|
||||
{X86_MARCH_TREMONT, "Tremont"},
|
||||
{X86_MARCH_KNIGHTSLANDING, "Knights Landing"},
|
||||
{X86_MARCH_KNIGHTSMILL, "Knights Mill"},
|
||||
{0, 0},
|
||||
{X86_MARCH_UNKNOWN, "Unknown"}, //
|
||||
{X86_MARCH_CORE2, "Core 2"}, //
|
||||
{X86_MARCH_NEHALEM, "Nehalem"}, //
|
||||
{X86_MARCH_WESTMERE, "Westmere"}, //
|
||||
{X86_MARCH_SANDYBRIDGE, "Sandybridge"}, //
|
||||
{X86_MARCH_IVYBRIDGE, "Ivybridge"}, //
|
||||
{X86_MARCH_HASWELL, "Haswell"}, //
|
||||
{X86_MARCH_BROADWELL, "Broadwell"}, //
|
||||
{X86_MARCH_SKYLAKE, "Skylake"}, //
|
||||
{X86_MARCH_KABYLAKE, "Kabylake"}, //
|
||||
{X86_MARCH_CANNONLAKE, "Cannonlake"}, //
|
||||
{X86_MARCH_ICELAKE, "Icelake"}, //
|
||||
{X86_MARCH_TIGERLAKE, "Tigerlake"}, //
|
||||
{X86_MARCH_BONNELL, "Bonnell"}, //
|
||||
{X86_MARCH_SALTWELL, "Saltwell"}, //
|
||||
{X86_MARCH_SILVERMONT, "Silvermont"}, //
|
||||
{X86_MARCH_AIRMONT, "Airmont"}, //
|
||||
{X86_MARCH_GOLDMONT, "Goldmont"}, //
|
||||
{X86_MARCH_GOLDMONTPLUS, "Goldmont Plus"}, //
|
||||
{X86_MARCH_TREMONT, "Tremont"}, //
|
||||
{X86_MARCH_KNIGHTSLANDING, "Knights Landing"}, //
|
||||
{X86_MARCH_KNIGHTSMILL, "Knights Mill"}, //
|
||||
{0}, //
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue