mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Create variables for page size
This commit is contained in:
parent
23dfb79d33
commit
567d8fe32d
34 changed files with 137 additions and 101 deletions
|
@ -66,6 +66,8 @@ extern char ape_stack_prot[] __attribute__((__weak__));
|
|||
extern pthread_mutex_t __mmi_lock_obj;
|
||||
extern int hostos asm("__hostos");
|
||||
|
||||
void __pagesize_init(unsigned long *auxv);
|
||||
|
||||
static const char *DecodeMagnum(const char *p, long *r) {
|
||||
int k = 0;
|
||||
unsigned long c, x = 0;
|
||||
|
@ -164,6 +166,7 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename,
|
|||
__pid = sys_getpid().ax;
|
||||
|
||||
// initialize file system
|
||||
__pagesize_init(auxv);
|
||||
__maps_init();
|
||||
__init_fds(argc, argv, envp);
|
||||
|
||||
|
@ -172,13 +175,6 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename,
|
|||
|
||||
__enable_tls();
|
||||
|
||||
#if 0
|
||||
#if IsAsan()
|
||||
// TODO(jart): Figure out ASAN data model on AARCH64.
|
||||
__asan_init(argc, argv, envp, auxv);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
_init();
|
||||
// initialize program
|
||||
#if SYSDEBUG
|
||||
|
|
|
@ -23,5 +23,5 @@ long __get_avphys_pages(void) {
|
|||
struct sysinfo si;
|
||||
if (sysinfo(&si) == -1)
|
||||
return -1;
|
||||
return (((int64_t)si.freeram + si.bufferram) * si.mem_unit) / getpagesize();
|
||||
return (((int64_t)si.freeram + si.bufferram) * si.mem_unit) / __pagesize;
|
||||
}
|
||||
|
|
|
@ -23,5 +23,5 @@ long __get_phys_pages(void) {
|
|||
struct sysinfo si;
|
||||
if (sysinfo(&si) == -1)
|
||||
return -1;
|
||||
return ((int64_t)si.totalram * si.mem_unit) / getpagesize();
|
||||
return ((int64_t)si.totalram * si.mem_unit) / __pagesize;
|
||||
}
|
||||
|
|
|
@ -35,5 +35,5 @@ char __is_stack_overflow(siginfo_t *si, void *arg) {
|
|||
return false;
|
||||
intptr_t sp = uc->uc_mcontext.SP;
|
||||
intptr_t fp = (intptr_t)si->si_addr;
|
||||
return ABS(fp - sp) < getpagesize();
|
||||
return ABS(fp - sp) < __pagesize;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ static struct SymbolTable *OpenSymbolTableImpl(const char *filename) {
|
|||
size_t n, m, tsz, size;
|
||||
const Elf64_Sym *symtab, *sym;
|
||||
ptrdiff_t names_offset, name_base_offset, stp_offset;
|
||||
long pagesz = getpagesize();
|
||||
long pagesz = __pagesize;
|
||||
map = MAP_FAILED;
|
||||
if ((fd = open(filename, O_RDONLY | O_CLOEXEC)) == -1)
|
||||
return 0;
|
||||
|
|
|
@ -71,6 +71,8 @@ char *secure_getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
|
|||
extern int __argc;
|
||||
extern char **__argv;
|
||||
extern char **__envp;
|
||||
extern int __pagesize;
|
||||
extern int __gransize;
|
||||
extern unsigned long *__auxv;
|
||||
extern intptr_t __oldstack;
|
||||
extern char *__program_executable_name;
|
||||
|
|
|
@ -61,9 +61,9 @@ long sysconf(int name) {
|
|||
case _SC_CLK_TCK:
|
||||
return CLK_TCK;
|
||||
case _SC_PAGESIZE:
|
||||
return getpagesize();
|
||||
return __pagesize;
|
||||
case _SC_GRANSIZE:
|
||||
return getgransize();
|
||||
return __gransize;
|
||||
case _SC_ARG_MAX:
|
||||
return __get_arg_max();
|
||||
case _SC_SIGSTKSZ:
|
||||
|
|
|
@ -59,6 +59,7 @@ __msabi extern typeof(AddVectoredExceptionHandler) *const __imp_AddVectoredExcep
|
|||
__msabi extern typeof(CreateFileMapping) *const __imp_CreateFileMappingW;
|
||||
__msabi extern typeof(DuplicateHandle) *const __imp_DuplicateHandle;
|
||||
__msabi extern typeof(FreeEnvironmentStrings) *const __imp_FreeEnvironmentStringsW;
|
||||
__msabi extern typeof(GetCommandLine) *const __imp_GetCommandLineW;
|
||||
__msabi extern typeof(GetConsoleMode) *const __imp_GetConsoleMode;
|
||||
__msabi extern typeof(GetCurrentDirectory) *const __imp_GetCurrentDirectoryW;
|
||||
__msabi extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId;
|
||||
|
@ -67,6 +68,7 @@ __msabi extern typeof(GetEnvironmentVariable) *const __imp_GetEnvironmentVariabl
|
|||
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
||||
__msabi extern typeof(GetStdHandle) *const __imp_GetStdHandle;
|
||||
__msabi extern typeof(GetSystemInfo) *const __imp_GetSystemInfo;
|
||||
__msabi extern typeof(GetSystemInfo) *const __imp_GetSystemInfo;
|
||||
__msabi extern typeof(GetUserName) *const __imp_GetUserNameW;
|
||||
__msabi extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx;
|
||||
__msabi extern typeof(SetConsoleCP) *const __imp_SetConsoleCP;
|
||||
|
@ -87,16 +89,6 @@ __funline int IsAlpha(int c) {
|
|||
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
||||
}
|
||||
|
||||
// https://nullprogram.com/blog/2022/02/18/
|
||||
__funline char16_t *MyCommandLine(void) {
|
||||
void *cmd;
|
||||
asm("mov\t%%gs:(0x60),%0\n"
|
||||
"mov\t0x20(%0),%0\n"
|
||||
"mov\t0x78(%0),%0\n"
|
||||
: "=r"(cmd));
|
||||
return cmd;
|
||||
}
|
||||
|
||||
static abi char16_t *StrStr(const char16_t *haystack, const char16_t *needle) {
|
||||
size_t i;
|
||||
for (;;) {
|
||||
|
@ -318,9 +310,13 @@ abi int64_t WinMain(int64_t hInstance, int64_t hPrevInstance,
|
|||
"sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop'\n");
|
||||
return 77 << 8; // exit(77)
|
||||
}
|
||||
struct NtSystemInfo si;
|
||||
__imp_GetSystemInfo(&si);
|
||||
__pagesize = si.dwPageSize;
|
||||
__gransize = si.dwAllocationGranularity;
|
||||
__umask = 077;
|
||||
__pid = __imp_GetCurrentProcessId();
|
||||
cmdline = MyCommandLine();
|
||||
cmdline = __imp_GetCommandLineW();
|
||||
#if SYSDEBUG
|
||||
// sloppy flag-only check for early initialization
|
||||
if (StrStr(cmdline, u"--strace"))
|
||||
|
|
|
@ -62,7 +62,7 @@ static void __zipos_dismiss(uint8_t *map, const uint8_t *cdir, long pg) {
|
|||
}
|
||||
|
||||
// unmap the executable portion beneath the local files
|
||||
mo = ROUNDDOWN(lo, getgransize());
|
||||
mo = ROUNDDOWN(lo, __gransize);
|
||||
if (mo)
|
||||
munmap(map, mo);
|
||||
|
||||
|
@ -128,7 +128,7 @@ static void __zipos_init(void) {
|
|||
if (!fstat(fd, &st) && (map = mmap(0, st.st_size, PROT_READ, MAP_SHARED,
|
||||
fd, 0)) != MAP_FAILED) {
|
||||
if ((cdir = GetZipEocd(map, st.st_size, &err))) {
|
||||
long pagesz = getpagesize();
|
||||
long pagesz = __pagesize;
|
||||
__zipos_dismiss(map, cdir, pagesz);
|
||||
__zipos.map = map;
|
||||
__zipos.cdir = cdir;
|
||||
|
|
|
@ -31,7 +31,7 @@ int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) {
|
|||
bzero(st, sizeof(*st));
|
||||
st->st_nlink = 1;
|
||||
st->st_dev = zipos->dev;
|
||||
st->st_blksize = getpagesize();
|
||||
st->st_blksize = __pagesize;
|
||||
if (cf == ZIPOS_SYNTHETIC_DIRECTORY) {
|
||||
st->st_mode = S_IFDIR | (0555 & ~atomic_load_explicit(
|
||||
&__umask, memory_order_acquire));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue