Make some more fixups

This commit is contained in:
Justine Tunney 2022-06-12 09:37:17 -07:00
parent 6070a53e89
commit 4ddfc47d6e
18 changed files with 81 additions and 259 deletions

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_
#define COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_
#include "libc/intrin/pthread.h"
#include "libc/stdio/stdio.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -16,10 +17,14 @@ struct CxaAtexitBlocks {
} * p, root;
};
extern pthread_mutex_t __cxa_lock_obj;
extern struct CxaAtexitBlocks __cxa_blocks;
void __cxa_printexits(FILE *, void *);
#define __cxa_lock() pthread_mutex_lock(&__cxa_lock_obj)
#define __cxa_unlock() pthread_mutex_unlock(&__cxa_lock_obj)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_ */

View file

@ -139,12 +139,11 @@ textwindows void WinMainForked(void) {
char *addr, *shad;
struct DirectMap dm;
uint64_t size, upsize;
int64_t oncrash, savetsc;
struct MemoryInterval *maps;
char16_t fvar[21 + 1 + 21 + 1];
int64_t oncrash, savetsc, savebir;
uint32_t i, varlen, oldprot, savepid;
long mapcount, mapcapacity, specialz;
extern uint64_t ts asm("kStartTsc");
// check to see if the process was actually forked
// this variable should have the pipe handle numba
@ -198,13 +197,11 @@ textwindows void WinMainForked(void) {
// read the .data and .bss program image sections
savepid = __pid;
savebir = __kbirth;
savetsc = ts;
savetsc = kStartTsc;
ReadOrDie(reader, __data_start, __data_end - __data_start);
ReadOrDie(reader, __bss_start, __bss_end - __bss_start);
__pid = savepid;
__kbirth = savebir;
ts = savetsc;
kStartTsc = savetsc;
// apply fixups and reapply memory protections
_mmi.p = maps;

View file

@ -31,6 +31,7 @@ static inline bool IsMemtrackedImpl(int x, int y) {
}
bool IsMemtracked(int x, int y) {
/* assumes __mmi_lock() is held */
bool res;
res = IsMemtrackedImpl(x, y);
return res;

View file

@ -20,7 +20,7 @@ extern _Atomic(int) __strace; /* SYS */
extern char *program_invocation_name; /* RII */
extern char *program_invocation_short_name; /* RII */
extern uint64_t __syscount; /* RII */
extern const uint64_t kStartTsc; /* RII */
extern uint64_t kStartTsc; /* RII */
extern const char kTmpPath[]; /* RII */
extern const char kNtSystemDirectory[]; /* RII */
extern const char kNtWindowsDirectory[]; /* RII */

View file

@ -275,9 +275,8 @@ __msabi textwindows int64_t WinMain(int64_t hInstance, int64_t hPrevInstance,
const char *lpCmdLine, int64_t nCmdShow) {
const char16_t *cmdline;
extern char os asm("__hostos");
extern uint64_t ts asm("kStartTsc");
os = WINDOWS; /* madness https://news.ycombinator.com/item?id=21019722 */
ts = rdtsc();
kStartTsc = rdtsc();
__pid = GetCurrentProcessId();
#if !IsTiny()
__wincrashearly = AddVectoredExceptionHandler(1, (void *)OnEarlyWinCrash);