mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Do more quality assurance work
This commit is contained in:
parent
67b19ae733
commit
d461c6f47d
31 changed files with 194 additions and 108 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/sig.internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
|
@ -66,6 +67,7 @@
|
|||
#ifdef __x86_64__
|
||||
|
||||
extern long __klog_handle;
|
||||
extern atomic_uint free_waiters_mu;
|
||||
void WipeKeystrokes(void);
|
||||
__msabi extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId;
|
||||
|
||||
|
@ -262,9 +264,13 @@ textwindows void WinMainForked(void) {
|
|||
__maps.free = 0;
|
||||
__maps.used = 0;
|
||||
__maps.maps = maps;
|
||||
__maps.count = 0;
|
||||
__maps.pages = 0;
|
||||
dll_init(&__maps.stack.elem);
|
||||
dll_make_first(&__maps.used, &__maps.stack.elem);
|
||||
for (struct Map *map = maps; map; map = map->next) {
|
||||
__maps.count += 1;
|
||||
__maps.pages += (map->size + 4095) / 4096;
|
||||
dll_make_last(&__maps.used, &map->elem);
|
||||
if (!VirtualProtect(map->addr, map->size, __prot2nt(map->prot, map->iscow),
|
||||
&oldprot)) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
|
@ -44,15 +45,20 @@
|
|||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
extern atomic_uint free_waiters_mu;
|
||||
|
||||
static void _onfork_prepare(void) {
|
||||
if (_weaken(_pthread_onfork_prepare))
|
||||
_weaken(_pthread_onfork_prepare)();
|
||||
_pthread_lock();
|
||||
__maps_lock();
|
||||
__fds_lock();
|
||||
while (atomic_exchange_explicit(&free_waiters_mu, 1, memory_order_acquire)) {
|
||||
}
|
||||
}
|
||||
|
||||
static void _onfork_parent(void) {
|
||||
atomic_store_explicit(&free_waiters_mu, 0, memory_order_release);
|
||||
__fds_unlock();
|
||||
__maps_unlock();
|
||||
_pthread_unlock();
|
||||
|
@ -65,6 +71,7 @@ static void _onfork_child(void) {
|
|||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&__fds_lock_obj, &attr);
|
||||
atomic_store_explicit(&free_waiters_mu, 0, memory_order_relaxed);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
_pthread_init();
|
||||
__maps_unlock();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue