Fix build breakage in MODE=dbg

This commit is contained in:
Justine Tunney 2022-06-15 19:13:47 -07:00
parent e466dd0553
commit fae2a17d2c
6 changed files with 57 additions and 30 deletions

View file

@ -23,15 +23,18 @@
noasan bool AreMemoryIntervalsOk(const struct MemoryIntervals *mm) { noasan bool AreMemoryIntervalsOk(const struct MemoryIntervals *mm) {
/* asan runtime depends on this function */ /* asan runtime depends on this function */
int i; int i;
size_t wantsize;
for (i = 0; i < mm->i; ++i) { for (i = 0; i < mm->i; ++i) {
if (mm->p[i].y < mm->p[i].x) { if (mm->p[i].y < mm->p[i].x) {
STRACE("AreMemoryIntervalsOk() y should be >= x!"); STRACE("AreMemoryIntervalsOk() y should be >= x!");
return false; return false;
} }
if (!(mm->p[i].size <= wantsize = (size_t)(mm->p[i].y - mm->p[i].x) * FRAMESIZE;
(size_t)(mm->p[i].y - mm->p[i].x) * FRAMESIZE + FRAMESIZE && if (!(wantsize < mm->p[i].size && mm->p[i].size <= wantsize + FRAMESIZE)) {
mm->p[i].size > (size_t)(mm->p[i].y - mm->p[i].x) * FRAMESIZE)) { STRACE("AreMemoryIntervalsOk(%p) size is wrong!"
STRACE("AreMemoryIntervalsOk() size is wrong!"); " %'zu not within %'zu .. %'zu",
(uintptr_t)mm->p[i].x << 16, mm->p[i].size, wantsize,
wantsize + FRAMESIZE);
return false; return false;
} }
if (i) { if (i) {

View file

@ -96,6 +96,13 @@ o/$(MODE)/libc/calls/mkntenvblock.o: \
-ffreestanding \ -ffreestanding \
-fno-sanitize=address -fno-sanitize=address
# we can't use sanitizers because:
# windows owns the data structure
o/$(MODE)/libc/calls/wincrash.o \
o/$(MODE)/libc/calls/ntcontext2linux.o: \
OVERRIDE_COPTS += \
-fno-sanitize=all
# we always want -O3 because: # we always want -O3 because:
# it makes the code size smaller too # it makes the code size smaller too
o/$(MODE)/libc/calls/sigenter-freebsd.o \ o/$(MODE)/libc/calls/sigenter-freebsd.o \

View file

@ -88,6 +88,13 @@ o/$(MODE)/libc/intrin/_spinlock_debug_4.o: \
-mgeneral-regs-only \ -mgeneral-regs-only \
-fno-stack-protector -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: \
OVERRIDE_CFLAGS += \
-fno-sanitize=all
o/$(MODE)/libc/intrin/tls.greg.o \ o/$(MODE)/libc/intrin/tls.greg.o \
o/$(MODE)/libc/intrin/exit.greg.o \ o/$(MODE)/libc/intrin/exit.greg.o \
o/$(MODE)/libc/intrin/exit1.greg.o \ o/$(MODE)/libc/intrin/exit1.greg.o \

View file

@ -26,10 +26,12 @@ COSMOPOLITAN_C_START_
#define kFixedmapStart _kMem(0x300000000000, 0x000040000000) #define kFixedmapStart _kMem(0x300000000000, 0x000040000000)
#define kFixedmapSize \ #define kFixedmapSize \
_kMem(0x400000000000 - 0x300000000000, 0x000070000000 - 0x000040000000) _kMem(0x400000000000 - 0x300000000000, 0x000070000000 - 0x000040000000)
#define kMemtrackFdsStart _kMem(0x6fe000000000, 0x80000000) #define kMemtrackFdsStart \
#define kMemtrackFdsSize _kMem(0x001000000000, 0x04000000) (ROUNDDOWN(_kMem(0x6fe000000000, 0x68000000), FRAMESIZE * 8) - 0x8000 * 8)
#define kMemtrackZiposStart _kMem(0x6fd000000000, 0x84000000) #define kMemtrackFdsSize _kMem(0x001000000000, 0x04000000)
#define kMemtrackZiposSize _kMem(0x001000000000, 0x20000000) #define kMemtrackZiposStart \
(ROUNDDOWN(_kMem(0x6fd000000000, 0x6c000000), FRAMESIZE * 8) - 0x8000 * 8)
#define kMemtrackZiposSize _kMem(0x001000000000, 0x10000000)
#define _kMmi(VSPACE) \ #define _kMmi(VSPACE) \
ROUNDUP(VSPACE / FRAMESIZE * (intptr_t)sizeof(struct MemoryInterval), \ ROUNDUP(VSPACE / FRAMESIZE * (intptr_t)sizeof(struct MemoryInterval), \
FRAMESIZE) FRAMESIZE)

View file

@ -40,22 +40,22 @@
00005c00-00005fff 64mb arena 00005c00-00005fff 64mb arena
00006000-000063ff 64mb arena 00006000-000063ff 64mb arena
00006400-000067ff 64mb arena 00006400-000067ff 64mb arena
00006800-00006bff 64mb arena 00006800-00006bff 64mb fds
00006c00-00006fff 64mb arena 00006c00-00006fff 64mb zipos
00007000-000073ff 64mb arena 00007000-000073ff 64mb zipos
00007400-000077ff 64mb arena 00007400-000077ff 64mb zipos
00007800-00007bff 64mb arena 00007800-00007bff 64mb zipos
00007c00-00007ffd 64mb arena 00007c00-00007ffd 64mb arena
00007ffe-00007fff 128kb free 00007ffe-00007fff 128kb free
00008000-000083ff 64mb fds 00008000-000083ff 64mb free
00008400-000087ff 64mb zipos 00008400-000087ff 64mb free
00008800-00008bff 64mb zipos 00008800-00008bff 64mb free
00008c00-00008fff 64mb zipos 00008c00-00008fff 64mb free
00009000-000093ff 64mb zipos 00009000-000093ff 64mb free
00009400-000097ff 64mb zipos 00009400-000097ff 64mb free
00009800-00009bff 64mb zipos 00009800-00009bff 64mb free
00009c00-00009fff 64mb zipos 00009c00-00009fff 64mb free
0000a000-0000a3ff 64mb zipos 0000a000-0000a3ff 64mb free
0000a400-0000a7ff 64mb free 0000a400-0000a7ff 64mb free
0000a800-0000abff 64mb free 0000a800-0000abff 64mb free
0000ac00-0000afff 64mb free 0000ac00-0000afff 64mb free

View file

@ -47,14 +47,15 @@
static volatile size_t maptotal; static volatile size_t maptotal;
static pureconst size_t __zipos_granularity(void) { static pureconst size_t __zipos_granularity(void) {
return (IsWindows() ? FRAMESIZE : PAGESIZE) * (IsAsan() ? 8 : 1); return FRAMESIZE * (IsAsan() ? 8 : 1);
} }
static void *__zipos_mmap(size_t mapsize) { static void *__zipos_mmap(size_t mapsize) {
size_t offset; size_t offset;
int prot, flags;
struct DirectMap dm; struct DirectMap dm;
uint64_t addr, addr2; int rc, prot, flags;
uint64_t addr, addr2, addr3;
assert(mapsize);
do offset = maptotal; do offset = maptotal;
while (!_cmpxchg(&maptotal, offset, maptotal + mapsize)); while (!_cmpxchg(&maptotal, offset, maptotal + mapsize));
if (offset + mapsize <= kMemtrackZiposSize) { if (offset + mapsize <= kMemtrackZiposSize) {
@ -63,14 +64,21 @@ static void *__zipos_mmap(size_t mapsize) {
addr = kMemtrackZiposStart + offset; addr = kMemtrackZiposStart + offset;
if ((dm = sys_mmap((void *)addr, mapsize, prot, flags, -1, 0)).addr != if ((dm = sys_mmap((void *)addr, mapsize, prot, flags, -1, 0)).addr !=
MAP_FAILED) { MAP_FAILED) {
TrackMemoryInterval(&_mmi, addr >> 16, (addr + mapsize - 1) >> 16, rc = TrackMemoryInterval(&_mmi, addr >> 16, (addr + mapsize - 1) >> 16,
dm.maphandle, prot, flags, false, false, 0, mapsize); dm.maphandle, prot, flags, false, false, 0,
mapsize);
assert(!rc);
if (IsAsan()) { if (IsAsan()) {
addr2 = (addr >> 3) + 0x7fff8000; addr2 = (addr >> 3) + 0x7fff8000;
addr3 = ((addr + mapsize) >> 3) + 0x7fff8000;
assert(!(addr2 & (FRAMESIZE - 1)));
assert(!(addr3 & (FRAMESIZE - 1)));
dm = sys_mmap((void *)addr2, mapsize >> 3, prot, flags, -1, 0); dm = sys_mmap((void *)addr2, mapsize >> 3, prot, flags, -1, 0);
TrackMemoryInterval(&_mmi, addr2 >> 16, assert(dm.addr != MAP_FAILED);
(addr2 + (mapsize >> 3) - 1) >> 16, dm.maphandle, rc = TrackMemoryInterval(&_mmi, addr2 >> 16, (addr3 >> 16) - 1,
prot, flags, false, false, 0, mapsize >> 3); dm.maphandle, prot, flags, false, false, 0,
mapsize >> 3);
assert(!rc);
} }
return (void *)addr; return (void *)addr;
} }