mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Make more fixes and improvements
- Remove PAGESIZE constant - Fix realloc() documentation - Fix ttyname_r() error reporting - Make forking more reliable on Windows - Make execvp() a few microseconds faster - Make system() a few microseconds faster - Tighten up the socket-related magic numbers - Loosen restrictions on mmap() offset alignment - Improve GetProgramExecutableName() with getenv("_") - Use mkstemp() as basis for mktemp(), tmpfile(), tmpfd() - Fix flakes in pthread_cancel_test, unix_test, fork_test - Fix recently introduced futex stack overflow regression - Let sockets be passed as stdio to subprocesses on Windows - Improve security of bind() on Windows w/ SO_EXCLUSIVEADDRUSE
This commit is contained in:
parent
140a8a52e5
commit
18bb5888e1
311 changed files with 1239 additions and 2622 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/bsr.h"
|
||||
#include "libc/intrin/dll.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/internal.h"
|
||||
|
@ -53,6 +54,10 @@ __static_yoink("_pthread_atfork");
|
|||
#define MAP_ANON_OPENBSD 0x1000
|
||||
#define MAP_STACK_OPENBSD 0x4000
|
||||
|
||||
static unsigned long roundup2pow(unsigned long x) {
|
||||
return x > 1 ? 2ul << _bsrl(x - 1) : x ? 1 : 0;
|
||||
}
|
||||
|
||||
void _pthread_free(struct PosixThread *pt) {
|
||||
if (pt->flags & PT_STATIC) return;
|
||||
free(pt->tls);
|
||||
|
@ -104,13 +109,14 @@ static int FixupCustomStackOnOpenbsd(pthread_attr_t *attr) {
|
|||
// in order to successfully call mmap(), which will return EINVAL if
|
||||
// these calculations should overflow.
|
||||
size_t n;
|
||||
int e, rc;
|
||||
uintptr_t x, y;
|
||||
int e, rc, pagesz;
|
||||
pagesz = getauxval(AT_PAGESZ);
|
||||
n = attr->__stacksize;
|
||||
x = (uintptr_t)attr->__stackaddr;
|
||||
y = ROUNDUP(x, PAGESIZE);
|
||||
y = ROUNDUP(x, pagesz);
|
||||
n -= y - x;
|
||||
n = ROUNDDOWN(n, PAGESIZE);
|
||||
n = ROUNDDOWN(n, pagesz);
|
||||
e = errno;
|
||||
if (__sys_mmap((void *)y, n, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_FIXED | MAP_ANON_OPENBSD | MAP_STACK_OPENBSD,
|
||||
|
@ -176,7 +182,7 @@ static errno_t pthread_create_impl(pthread_t *thread,
|
|||
default_guardsize = getauxval(AT_PAGESZ);
|
||||
pt->flags = PT_OWNSTACK;
|
||||
pt->attr.__stacksize = MAX(pt->attr.__stacksize, GetStackSize());
|
||||
pt->attr.__stacksize = _roundup2pow(pt->attr.__stacksize);
|
||||
pt->attr.__stacksize = roundup2pow(pt->attr.__stacksize);
|
||||
pt->attr.__guardsize = ROUNDUP(pt->attr.__guardsize, default_guardsize);
|
||||
if (pt->attr.__guardsize + default_guardsize >= pt->attr.__stacksize) {
|
||||
_pthread_free(pt);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue