mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-25 12:00:31 +00:00
Avoid leaking handles across processes
This commit is contained in:
parent
a359de7893
commit
8a0008d985
44 changed files with 232 additions and 266 deletions
|
@ -28,7 +28,7 @@
|
|||
* @see System Five Application Binary Interface § 3.4.3
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
dontasan struct AuxiliaryValue __getauxval(unsigned long at) {
|
||||
struct AuxiliaryValue __getauxval(unsigned long at) {
|
||||
unsigned long *ap;
|
||||
for (ap = __auxv; ap[0]; ap += 2) {
|
||||
if (at == ap[0]) {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#define ToUpper(c) \
|
||||
(IsWindows() && (c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
|
||||
|
||||
dontasan privileged struct Env __getenv(char **p, const char *k) {
|
||||
privileged struct Env __getenv(char **p, const char *k) {
|
||||
char *t;
|
||||
int i, j;
|
||||
for (i = 0; (t = p[i]); ++i) {
|
||||
|
|
|
@ -773,7 +773,7 @@ static void __asan_report_memory_origin_image(intptr_t a, int z) {
|
|||
}
|
||||
}
|
||||
|
||||
static dontasan void __asan_onmemory(void *x, void *y, size_t n, void *a) {
|
||||
static void __asan_onmemory(void *x, void *y, size_t n, void *a) {
|
||||
const unsigned char *p = x;
|
||||
struct ReportOriginHeap *t = a;
|
||||
if ((p <= t->a && t->a < p + n) ||
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
#define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__)
|
||||
|
||||
dontinstrument dontasan const char *(DescribeBacktrace)(char buf[N],
|
||||
struct StackFrame *fr) {
|
||||
dontinstrument const char *(DescribeBacktrace)(char buf[N],
|
||||
struct StackFrame *fr) {
|
||||
bool gotsome = false;
|
||||
char *p = buf;
|
||||
char *pe = p + N;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
const char *(
|
||||
DescribeNtSecurityAttributes)(char buf[32],
|
||||
const struct NtSecurityAttributes *p) {
|
||||
if (p == &kNtIsInheritable) return "&kNtIsInheritable";
|
||||
FormatInt64(buf, (uintptr_t)p);
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -32,15 +32,15 @@
|
|||
|
||||
static uint64_t sys_mmap_metal_break;
|
||||
|
||||
dontasan static struct DirectMap bad_mmap(void) {
|
||||
static struct DirectMap bad_mmap(void) {
|
||||
struct DirectMap res;
|
||||
res.addr = (void *)-1;
|
||||
res.maphandle = -1;
|
||||
return res;
|
||||
}
|
||||
|
||||
dontasan struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot,
|
||||
int flags, int fd, int64_t off) {
|
||||
struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot, int flags,
|
||||
int fd, int64_t off) {
|
||||
/* asan runtime depends on this function */
|
||||
size_t i;
|
||||
struct mman *mm;
|
||||
|
|
|
@ -42,13 +42,6 @@ textwindows struct DirectMap sys_mmap_nt(void *addr, size_t size, int prot,
|
|||
handle = g_fds.p[fd].handle;
|
||||
}
|
||||
|
||||
const struct NtSecurityAttributes *sec;
|
||||
if ((flags & MAP_TYPE) != MAP_SHARED) {
|
||||
sec = 0; // MAP_PRIVATE isn't inherited across fork()
|
||||
} else {
|
||||
sec = &kNtIsInheritable; // MAP_SHARED gives us zero-copy fork()
|
||||
}
|
||||
|
||||
// nt will whine under many circumstances if we change the execute bit
|
||||
// later using mprotect(). the workaround is to always request execute
|
||||
// and then virtualprotect() it away until we actually need it. please
|
||||
|
@ -80,7 +73,7 @@ textwindows struct DirectMap sys_mmap_nt(void *addr, size_t size, int prot,
|
|||
int e = errno;
|
||||
struct DirectMap dm;
|
||||
TryAgain:
|
||||
if ((dm.maphandle = CreateFileMapping(handle, sec, fl.flags1,
|
||||
if ((dm.maphandle = CreateFileMapping(handle, 0, fl.flags1,
|
||||
(size + off) >> 32, (size + off), 0))) {
|
||||
if ((dm.addr = MapViewOfFileEx(dm.maphandle, fl.flags2, off >> 32, off,
|
||||
size, addr))) {
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#define G FRAMESIZE
|
||||
|
||||
static dontasan void *_mapframe(void *p, int f) {
|
||||
static void *_mapframe(void *p, int f) {
|
||||
int rc, prot, flags;
|
||||
struct DirectMap dm;
|
||||
prot = PROT_READ | PROT_WRITE;
|
||||
|
@ -73,7 +73,7 @@ static dontasan void *_mapframe(void *p, int f) {
|
|||
* @return new value for `e` or null w/ errno
|
||||
* @raise ENOMEM if we require more vespene gas
|
||||
*/
|
||||
dontasan void *_extend(void *p, size_t n, void *e, int f, intptr_t h) {
|
||||
void *_extend(void *p, size_t n, void *e, int f, intptr_t h) {
|
||||
char *q;
|
||||
unassert(!((uintptr_t)SHADOW(p) & (G - 1)));
|
||||
unassert((uintptr_t)p + (G << kAsanScale) <= h);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
|
||||
dontasan unsigned __find_memory(const struct MemoryIntervals *mm, int x) {
|
||||
unsigned __find_memory(const struct MemoryIntervals *mm, int x) {
|
||||
unsigned l, m, r;
|
||||
l = 0;
|
||||
r = mm->i;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @param delta is added to enabled state
|
||||
* @return enabled state before `delta` was applied
|
||||
*/
|
||||
dontasan dontubsan dontinstrument int ftrace_enabled(int delta) {
|
||||
dontinstrument int ftrace_enabled(int delta) {
|
||||
int res;
|
||||
struct CosmoTib *tib;
|
||||
if (__tls_enabled) {
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
* @threadsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
dontasan int getpid(void) {
|
||||
int getpid(void) {
|
||||
int rc;
|
||||
if (IsMetal()) {
|
||||
rc = 1;
|
||||
|
|
62
libc/intrin/handlock.c
Normal file
62
libc/intrin/handlock.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*-*- 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 2023 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/dce.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
|
||||
/**
|
||||
* @fileoverview r/w lock for maanging windows file inheritence
|
||||
*/
|
||||
|
||||
static nsync_mu __hand_mu;
|
||||
|
||||
void __hand_init(void) {
|
||||
if (!SupportsWindows()) return;
|
||||
bzero(&__hand_mu, sizeof(__hand_mu));
|
||||
}
|
||||
|
||||
void __hand_rlock(void) {
|
||||
if (!IsWindows()) return;
|
||||
if (_weaken(nsync_mu_rlock) && __threaded) {
|
||||
_weaken(nsync_mu_rlock)(&__hand_mu);
|
||||
}
|
||||
}
|
||||
|
||||
void __hand_runlock(void) {
|
||||
if (!IsWindows()) return;
|
||||
if (_weaken(nsync_mu_runlock) && __threaded) {
|
||||
_weaken(nsync_mu_runlock)(&__hand_mu);
|
||||
}
|
||||
}
|
||||
|
||||
void __hand_lock(void) {
|
||||
if (!IsWindows()) return;
|
||||
if (_weaken(nsync_mu_lock) && __threaded) {
|
||||
_weaken(nsync_mu_lock)(&__hand_mu);
|
||||
}
|
||||
}
|
||||
|
||||
void __hand_unlock(void) {
|
||||
if (!IsWindows()) return;
|
||||
if (_weaken(nsync_mu_unlock) && __threaded) {
|
||||
_weaken(nsync_mu_unlock)(&__hand_mu);
|
||||
}
|
||||
}
|
14
libc/intrin/handlock.internal.h
Normal file
14
libc/intrin/handlock.internal.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_HANDLOCK_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_HANDLOCK_INTERNAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void __hand_init(void);
|
||||
void __hand_rlock(void);
|
||||
void __hand_runlock(void);
|
||||
void __hand_lock(void);
|
||||
void __hand_unlock(void);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_HANDLOCK_INTERNAL_H_ */
|
|
@ -46,31 +46,11 @@ $(LIBC_INTRIN_A).pkg: \
|
|||
$(LIBC_INTRIN_A_OBJS) \
|
||||
$(foreach x,$(LIBC_INTRIN_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
# we can't use asan because:
|
||||
# __strace_init() calls this before asan is initialized
|
||||
o/$(MODE)/libc/intrin/strace_enabled.o: private \
|
||||
COPTS += \
|
||||
-fno-sanitize=address
|
||||
o/$(MODE)/libc/intrin/mman.greg.o: private COPTS += -Os
|
||||
|
||||
# we can't use asan because:
|
||||
# asan guard pages haven't been allocated yet
|
||||
o/$(MODE)/libc/intrin/directmap.o \
|
||||
o/$(MODE)/libc/intrin/directmap-nt.o: private \
|
||||
COPTS += \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=address
|
||||
|
||||
# we want small code size because:
|
||||
# to keep .text.head under 4096 bytes
|
||||
o/$(MODE)/libc/intrin/mman.greg.o: private \
|
||||
COPTS += \
|
||||
-Os
|
||||
|
||||
# we can't use asan and ubsan because:
|
||||
# this is asan and ubsan
|
||||
o/$(MODE)/libc/intrin/asan.o \
|
||||
o/$(MODE)/libc/intrin/ubsan.o: private \
|
||||
$(LIBC_INTRIN_A_OBJS): private \
|
||||
CFLAGS += \
|
||||
-x-no-pg \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=all \
|
||||
-fno-stack-protector
|
||||
|
@ -81,121 +61,6 @@ o/$(MODE)/libc/intrin/asan.o: private \
|
|||
-finline \
|
||||
-finline-functions
|
||||
|
||||
o/$(MODE)/libc/intrin/asanthunk.o: private \
|
||||
CFLAGS += \
|
||||
-x-no-pg \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=all \
|
||||
-fno-stack-protector
|
||||
|
||||
# we can't use compiler magic because:
|
||||
# kprintf() is mission critical to error reporting
|
||||
o/$(MODE)/libc/intrin/getmagnumstr.greg.o \
|
||||
o/$(MODE)/libc/intrin/strerrno.greg.o \
|
||||
o/$(MODE)/libc/intrin/strerrdoc.greg.o \
|
||||
o/$(MODE)/libc/intrin/strerror_wr.greg.o \
|
||||
o/$(MODE)/libc/intrin/kprintf.greg.o: private \
|
||||
CFLAGS += \
|
||||
-fpie \
|
||||
-fwrapv \
|
||||
-x-no-pg \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=all \
|
||||
-fno-stack-protector
|
||||
|
||||
# TODO(jart): Do we really need these?
|
||||
# synchronization primitives are intended to be magic free
|
||||
o/$(MODE)/libc/intrin/futex_wait.o \
|
||||
o/$(MODE)/libc/intrin/futex_wake.o \
|
||||
o/$(MODE)/libc/intrin/gettid.greg.o \
|
||||
o/$(MODE)/libc/intrin/_trylock_debug_4.o \
|
||||
o/$(MODE)/libc/intrin/_spinlock_debug_4.o: private \
|
||||
CFLAGS += \
|
||||
-fwrapv \
|
||||
-x-no-pg \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=all \
|
||||
-mgeneral-regs-only \
|
||||
-fno-stack-protector
|
||||
|
||||
# we can't use asan because:
|
||||
# global gone could be raised
|
||||
o/$(MODE)/libc/intrin/exit.o \
|
||||
o/$(MODE)/libc/intrin/restorewintty.o: private \
|
||||
CFLAGS += \
|
||||
-fno-sanitize=all
|
||||
|
||||
# we can't use -ftrapv because:
|
||||
# this file implements it
|
||||
o/$(MODE)/libc/intrin/ftrapv.o: private \
|
||||
CFLAGS += \
|
||||
-ffunction-sections \
|
||||
-ffreestanding \
|
||||
-fwrapv
|
||||
|
||||
# we can't use asan because:
|
||||
# sys_mmap() calls these which sets up shadow memory
|
||||
o/$(MODE)/libc/intrin/describeflags.o \
|
||||
o/$(MODE)/libc/intrin/describeframe.o \
|
||||
o/$(MODE)/libc/intrin/describemapflags.o \
|
||||
o/$(MODE)/libc/intrin/describeprotflags.o: private \
|
||||
CFLAGS += \
|
||||
-fno-sanitize=address
|
||||
|
||||
o/$(MODE)/libc/intrin/exit1.greg.o \
|
||||
o/$(MODE)/libc/intrin/wsarecv.o \
|
||||
o/$(MODE)/libc/intrin/wsarecvfrom.o \
|
||||
o/$(MODE)/libc/intrin/createfile.o \
|
||||
o/$(MODE)/libc/intrin/reopenfile.o \
|
||||
o/$(MODE)/libc/intrin/deletefile.o \
|
||||
o/$(MODE)/libc/intrin/createpipe.o \
|
||||
o/$(MODE)/libc/intrin/closehandle.o \
|
||||
o/$(MODE)/libc/intrin/openprocess.o \
|
||||
o/$(MODE)/libc/intrin/createthread.o \
|
||||
o/$(MODE)/libc/intrin/findclose.o \
|
||||
o/$(MODE)/libc/intrin/findnextfile.o \
|
||||
o/$(MODE)/libc/intrin/createprocess.o \
|
||||
o/$(MODE)/libc/intrin/findfirstfile.o \
|
||||
o/$(MODE)/libc/intrin/removedirectory.o \
|
||||
o/$(MODE)/libc/intrin/createsymboliclink.o \
|
||||
o/$(MODE)/libc/intrin/createnamedpipe.o \
|
||||
o/$(MODE)/libc/intrin/unmapviewoffile.o \
|
||||
o/$(MODE)/libc/intrin/virtualprotect.o \
|
||||
o/$(MODE)/libc/intrin/flushviewoffile.o \
|
||||
o/$(MODE)/libc/intrin/createdirectory.o \
|
||||
o/$(MODE)/libc/intrin/flushfilebuffers.o \
|
||||
o/$(MODE)/libc/intrin/terminateprocess.o \
|
||||
o/$(MODE)/libc/intrin/getfileattributes.o \
|
||||
o/$(MODE)/libc/intrin/getexitcodeprocess.o \
|
||||
o/$(MODE)/libc/intrin/waitforsingleobject.o \
|
||||
o/$(MODE)/libc/intrin/setcurrentdirectory.o \
|
||||
o/$(MODE)/libc/intrin/mapviewoffileex.o \
|
||||
o/$(MODE)/libc/intrin/movefileex.o \
|
||||
o/$(MODE)/libc/intrin/mapviewoffileexnuma.o \
|
||||
o/$(MODE)/libc/intrin/createfilemapping.o \
|
||||
o/$(MODE)/libc/intrin/createfilemappingnuma.o \
|
||||
o/$(MODE)/libc/intrin/waitformultipleobjects.o \
|
||||
o/$(MODE)/libc/intrin/wsagetoverlappedresult.o \
|
||||
o/$(MODE)/libc/intrin/generateconsolectrlevent.o \
|
||||
o/$(MODE)/libc/intrin/wsawaitformultipleevents.o: private\
|
||||
CFLAGS += \
|
||||
-Os \
|
||||
-fwrapv \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-sanitize=all
|
||||
|
||||
# privileged functions
|
||||
o/$(MODE)/libc/intrin/dos2errno.o \
|
||||
o/$(MODE)/libc/intrin/have_fsgsbase.o \
|
||||
o/$(MODE)/libc/intrin/getmagnumstr.o \
|
||||
o/$(MODE)/libc/intrin/formatint32.o \
|
||||
o/$(MODE)/libc/intrin/strsignal_r.o \
|
||||
o/$(MODE)/libc/intrin/strerror_wr.o: private \
|
||||
CFLAGS += \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=all
|
||||
|
||||
o//libc/intrin/memmove.o: private \
|
||||
CFLAGS += \
|
||||
-fno-toplevel-reorder
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#define kBufSize 1024
|
||||
#define kPid "TracerPid:\t"
|
||||
|
||||
static textwindows dontasan bool IsBeingDebugged(void) {
|
||||
static textwindows bool IsBeingDebugged(void) {
|
||||
return !!NtGetPeb()->BeingDebugged;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,9 +36,8 @@ static inline const unsigned char *memchr_pure(const unsigned char *s,
|
|||
}
|
||||
|
||||
#if defined(__x86_64__) && !defined(__chibicc__)
|
||||
dontasan static inline const unsigned char *memchr_sse(const unsigned char *s,
|
||||
unsigned char c,
|
||||
size_t n) {
|
||||
static inline const unsigned char *memchr_sse(const unsigned char *s,
|
||||
unsigned char c, size_t n) {
|
||||
size_t i;
|
||||
unsigned m;
|
||||
xmm_t v, t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
|
||||
|
@ -68,7 +67,7 @@ dontasan static inline const unsigned char *memchr_sse(const unsigned char *s,
|
|||
* @return is pointer to first instance of c or NULL if not found
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
dontasan void *memchr(const void *s, int c, size_t n) {
|
||||
void *memchr(const void *s, int c, size_t n) {
|
||||
#if defined(__x86_64__) && !defined(__chibicc__)
|
||||
const void *r;
|
||||
if (IsAsan()) __asan_verify(s, n);
|
||||
|
|
|
@ -37,9 +37,8 @@ static inline const unsigned char *memrchr_pure(const unsigned char *s,
|
|||
}
|
||||
|
||||
#if defined(__x86_64__) && !defined(__chibicc__)
|
||||
dontasan static inline const unsigned char *memrchr_sse(const unsigned char *s,
|
||||
unsigned char c,
|
||||
size_t n) {
|
||||
static inline const unsigned char *memrchr_sse(const unsigned char *s,
|
||||
unsigned char c, size_t n) {
|
||||
size_t i;
|
||||
unsigned m;
|
||||
xmm_t v, t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
|
||||
|
|
|
@ -54,7 +54,7 @@ struct ReclaimedPage {
|
|||
/**
|
||||
* Allocates new page of physical memory.
|
||||
*/
|
||||
dontasan texthead uint64_t __new_page(struct mman *mm) {
|
||||
texthead uint64_t __new_page(struct mman *mm) {
|
||||
uint64_t p = mm->frp;
|
||||
if (p != NOPAGE) {
|
||||
uint64_t q;
|
||||
|
@ -81,8 +81,8 @@ dontasan texthead uint64_t __new_page(struct mman *mm) {
|
|||
* Returns pointer to page table entry for page at virtual address.
|
||||
* Additional page tables are allocated if needed as a side-effect.
|
||||
*/
|
||||
dontasan textreal uint64_t *__get_virtual(struct mman *mm, uint64_t *t,
|
||||
int64_t vaddr, bool maketables) {
|
||||
textreal uint64_t *__get_virtual(struct mman *mm, uint64_t *t, int64_t vaddr,
|
||||
bool maketables) {
|
||||
uint64_t *e, p;
|
||||
unsigned char h;
|
||||
for (h = 39;; h -= 9) {
|
||||
|
@ -101,7 +101,7 @@ dontasan textreal uint64_t *__get_virtual(struct mman *mm, uint64_t *t,
|
|||
/**
|
||||
* Sorts, rounds, and filters BIOS memory map.
|
||||
*/
|
||||
static dontasan textreal void __normalize_e820(struct mman *mm, uint64_t top) {
|
||||
static textreal void __normalize_e820(struct mman *mm, uint64_t top) {
|
||||
uint64_t a, b;
|
||||
uint64_t x, y;
|
||||
unsigned i, j, n;
|
||||
|
@ -134,10 +134,9 @@ static dontasan textreal void __normalize_e820(struct mman *mm, uint64_t top) {
|
|||
/**
|
||||
* Identity maps an area of physical memory to its negative address.
|
||||
*/
|
||||
dontasan textreal uint64_t *__invert_memory_area(struct mman *mm,
|
||||
uint64_t *pml4t, uint64_t ps,
|
||||
uint64_t size,
|
||||
uint64_t pte_flags) {
|
||||
textreal uint64_t *__invert_memory_area(struct mman *mm, uint64_t *pml4t,
|
||||
uint64_t ps, uint64_t size,
|
||||
uint64_t pte_flags) {
|
||||
uint64_t pe = ps + size, p, *m = NULL;
|
||||
ps = ROUNDDOWN(ps, 4096);
|
||||
pe = ROUNDUP(pe, 4096);
|
||||
|
@ -153,7 +152,7 @@ dontasan textreal uint64_t *__invert_memory_area(struct mman *mm,
|
|||
/**
|
||||
* Increments the reference count for a page of physical memory.
|
||||
*/
|
||||
dontasan void __ref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
|
||||
void __ref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
|
||||
uint64_t *m, e;
|
||||
m = __invert_memory_area(mm, pml4t, p, 4096, PAGE_RW | PAGE_XD);
|
||||
if (m) {
|
||||
|
@ -168,8 +167,7 @@ dontasan void __ref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
|
|||
/**
|
||||
* Increments the reference counts for an area of physical memory.
|
||||
*/
|
||||
dontasan void __ref_pages(struct mman *mm, uint64_t *pml4t, uint64_t ps,
|
||||
uint64_t size) {
|
||||
void __ref_pages(struct mman *mm, uint64_t *pml4t, uint64_t ps, uint64_t size) {
|
||||
uint64_t p = ROUNDDOWN(ps, 4096), e = ROUNDUP(ps + size, 4096);
|
||||
while (p != e) {
|
||||
__ref_page(mm, pml4t, p);
|
||||
|
@ -180,7 +178,7 @@ dontasan void __ref_pages(struct mman *mm, uint64_t *pml4t, uint64_t ps,
|
|||
/**
|
||||
* Reclaims a page of physical memory for later use.
|
||||
*/
|
||||
static dontasan void __reclaim_page(struct mman *mm, uint64_t p) {
|
||||
static void __reclaim_page(struct mman *mm, uint64_t p) {
|
||||
struct ReclaimedPage *rp = (struct ReclaimedPage *)(BANE + p);
|
||||
unassert(p == (p & PAGE_TA));
|
||||
rp->next = mm->frp;
|
||||
|
@ -192,7 +190,7 @@ static dontasan void __reclaim_page(struct mman *mm, uint64_t p) {
|
|||
* page if there are no virtual addresses (excluding the negative space)
|
||||
* referring to it.
|
||||
*/
|
||||
dontasan void __unref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
|
||||
void __unref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
|
||||
uint64_t *m, e;
|
||||
m = __invert_memory_area(mm, pml4t, p, 4096, PAGE_RW | PAGE_XD);
|
||||
if (m) {
|
||||
|
@ -208,8 +206,7 @@ dontasan void __unref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
|
|||
/**
|
||||
* Identity maps all usable physical memory to its negative address.
|
||||
*/
|
||||
static dontasan textreal void __invert_memory(struct mman *mm,
|
||||
uint64_t *pml4t) {
|
||||
static textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) {
|
||||
uint64_t i;
|
||||
for (i = 0; i < mm->e820n; ++i) {
|
||||
uint64_t ps = mm->e820[i].addr, size = mm->e820[i].size;
|
||||
|
@ -232,8 +229,7 @@ static dontasan textreal void __invert_memory(struct mman *mm,
|
|||
: "i"(offsetof(type, member))); \
|
||||
} while (0)
|
||||
|
||||
dontasan textreal void __setup_mman(struct mman *mm, uint64_t *pml4t,
|
||||
uint64_t top) {
|
||||
textreal void __setup_mman(struct mman *mm, uint64_t *pml4t, uint64_t top) {
|
||||
export_offsetof(struct mman, pc_drive_base_table);
|
||||
export_offsetof(struct mman, pc_drive_last_sector);
|
||||
export_offsetof(struct mman, pc_drive_last_head);
|
||||
|
@ -259,8 +255,8 @@ dontasan textreal void __setup_mman(struct mman *mm, uint64_t *pml4t,
|
|||
/**
|
||||
* Maps APE-defined ELF program headers into memory and clears BSS.
|
||||
*/
|
||||
dontasan textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b,
|
||||
uint64_t top) {
|
||||
textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b,
|
||||
uint64_t top) {
|
||||
uint64_t i, f, v, m;
|
||||
struct Elf64_Phdr *p;
|
||||
extern char ape_phdrs[] __attribute__((__weak__));
|
||||
|
@ -294,9 +290,8 @@ dontasan textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b,
|
|||
* Reclaims memory pages which were used at boot time but which can now be
|
||||
* made available for the application.
|
||||
*/
|
||||
dontasan textreal void __reclaim_boot_pages(struct mman *mm,
|
||||
uint64_t skip_start,
|
||||
uint64_t skip_end) {
|
||||
textreal void __reclaim_boot_pages(struct mman *mm, uint64_t skip_start,
|
||||
uint64_t skip_end) {
|
||||
uint64_t p = mm->frp, q = IMAGE_BASE_REAL, i, n = mm->e820n, b, e;
|
||||
for (i = 0; i < n; ++i) {
|
||||
b = mm->e820[i].addr;
|
||||
|
|
|
@ -48,9 +48,8 @@
|
|||
*/
|
||||
bool __nocolor;
|
||||
|
||||
optimizesize textstartup dontasan void __nocolor_init(int argc, char **argv,
|
||||
char **envp,
|
||||
intptr_t *auxv) {
|
||||
optimizesize textstartup void __nocolor_init(int argc, char **argv, char **envp,
|
||||
intptr_t *auxv) {
|
||||
char *s;
|
||||
__nocolor = (IsWindows() && !IsAtLeastWindows10()) ||
|
||||
((s = getenv("TERM")) && IsDumb(s));
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
*
|
||||
* @see IsAtLeastWindows10()
|
||||
*/
|
||||
textwindows dontasan int NtGetVersion(void) {
|
||||
textwindows int NtGetVersion(void) {
|
||||
return (NtGetPeb()->OSMajorVersion & 0xff) << 8 | NtGetPeb()->OSMinorVersion;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|||
* @return pointer to nul byte
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
dontasan char *stpcpy(char *d, const char *s) {
|
||||
char *stpcpy(char *d, const char *s) {
|
||||
size_t i = 0;
|
||||
if (IsAsan()) {
|
||||
__asan_verify(d, strlen(s) + 1);
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
|
||||
#define _KERNTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _POLLTRACE 1 /* not configurable w/ flag yet */
|
||||
#define _POLLTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _DATATRACE 1 /* not configurable w/ flag yet */
|
||||
#define _STDIOTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _LOCKTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _NTTRACE 1 /* not configurable w/ flag yet */
|
||||
#define _NTTRACE 0 /* not configurable w/ flag yet */
|
||||
|
||||
#define STRACE_PROLOGUE "%rSYS %6P %'18T "
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @param delta is added to enabled state
|
||||
* @return enabled state before `delta` was applied
|
||||
*/
|
||||
dontasan dontubsan dontinstrument int strace_enabled(int delta) {
|
||||
dontinstrument int strace_enabled(int delta) {
|
||||
int res;
|
||||
struct CosmoTib *tib;
|
||||
if (__tls_enabled) {
|
||||
|
|
|
@ -32,7 +32,7 @@ static inline const char *strchr_pure(const char *s, int c) {
|
|||
|
||||
#if defined(__x86_64__) && !defined(__chibicc__)
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
dontasan static inline const char *strchr_sse(const char *s, unsigned char c) {
|
||||
static inline const char *strchr_sse(const char *s, unsigned char c) {
|
||||
unsigned k;
|
||||
unsigned m;
|
||||
const xmm_t *p;
|
||||
|
@ -56,7 +56,7 @@ dontasan static inline const char *strchr_sse(const char *s, unsigned char c) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static dontasan inline const char *strchr_x64(const char *p, uint64_t c) {
|
||||
static inline const char *strchr_x64(const char *p, uint64_t c) {
|
||||
unsigned a, b;
|
||||
uint64_t w, x, y;
|
||||
for (c *= 0x0101010101010101;; p += 8) {
|
||||
|
@ -95,7 +95,7 @@ static dontasan inline const char *strchr_x64(const char *p, uint64_t c) {
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
dontasan char *strchr(const char *s, int c) {
|
||||
char *strchr(const char *s, int c) {
|
||||
if (IsAsan()) __asan_verify_str(s);
|
||||
#if defined(__x86_64__) && !defined(__chibicc__)
|
||||
const char *r;
|
||||
|
|
|
@ -32,8 +32,7 @@ static inline const char *strchrnul_pure(const char *s, int c) {
|
|||
|
||||
#if defined(__x86_64__) && !defined(__chibicc__)
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
dontasan static inline const char *strchrnul_sse(const char *s,
|
||||
unsigned char c) {
|
||||
static inline const char *strchrnul_sse(const char *s, unsigned char c) {
|
||||
unsigned k;
|
||||
unsigned m;
|
||||
const xmm_t *p;
|
||||
|
@ -54,7 +53,7 @@ dontasan static inline const char *strchrnul_sse(const char *s,
|
|||
}
|
||||
#endif
|
||||
|
||||
dontasan static const char *strchrnul_x64(const char *p, uint64_t c) {
|
||||
static const char *strchrnul_x64(const char *p, uint64_t c) {
|
||||
unsigned a, b;
|
||||
uint64_t w, x, y;
|
||||
for (c *= 0x0101010101010101;; p += 8) {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* @return is <0, 0, or >0 based on uint8_t comparison
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
dontasan int strcmp(const char *a, const char *b) {
|
||||
int strcmp(const char *a, const char *b) {
|
||||
int c;
|
||||
size_t i = 0;
|
||||
uint64_t v, w;
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|||
* @return original dest
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
dontasan char *strcpy(char *d, const char *s) {
|
||||
char *strcpy(char *d, const char *s) {
|
||||
size_t i = 0;
|
||||
if (IsAsan()) {
|
||||
__asan_verify_str(s);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
// clang-format off
|
||||
|
||||
#if defined(SYSDEBUG) && _NTTRACE
|
||||
dontasan dontubsan privileged
|
||||
privileged
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
// clang-format off
|
||||
|
||||
#if defined(SYSDEBUG) && _NTTRACE
|
||||
dontasan dontubsan privileged
|
||||
privileged
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
* @return number of bytes (excluding NUL)
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
dontasan size_t strlen(const char *s) {
|
||||
size_t strlen(const char *s) {
|
||||
if (IsAsan()) __asan_verify_str(s);
|
||||
#if defined(__x86_64__) && !defined(__chibicc__)
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#ifndef __aarch64__
|
||||
|
||||
static dontasan size_t strnlen_x64(const char *s, size_t n, size_t i) {
|
||||
static size_t strnlen_x64(const char *s, size_t n, size_t i) {
|
||||
uint64_t w;
|
||||
for (; i + 8 < n; i += 8) {
|
||||
w = *(uint64_t *)(s + i);
|
||||
|
@ -43,7 +43,7 @@ static dontasan size_t strnlen_x64(const char *s, size_t n, size_t i) {
|
|||
* @return byte length
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
dontasan size_t strnlen(const char *s, size_t n) {
|
||||
size_t strnlen(const char *s, size_t n) {
|
||||
size_t i;
|
||||
if (IsAsan() && n) __asan_verify(s, 1);
|
||||
for (i = 0; (uintptr_t)(s + i) & 7; ++i) {
|
||||
|
|
|
@ -31,6 +31,6 @@ char *strrchr(const char *s, int c) {
|
|||
return memrchr(s, c, strlen(s));
|
||||
}
|
||||
|
||||
__strong_reference(strrchr, rindex);
|
||||
__weak_reference(strrchr, rindex);
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue