mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Get life.com in MODE=tiny back down to 12kb
This commit is contained in:
parent
23b72eb617
commit
b90fa996b4
14 changed files with 199 additions and 72 deletions
|
@ -44,12 +44,12 @@ textwindows noasan struct DirectMap sys_mmap_nt(void *addr, size_t size,
|
||||||
* combination of flags, that'll cause Windows to actually do this!
|
* combination of flags, that'll cause Windows to actually do this!
|
||||||
*/
|
*/
|
||||||
upsize = ROUNDUP(size, FRAMESIZE);
|
upsize = ROUNDUP(size, FRAMESIZE);
|
||||||
if ((dm.maphandle = CreateFileMappingNuma(
|
if ((dm.maphandle =
|
||||||
-1, &kNtIsInheritable, kNtPageExecuteReadwrite, upsize >> 32,
|
CreateFileMapping(-1, &kNtIsInheritable, kNtPageExecuteReadwrite,
|
||||||
upsize, NULL, kNtNumaNoPreferredNode))) {
|
upsize >> 32, upsize, NULL))) {
|
||||||
if ((dm.addr = MapViewOfFileExNuma(
|
if ((dm.addr = MapViewOfFileEx(dm.maphandle,
|
||||||
dm.maphandle, kNtFileMapWrite | kNtFileMapExecute, 0, 0, upsize,
|
kNtFileMapWrite | kNtFileMapExecute, 0, 0,
|
||||||
addr, kNtNumaNoPreferredNode))) {
|
upsize, addr))) {
|
||||||
for (i = 0; i < size; i += got) {
|
for (i = 0; i < size; i += got) {
|
||||||
got = 0;
|
got = 0;
|
||||||
op.Internal = 0;
|
op.Internal = 0;
|
||||||
|
@ -68,16 +68,15 @@ textwindows noasan struct DirectMap sys_mmap_nt(void *addr, size_t size,
|
||||||
CloseHandle(dm.maphandle);
|
CloseHandle(dm.maphandle);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((dm.maphandle = CreateFileMappingNuma(
|
if ((dm.maphandle = CreateFileMapping(
|
||||||
handle, &kNtIsInheritable,
|
handle, &kNtIsInheritable,
|
||||||
(prot & PROT_WRITE) ? kNtPageExecuteReadwrite : kNtPageExecuteRead,
|
(prot & PROT_WRITE) ? kNtPageExecuteReadwrite : kNtPageExecuteRead,
|
||||||
handle != -1 ? 0 : size >> 32, handle != -1 ? 0 : size, NULL,
|
handle != -1 ? 0 : size >> 32, handle != -1 ? 0 : size, NULL))) {
|
||||||
kNtNumaNoPreferredNode))) {
|
if ((dm.addr = MapViewOfFileEx(dm.maphandle,
|
||||||
if ((dm.addr = MapViewOfFileExNuma(
|
(prot & PROT_WRITE)
|
||||||
dm.maphandle,
|
? kNtFileMapWrite | kNtFileMapExecute
|
||||||
(prot & PROT_WRITE) ? kNtFileMapWrite | kNtFileMapExecute
|
: kNtFileMapRead | kNtFileMapExecute,
|
||||||
: kNtFileMapRead | kNtFileMapExecute,
|
off >> 32, off, size, addr))) {
|
||||||
off >> 32, off, size, addr, kNtNumaNoPreferredNode))) {
|
|
||||||
return dm;
|
return dm;
|
||||||
}
|
}
|
||||||
CloseHandle(dm.maphandle);
|
CloseHandle(dm.maphandle);
|
||||||
|
|
|
@ -75,15 +75,13 @@ textwindows int ntspawn(
|
||||||
block = NULL;
|
block = NULL;
|
||||||
if (__mkntpath(prog, prog16) == -1) return -1;
|
if (__mkntpath(prog, prog16) == -1) return -1;
|
||||||
blocksize = ROUNDUP(sizeof(*block), FRAMESIZE);
|
blocksize = ROUNDUP(sizeof(*block), FRAMESIZE);
|
||||||
if ((handle = CreateFileMappingNuma(
|
if ((handle = CreateFileMapping(
|
||||||
-1,
|
-1,
|
||||||
&(struct NtSecurityAttributes){sizeof(struct NtSecurityAttributes),
|
&(struct NtSecurityAttributes){sizeof(struct NtSecurityAttributes),
|
||||||
NULL, false},
|
NULL, false},
|
||||||
pushpop(kNtPageReadwrite), 0, blocksize, NULL,
|
pushpop(kNtPageReadwrite), 0, blocksize, NULL)) &&
|
||||||
kNtNumaNoPreferredNode)) &&
|
(block = MapViewOfFileEx(handle, kNtFileMapRead | kNtFileMapWrite, 0, 0,
|
||||||
(block =
|
blocksize, NULL))) {
|
||||||
MapViewOfFileExNuma(handle, kNtFileMapRead | kNtFileMapWrite, 0, 0,
|
|
||||||
blocksize, NULL, kNtNumaNoPreferredNode))) {
|
|
||||||
if (mkntcmdline(block->cmdline, prog, argv) != -1 &&
|
if (mkntcmdline(block->cmdline, prog, argv) != -1 &&
|
||||||
mkntenvblock(block->envvars, envp, extravar) != -1) {
|
mkntenvblock(block->envvars, envp, extravar) != -1) {
|
||||||
if (CreateProcess(prog16, block->cmdline, opt_lpProcessAttributes,
|
if (CreateProcess(prog16, block->cmdline, opt_lpProcessAttributes,
|
||||||
|
|
|
@ -47,13 +47,12 @@ static const char *DescribeDisposition(int x) {
|
||||||
*
|
*
|
||||||
* @return handle, or -1 on failure
|
* @return handle, or -1 on failure
|
||||||
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
||||||
* @see MapViewOfFileExNuma()
|
|
||||||
*/
|
*/
|
||||||
int64_t CreateFile(const char16_t *lpFileName, uint32_t dwDesiredAccess,
|
textwindows int64_t CreateFile(
|
||||||
uint32_t dwShareMode,
|
const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
|
||||||
struct NtSecurityAttributes *opt_lpSecurityAttributes,
|
struct NtSecurityAttributes *opt_lpSecurityAttributes,
|
||||||
int dwCreationDisposition, uint32_t dwFlagsAndAttributes,
|
int dwCreationDisposition, uint32_t dwFlagsAndAttributes,
|
||||||
int64_t opt_hTemplateFile) {
|
int64_t opt_hTemplateFile) {
|
||||||
int64_t hHandle;
|
int64_t hHandle;
|
||||||
hHandle = __imp_CreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
|
hHandle = __imp_CreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
|
||||||
opt_lpSecurityAttributes, dwCreationDisposition,
|
opt_lpSecurityAttributes, dwCreationDisposition,
|
||||||
|
|
50
libc/intrin/createfilemapping.greg.c
Normal file
50
libc/intrin/createfilemapping.greg.c
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
|
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||||
|
│ │
|
||||||
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
│ above copyright notice and this permission notice appear in all copies. │
|
||||||
|
│ │
|
||||||
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||||
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||||
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||||
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||||
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||||
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||||
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/calls/internal.h"
|
||||||
|
#include "libc/calls/strace.internal.h"
|
||||||
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
|
#include "libc/nt/memory.h"
|
||||||
|
#include "libc/nt/struct/securityattributes.h"
|
||||||
|
|
||||||
|
extern typeof(CreateFileMapping) *const __imp_CreateFileMappingW __msabi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates file mapping object on the New Technology.
|
||||||
|
*
|
||||||
|
* @param opt_hFile may be -1 for MAP_ANONYMOUS behavior
|
||||||
|
* @return handle, or 0 on failure
|
||||||
|
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
||||||
|
* @see MapViewOfFileEx()
|
||||||
|
*/
|
||||||
|
textwindows int64_t CreateFileMapping(
|
||||||
|
int64_t opt_hFile,
|
||||||
|
const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
|
||||||
|
uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
|
||||||
|
const char16_t *opt_lpName) {
|
||||||
|
int64_t hHandle;
|
||||||
|
hHandle = __imp_CreateFileMappingW(opt_hFile, opt_lpFileMappingAttributes,
|
||||||
|
flProtect, dwMaximumSizeHigh,
|
||||||
|
dwMaximumSizeLow, opt_lpName);
|
||||||
|
if (!hHandle) __winerr();
|
||||||
|
STRACE("CreateFileMapping(%ld, %s, max:%'zu, name:%#hs) → %ld% m", opt_hFile,
|
||||||
|
DescribeNtPageFlags(flProtect),
|
||||||
|
(uint64_t)dwMaximumSizeHigh << 32 | dwMaximumSizeLow, opt_lpName,
|
||||||
|
hHandle);
|
||||||
|
return hHandle;
|
||||||
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/strace.internal.h"
|
#include "libc/calls/strace.internal.h"
|
||||||
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/nt/memory.h"
|
#include "libc/nt/memory.h"
|
||||||
#include "libc/nt/struct/securityattributes.h"
|
#include "libc/nt/struct/securityattributes.h"
|
||||||
|
@ -33,7 +34,7 @@ extern typeof(CreateFileMappingNuma) *const
|
||||||
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
||||||
* @see MapViewOfFileExNuma()
|
* @see MapViewOfFileExNuma()
|
||||||
*/
|
*/
|
||||||
int64_t CreateFileMappingNuma(
|
textwindows int64_t CreateFileMappingNuma(
|
||||||
int64_t opt_hFile,
|
int64_t opt_hFile,
|
||||||
const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
|
const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
|
||||||
uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
|
uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
|
||||||
|
|
53
libc/intrin/mapviewoffileex.greg.c
Normal file
53
libc/intrin/mapviewoffileex.greg.c
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
|
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||||
|
│ │
|
||||||
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
│ above copyright notice and this permission notice appear in all copies. │
|
||||||
|
│ │
|
||||||
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||||
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||||
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||||
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||||
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||||
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||||
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/assert.h"
|
||||||
|
#include "libc/calls/internal.h"
|
||||||
|
#include "libc/calls/strace.internal.h"
|
||||||
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
|
#include "libc/nt/enum/filemapflags.h"
|
||||||
|
#include "libc/nt/memory.h"
|
||||||
|
|
||||||
|
extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx __msabi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps view of file mapping into memory on the New Technology.
|
||||||
|
*
|
||||||
|
* @param hFileMappingObject was returned by CreateFileMapping()
|
||||||
|
* @param dwDesiredAccess has kNtFileMap... flags
|
||||||
|
* @param opt_lpDesiredBaseAddress may be NULL to let o/s choose
|
||||||
|
* @return base address, or NULL on failure
|
||||||
|
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
||||||
|
*/
|
||||||
|
textwindows void *MapViewOfFileEx(int64_t hFileMappingObject,
|
||||||
|
uint32_t dwDesiredAccess,
|
||||||
|
uint32_t dwFileOffsetHigh,
|
||||||
|
uint32_t dwFileOffsetLow,
|
||||||
|
size_t dwNumberOfBytesToMap,
|
||||||
|
void *opt_lpDesiredBaseAddress) {
|
||||||
|
void *pStartingAddress;
|
||||||
|
pStartingAddress = __imp_MapViewOfFileEx(
|
||||||
|
hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow,
|
||||||
|
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress);
|
||||||
|
if (!pStartingAddress) __winerr();
|
||||||
|
STRACE("MapViewOfFileEx(%ld, %s, off:%'ld, size:%'zu, %p) → %p% m",
|
||||||
|
hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess),
|
||||||
|
(uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow,
|
||||||
|
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress, pStartingAddress);
|
||||||
|
return pStartingAddress;
|
||||||
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/strace.internal.h"
|
#include "libc/calls/strace.internal.h"
|
||||||
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/nt/enum/filemapflags.h"
|
#include "libc/nt/enum/filemapflags.h"
|
||||||
#include "libc/nt/memory.h"
|
#include "libc/nt/memory.h"
|
||||||
|
@ -34,11 +35,13 @@ extern typeof(MapViewOfFileExNuma) *const __imp_MapViewOfFileExNuma __msabi;
|
||||||
* @return base address, or NULL on failure
|
* @return base address, or NULL on failure
|
||||||
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
||||||
*/
|
*/
|
||||||
void *MapViewOfFileExNuma(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
|
textwindows void *MapViewOfFileExNuma(int64_t hFileMappingObject,
|
||||||
uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
|
uint32_t dwDesiredAccess,
|
||||||
size_t dwNumberOfBytesToMap,
|
uint32_t dwFileOffsetHigh,
|
||||||
void *opt_lpDesiredBaseAddress,
|
uint32_t dwFileOffsetLow,
|
||||||
uint32_t nndDesiredNumaNode) {
|
size_t dwNumberOfBytesToMap,
|
||||||
|
void *opt_lpDesiredBaseAddress,
|
||||||
|
uint32_t nndDesiredNumaNode) {
|
||||||
void *pStartingAddress;
|
void *pStartingAddress;
|
||||||
pStartingAddress = __imp_MapViewOfFileExNuma(
|
pStartingAddress = __imp_MapViewOfFileExNuma(
|
||||||
hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow,
|
hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow,
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
.imp kernel32,__imp_CreateFileMappingW,CreateFileMappingW,0
|
.imp kernel32,__imp_CreateFileMappingW,CreateFileMappingW,0
|
||||||
|
|
||||||
.text.windows
|
.text.windows
|
||||||
CreateFileMapping:
|
__CreateFileMapping:
|
||||||
push %rbp
|
push %rbp
|
||||||
mov %rsp,%rbp
|
mov %rsp,%rbp
|
||||||
.profilable
|
.profilable
|
||||||
mov __imp_CreateFileMappingW(%rip),%rax
|
mov __imp_CreateFileMappingW(%rip),%rax
|
||||||
jmp __sysv2nt8
|
jmp __sysv2nt6
|
||||||
.endfn CreateFileMapping,globl
|
.endfn __CreateFileMapping,globl
|
||||||
.previous
|
.previous
|
||||||
|
|
|
@ -1,2 +1,12 @@
|
||||||
.include "o/libc/nt/codegen.inc"
|
.include "o/libc/nt/codegen.inc"
|
||||||
.imp kernel32,__imp_MapViewOfFileEx,MapViewOfFileEx,0
|
.imp kernel32,__imp_MapViewOfFileEx,MapViewOfFileEx,0
|
||||||
|
|
||||||
|
.text.windows
|
||||||
|
__MapViewOfFileEx:
|
||||||
|
push %rbp
|
||||||
|
mov %rsp,%rbp
|
||||||
|
.profilable
|
||||||
|
mov __imp_MapViewOfFileEx(%rip),%rax
|
||||||
|
jmp __sysv2nt6
|
||||||
|
.endfn __MapViewOfFileEx,globl
|
||||||
|
.previous
|
||||||
|
|
|
@ -580,10 +580,11 @@ imp 'CreateFiber' CreateFiber kernel32 0 # KernelBase
|
||||||
imp 'CreateFiberEx' CreateFiberEx kernel32 0 # KernelBase
|
imp 'CreateFiberEx' CreateFiberEx kernel32 0 # KernelBase
|
||||||
imp 'CreateFileA' CreateFileA kernel32 0 7 # KernelBase
|
imp 'CreateFileA' CreateFileA kernel32 0 7 # KernelBase
|
||||||
imp '__CreateFile' CreateFileW kernel32 0 7 # KernelBase
|
imp '__CreateFile' CreateFileW kernel32 0 7 # KernelBase
|
||||||
|
imp '__CreateFileMapping' CreateFileMappingW kernel32 0 6 # KernelBase
|
||||||
imp '__CreateFileMappingNuma' CreateFileMappingNumaW kernel32 0 7 # Kernelbase
|
imp '__CreateFileMappingNuma' CreateFileMappingNumaW kernel32 0 7 # Kernelbase
|
||||||
|
imp '__MapViewOfFileEx' MapViewOfFileEx kernel32 0 6 # KernelBase
|
||||||
imp '__MapViewOfFileExNuma' MapViewOfFileExNuma kernel32 0 7 # KernelBase
|
imp '__MapViewOfFileExNuma' MapViewOfFileExNuma kernel32 0 7 # KernelBase
|
||||||
imp 'CreateFileMappingNumaA' CreateFileMappingNumaA kernel32 198 7
|
imp 'CreateFileMappingNumaA' CreateFileMappingNumaA kernel32 198 7
|
||||||
imp 'CreateFileMapping' CreateFileMappingW kernel32 0 7 # KernelBase
|
|
||||||
imp 'CreateFileMappingA' CreateFileMappingA kernel32 196 7
|
imp 'CreateFileMappingA' CreateFileMappingA kernel32 196 7
|
||||||
imp 'CreateFileTransacted' CreateFileTransactedW kernel32 202
|
imp 'CreateFileTransacted' CreateFileTransactedW kernel32 202
|
||||||
imp 'CreateFileTransactedA' CreateFileTransactedA kernel32 201
|
imp 'CreateFileTransactedA' CreateFileTransactedA kernel32 201
|
||||||
|
@ -3339,7 +3340,6 @@ imp 'MapUserPhysicalPagesScatter' MapUserPhysicalPagesScatter kernel32 986
|
||||||
imp 'MapViewOfFile' MapViewOfFile kernel32 0 # KernelBase
|
imp 'MapViewOfFile' MapViewOfFile kernel32 0 # KernelBase
|
||||||
imp 'MapViewOfFile3' MapViewOfFile3 KernelBase 1003
|
imp 'MapViewOfFile3' MapViewOfFile3 KernelBase 1003
|
||||||
imp 'MapViewOfFile3FromApp' MapViewOfFile3FromApp KernelBase 1004
|
imp 'MapViewOfFile3FromApp' MapViewOfFile3FromApp KernelBase 1004
|
||||||
imp 'MapViewOfFileEx' MapViewOfFileEx kernel32 0 # KernelBase
|
|
||||||
imp 'MapViewOfFileFromApp' MapViewOfFileFromApp kernel32 0 # KernelBase
|
imp 'MapViewOfFileFromApp' MapViewOfFileFromApp kernel32 0 # KernelBase
|
||||||
imp 'MapViewOfFileNuma2' MapViewOfFileNuma2 KernelBase 1008
|
imp 'MapViewOfFileNuma2' MapViewOfFileNuma2 KernelBase 1008
|
||||||
imp 'MapVirtualKeyA' MapVirtualKeyA user32 2153
|
imp 'MapVirtualKeyA' MapVirtualKeyA user32 2153
|
||||||
|
|
|
@ -36,18 +36,26 @@ COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
void *LocalFree(void *hMem);
|
void *LocalFree(void *hMem);
|
||||||
|
|
||||||
|
int64_t CreateFileMapping(
|
||||||
|
int64_t opt_hFile,
|
||||||
|
const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
|
||||||
|
uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
|
||||||
|
const char16_t *opt_lpName);
|
||||||
int64_t CreateFileMappingNuma(
|
int64_t CreateFileMappingNuma(
|
||||||
int64_t opt_hFile /* -1ul is MAP_ANONYMOUS */,
|
int64_t opt_hFile,
|
||||||
const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
|
const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
|
||||||
uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
|
uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
|
||||||
const char16_t *opt_lpName, uint32_t nndDesiredNumaNode);
|
const char16_t *opt_lpName, uint32_t nndDesiredNumaNode);
|
||||||
|
|
||||||
void *MapViewOfFileExNuma(
|
void *MapViewOfFileEx(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
|
||||||
int64_t hFileMappingObject, /* @see CreateFileMapping() */
|
uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
|
||||||
uint32_t dwDesiredAccess, uint32_t dwFileOffsetHigh, /* high order bits */
|
size_t dwNumberOfBytesToMap,
|
||||||
uint32_t dwFileOffsetLow, /* low order bits */
|
void *opt_lpDesiredBaseAddress);
|
||||||
size_t dwNumberOfBytesToMap, void *opt_lpDesiredBaseAddress,
|
void *MapViewOfFileExNuma(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
|
||||||
uint32_t nndDesiredNumaNode);
|
uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
|
||||||
|
size_t dwNumberOfBytesToMap,
|
||||||
|
void *opt_lpDesiredBaseAddress,
|
||||||
|
uint32_t nndDesiredNumaNode);
|
||||||
|
|
||||||
bool32 UnmapViewOfFile(const void *lpBaseAddress);
|
bool32 UnmapViewOfFile(const void *lpBaseAddress);
|
||||||
bool32 FlushViewOfFile(const void *lpBaseAddress,
|
bool32 FlushViewOfFile(const void *lpBaseAddress,
|
||||||
|
|
|
@ -33,9 +33,14 @@
|
||||||
* @noreturn
|
* @noreturn
|
||||||
*/
|
*/
|
||||||
wontreturn void exit(int exitcode) {
|
wontreturn void exit(int exitcode) {
|
||||||
|
const uintptr_t *p;
|
||||||
STRACE("exit(%d)", exitcode);
|
STRACE("exit(%d)", exitcode);
|
||||||
if (weaken(__cxa_finalize)) {
|
if (weaken(__cxa_finalize)) {
|
||||||
weaken(__cxa_finalize)(NULL);
|
weaken(__cxa_finalize)(NULL);
|
||||||
}
|
}
|
||||||
quick_exit(exitcode);
|
for (p = __fini_array_end; p > __fini_array_start;) {
|
||||||
|
((void (*)(void))(*--p))();
|
||||||
|
}
|
||||||
|
__restorewintty();
|
||||||
|
_Exit(exitcode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,19 +160,16 @@ textwindows void WinMainForked(void) {
|
||||||
ReadAll(reader, &mapcount, sizeof(_mmi.i));
|
ReadAll(reader, &mapcount, sizeof(_mmi.i));
|
||||||
ReadAll(reader, &mapcapacity, sizeof(_mmi.n));
|
ReadAll(reader, &mapcapacity, sizeof(_mmi.n));
|
||||||
specialz = ROUNDUP(mapcapacity * sizeof(_mmi.p[0]), kMemtrackGran);
|
specialz = ROUNDUP(mapcapacity * sizeof(_mmi.p[0]), kMemtrackGran);
|
||||||
MapViewOfFileExNuma(CreateFileMappingNuma(
|
MapViewOfFileEx(CreateFileMapping(-1, &kNtIsInheritable, kNtPageReadwrite,
|
||||||
-1, &kNtIsInheritable, kNtPageReadwrite,
|
specialz >> 32, specialz, 0),
|
||||||
specialz >> 32, specialz, 0, kNtNumaNoPreferredNode),
|
kNtFileMapWrite, 0, 0, specialz, maps);
|
||||||
kNtFileMapWrite, 0, 0, specialz, maps,
|
|
||||||
kNtNumaNoPreferredNode);
|
|
||||||
ReadAll(reader, maps, mapcount * sizeof(_mmi.p[0]));
|
ReadAll(reader, maps, mapcount * sizeof(_mmi.p[0]));
|
||||||
if (IsAsan()) {
|
if (IsAsan()) {
|
||||||
shad = (char *)(((intptr_t)maps >> 3) + 0x7fff8000);
|
shad = (char *)(((intptr_t)maps >> 3) + 0x7fff8000);
|
||||||
size = ROUNDUP(specialz >> 3, FRAMESIZE);
|
size = ROUNDUP(specialz >> 3, FRAMESIZE);
|
||||||
MapViewOfFileExNuma(
|
MapViewOfFileEx(CreateFileMapping(-1, &kNtIsInheritable, kNtPageReadwrite,
|
||||||
CreateFileMappingNuma(-1, &kNtIsInheritable, kNtPageReadwrite,
|
size >> 32, size, 0),
|
||||||
size >> 32, size, 0, kNtNumaNoPreferredNode),
|
kNtFileMapWrite, 0, 0, size, maps);
|
||||||
kNtFileMapWrite, 0, 0, size, maps, kNtNumaNoPreferredNode);
|
|
||||||
#if 0
|
#if 0
|
||||||
ReadAll(reader, shad, (mapcount * sizeof(_mmi.p[0])) >> 3);
|
ReadAll(reader, shad, (mapcount * sizeof(_mmi.p[0])) >> 3);
|
||||||
#endif
|
#endif
|
||||||
|
@ -191,21 +188,20 @@ textwindows void WinMainForked(void) {
|
||||||
STRACE("fork() child CloseHandle(%ld) ~~~FAILED~~~ %m", maps[i].h);
|
STRACE("fork() child CloseHandle(%ld) ~~~FAILED~~~ %m", maps[i].h);
|
||||||
}
|
}
|
||||||
upsize = ROUNDUP(size, FRAMESIZE);
|
upsize = ROUNDUP(size, FRAMESIZE);
|
||||||
maps[i].h = CreateFileMappingNuma(-1, &kNtIsInheritable,
|
maps[i].h =
|
||||||
kNtPageExecuteReadwrite, upsize >> 32,
|
CreateFileMapping(-1, &kNtIsInheritable, kNtPageExecuteReadwrite,
|
||||||
upsize, NULL, kNtNumaNoPreferredNode);
|
upsize >> 32, upsize, NULL);
|
||||||
MapViewOfFileExNuma(maps[i].h, kNtFileMapWrite | kNtFileMapExecute, 0, 0,
|
MapViewOfFileEx(maps[i].h, kNtFileMapWrite | kNtFileMapExecute, 0, 0,
|
||||||
upsize, addr, kNtNumaNoPreferredNode);
|
upsize, addr);
|
||||||
ReadAll(reader, addr, size);
|
ReadAll(reader, addr, size);
|
||||||
} else {
|
} else {
|
||||||
STRACE("fork() child %p %'zu mapping shared hand:%ld offset:%'lu", addr,
|
STRACE("fork() child %p %'zu mapping shared hand:%ld offset:%'lu", addr,
|
||||||
size, maps[i].h, maps[i].offset);
|
size, maps[i].h, maps[i].offset);
|
||||||
MapViewOfFileExNuma(maps[i].h,
|
MapViewOfFileEx(maps[i].h,
|
||||||
(maps[i].prot & PROT_WRITE)
|
(maps[i].prot & PROT_WRITE)
|
||||||
? kNtFileMapWrite | kNtFileMapExecute
|
? kNtFileMapWrite | kNtFileMapExecute
|
||||||
: kNtFileMapRead | kNtFileMapExecute,
|
: kNtFileMapRead | kNtFileMapExecute,
|
||||||
maps[i].offset >> 32, maps[i].offset, size, addr,
|
maps[i].offset >> 32, maps[i].offset, size, addr);
|
||||||
kNtNumaNoPreferredNode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,13 @@
|
||||||
#include "libc/str/tpenc.h"
|
#include "libc/str/tpenc.h"
|
||||||
#include "libc/str/utf16.h"
|
#include "libc/str/utf16.h"
|
||||||
|
|
||||||
|
#if IsTiny()
|
||||||
|
extern typeof(CreateFileMapping) *const __imp_CreateFileMappingW __msabi;
|
||||||
|
extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx __msabi;
|
||||||
|
#define CreateFileMapping __imp_CreateFileMappingW
|
||||||
|
#define MapViewOfFileEx __imp_MapViewOfFileEx
|
||||||
|
#endif
|
||||||
|
|
||||||
#define AT_EXECFN 31L
|
#define AT_EXECFN 31L
|
||||||
#define MAP_ANONYMOUS 32
|
#define MAP_ANONYMOUS 32
|
||||||
#define MAP_PRIVATE 2
|
#define MAP_PRIVATE 2
|
||||||
|
@ -121,7 +128,6 @@ static noasan textwindows wontreturn noinstrument void WinMainNew(
|
||||||
STRACE("SetConsoleCP(kNtCpUtf8) → %hhhd", rc);
|
STRACE("SetConsoleCP(kNtCpUtf8) → %hhhd", rc);
|
||||||
rc = SetConsoleOutputCP(kNtCpUtf8);
|
rc = SetConsoleOutputCP(kNtCpUtf8);
|
||||||
STRACE("SetConsoleOutputCP(kNtCpUtf8) → %hhhd", rc);
|
STRACE("SetConsoleOutputCP(kNtCpUtf8) → %hhhd", rc);
|
||||||
SetEnvironmentVariable(u"TERM", u"xterm-truecolor");
|
|
||||||
for (i = 0; i < 2; ++i) {
|
for (i = 0; i < 2; ++i) {
|
||||||
hand = GetStdHandle(kConsoleHandles[i]);
|
hand = GetStdHandle(kConsoleHandles[i]);
|
||||||
rc = GetConsoleMode(hand, __ntconsolemode + i);
|
rc = GetConsoleMode(hand, __ntconsolemode + i);
|
||||||
|
@ -139,12 +145,11 @@ static noasan textwindows wontreturn noinstrument void WinMainNew(
|
||||||
allocaddr = stackaddr - argsize;
|
allocaddr = stackaddr - argsize;
|
||||||
STRACE("WinMainNew() mapping %'zu byte arg block + stack at %p", allocsize,
|
STRACE("WinMainNew() mapping %'zu byte arg block + stack at %p", allocsize,
|
||||||
allocaddr);
|
allocaddr);
|
||||||
MapViewOfFileExNuma(
|
MapViewOfFileEx(
|
||||||
(_mmi.p[0].h = CreateFileMappingNuma(
|
(_mmi.p[0].h =
|
||||||
-1, &kNtIsInheritable, kNtPageExecuteReadwrite, allocsize >> 32,
|
CreateFileMapping(-1, &kNtIsInheritable, kNtPageExecuteReadwrite,
|
||||||
allocsize, NULL, kNtNumaNoPreferredNode)),
|
allocsize >> 32, allocsize, NULL)),
|
||||||
kNtFileMapWrite | kNtFileMapExecute, 0, 0, allocsize, (void *)allocaddr,
|
kNtFileMapWrite | kNtFileMapExecute, 0, 0, allocsize, (void *)allocaddr);
|
||||||
kNtNumaNoPreferredNode);
|
|
||||||
_mmi.p[0].x = allocaddr >> 16;
|
_mmi.p[0].x = allocaddr >> 16;
|
||||||
_mmi.p[0].y = (allocaddr >> 16) + ((allocsize >> 16) - 1);
|
_mmi.p[0].y = (allocaddr >> 16) + ((allocsize >> 16) - 1);
|
||||||
_mmi.p[0].prot = PROT_READ | PROT_WRITE | PROT_EXEC;
|
_mmi.p[0].prot = PROT_READ | PROT_WRITE | PROT_EXEC;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue