mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Always initialize thread local storage
We had previously not enabled TLS in MODE=tiny in order to keep the smallest example programs (e.g. life.com) just 16kb in size. But it was error prone doing that, so now we just always enable it because this change uses hacks to ensure it won't increase life.com's size. This change also fixes a bug on NetBSD, where signal handlers would break thread local storage if SA_SIGINFO was being used. This looks like it might be a bug in NetBSD, but it's got a simple workaround.
This commit is contained in:
parent
057e8f5b54
commit
69f4152f38
33 changed files with 174 additions and 123 deletions
10
third_party/dlmalloc/platform.inc
vendored
10
third_party/dlmalloc/platform.inc
vendored
|
@ -179,6 +179,8 @@
|
|||
/*
|
||||
========================================================================
|
||||
To make a fully customizable malloc.h header file, cut everything
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
above this line, put into file malloc.h, edit to suit, and #include it
|
||||
on the next line, as well as in programs that use this malloc.
|
||||
========================================================================
|
||||
|
@ -385,7 +387,7 @@ unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
|
|||
|
||||
|
||||
/* MORECORE and MMAP must return MFAIL on failure */
|
||||
#define MFAIL ((void*)(MAX_SIZE_T))
|
||||
#define MFAIL NULL
|
||||
#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */
|
||||
|
||||
#if HAVE_MMAP
|
||||
|
@ -398,7 +400,7 @@ unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
|
|||
#endif /* MAP_ANON */
|
||||
#ifdef MAP_ANONYMOUS
|
||||
#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS)
|
||||
#define MMAP_DEFAULT(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0)
|
||||
#define MMAP_DEFAULT(s) _mapanon(s)
|
||||
#else /* MAP_ANONYMOUS */
|
||||
/*
|
||||
Nearly all versions of mmap support MAP_ANONYMOUS, so the following
|
||||
|
@ -408,8 +410,8 @@ unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
|
|||
static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
|
||||
#define MMAP_DEFAULT(s) ((dev_zero_fd < 0) ? \
|
||||
(dev_zero_fd = open("/dev/zero", O_RDWR), \
|
||||
mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \
|
||||
mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0))
|
||||
mmap_no(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \
|
||||
mmap_no(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0))
|
||||
#endif /* MAP_ANONYMOUS */
|
||||
|
||||
#define DIRECT_MMAP_DEFAULT(s) MMAP_DEFAULT(s)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue