mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 19:28:29 +00:00
Make improvements
- Make rand64() thread safe - Introduce lemur64 lcg prng - Improve strace on New Technology - Improve msync() on New Technology
This commit is contained in:
parent
43ba3009b2
commit
29bf8b1a30
73 changed files with 888 additions and 269 deletions
|
@ -36,5 +36,5 @@ textwindows int sys_close_nt(struct Fd *fd) {
|
|||
if (fd->kind == kFdConsole && fd->extra && fd->extra != -1) {
|
||||
ok &= CloseHandle(fd->extra);
|
||||
}
|
||||
return ok ? 0 : __winerr();
|
||||
return ok ? 0 : -1;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ textwindows noasan struct DirectMap sys_mmap_nt(void *addr, size_t size,
|
|||
int64_t handle, int64_t off) {
|
||||
size_t i;
|
||||
struct DirectMap dm;
|
||||
uint32_t flags1, flags2;
|
||||
struct ProtectNt fl;
|
||||
const struct NtSecurityAttributes *sec;
|
||||
|
||||
if (flags & MAP_PRIVATE) {
|
||||
|
@ -42,37 +42,19 @@ textwindows noasan struct DirectMap sys_mmap_nt(void *addr, size_t size,
|
|||
if ((prot & PROT_WRITE) && (flags & MAP_PRIVATE) && handle != -1) {
|
||||
// windows has cow pages but they can't propagate across fork()
|
||||
if (prot & PROT_EXEC) {
|
||||
flags1 = kNtPageExecuteWritecopy;
|
||||
flags2 = kNtFileMapCopy | kNtFileMapExecute;
|
||||
fl = (struct ProtectNt){kNtPageExecuteWritecopy,
|
||||
kNtFileMapCopy | kNtFileMapExecute};
|
||||
} else {
|
||||
flags1 = kNtPageWritecopy;
|
||||
flags2 = kNtFileMapCopy;
|
||||
}
|
||||
} else if (prot & PROT_WRITE) {
|
||||
if (prot & PROT_EXEC) {
|
||||
flags1 = kNtPageExecuteReadwrite;
|
||||
flags2 = kNtFileMapWrite | kNtFileMapExecute;
|
||||
} else {
|
||||
flags1 = kNtPageReadwrite;
|
||||
flags2 = kNtFileMapWrite;
|
||||
}
|
||||
} else if (prot & PROT_READ) {
|
||||
if (prot & PROT_EXEC) {
|
||||
flags1 = kNtPageExecuteRead;
|
||||
flags2 = kNtFileMapRead | kNtFileMapExecute;
|
||||
} else {
|
||||
flags1 = kNtPageReadonly;
|
||||
flags2 = kNtFileMapRead;
|
||||
fl = (struct ProtectNt){kNtPageWritecopy, kNtFileMapCopy};
|
||||
}
|
||||
} else {
|
||||
flags1 = kNtPageNoaccess;
|
||||
flags2 = 0;
|
||||
fl = __nt2prot(prot);
|
||||
}
|
||||
|
||||
if ((dm.maphandle = CreateFileMapping(handle, sec, flags1, (size + off) >> 32,
|
||||
(size + off), 0))) {
|
||||
if ((dm.addr = MapViewOfFileEx(dm.maphandle, flags2, off >> 32, off, size,
|
||||
addr))) {
|
||||
if ((dm.maphandle = CreateFileMapping(handle, sec, fl.flags1,
|
||||
(size + off) >> 32, (size + off), 0))) {
|
||||
if ((dm.addr = MapViewOfFileEx(dm.maphandle, fl.flags2, off >> 32, off,
|
||||
size, addr))) {
|
||||
return dm;
|
||||
}
|
||||
CloseHandle(dm.maphandle);
|
||||
|
|
|
@ -22,10 +22,5 @@
|
|||
|
||||
textwindows int sys_fdatasync_nt(int fd) {
|
||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||
/*
|
||||
* XXX: On Windows NT this might be more analagous to fflush() and
|
||||
* Microsoft docs say to do manual block i/o for database-ish
|
||||
* guarantees on disk persistence. Consider: Really good UPS.
|
||||
*/
|
||||
return FlushFileBuffers(g_fds.p[fd].handle) ? 0 : __winerr();
|
||||
return FlushFileBuffers(g_fds.p[fd].handle) ? 0 : -1;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* This function is typically regarded as a libc implementation detail;
|
||||
* thus, the source code is the documentation.
|
||||
*
|
||||
* @return aux val or 0 if not available
|
||||
* @see libc/sysv/consts.sh
|
||||
* @see System Five Application Binary Interface § 3.4.3
|
||||
* @asyncsignalsafe
|
||||
|
|
|
@ -226,7 +226,6 @@ void sys_exit(int) hidden;
|
|||
|
||||
void __onfork(void) hidden;
|
||||
i32 __fixupnewfd(i32, i32) hidden;
|
||||
u32 __prot2nt(i32, i32) privileged;
|
||||
void __restore_rt() hidden;
|
||||
int sys_utimensat_xnu(int, const char *, const struct timespec *, int) hidden;
|
||||
int sys_nanosleep_xnu(const struct timespec *, struct timespec *) hidden;
|
||||
|
@ -284,7 +283,7 @@ int sys_linkat_nt(int, const char *, int, const char *) hidden;
|
|||
int sys_lstat_nt(const char *, struct stat *) hidden;
|
||||
int sys_madvise_nt(void *, size_t, int) hidden;
|
||||
int sys_mkdirat_nt(int, const char *, uint32_t) hidden;
|
||||
int sys_msync_nt(void *, size_t, int) hidden;
|
||||
int sys_msync_nt(char *, size_t, int) hidden;
|
||||
int sys_nanosleep_nt(const struct timespec *, struct timespec *) hidden;
|
||||
int sys_pipe_nt(int[hasatleast 2], unsigned) hidden;
|
||||
int sys_renameat_nt(int, const char *, int, const char *) hidden;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "libc/errno.h"
|
||||
#include "libc/nt/memory.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/runtime/directmap.internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/sysv/consts/nr.h"
|
||||
|
||||
|
|
|
@ -50,11 +50,8 @@ textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) {
|
|||
pipefd[1] = writer;
|
||||
return 0;
|
||||
} else {
|
||||
__winerr();
|
||||
CloseHandle(hin);
|
||||
}
|
||||
} else {
|
||||
__winerr();
|
||||
}
|
||||
__releasefd(writer);
|
||||
__releasefd(reader);
|
||||
|
|
|
@ -63,7 +63,7 @@ struct Signals {
|
|||
struct Signal mem[__SIG_QUEUE_LENGTH];
|
||||
};
|
||||
|
||||
struct Signals __sig;
|
||||
struct Signals __sig; // TODO(jart): Need TLS
|
||||
|
||||
/**
|
||||
* Allocates piece of memory for storing pending signal.
|
||||
|
|
|
@ -51,7 +51,7 @@ static textwindows int SyncDirectory(int df, char16_t path[PATH_MAX], int n) {
|
|||
if (FlushFileBuffers(df)) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
path[0] = '.';
|
||||
|
@ -65,11 +65,11 @@ static textwindows int SyncDirectory(int df, char16_t path[PATH_MAX], int n) {
|
|||
if (FlushFileBuffers(fh)) {
|
||||
rc = 0;
|
||||
} else {
|
||||
rc = __winerr();
|
||||
rc = -1;
|
||||
}
|
||||
CloseHandle(fh);
|
||||
} else {
|
||||
rc = __winerr();
|
||||
rc = -1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/accounting.h"
|
||||
#include "libc/nt/enum/accessmask.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue