mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
Rewrite memory manager
Actually Portable Executable now supports Android. Cosmo's old mmap code required a 47 bit address space. The new implementation is very agnostic and supports both smaller address spaces (e.g. embedded) and even modern 56-bit PML5T paging for x86 which finally came true on Zen4 Threadripper Cosmopolitan no longer requires UNIX systems to observe the Windows 64kb granularity; i.e. sysconf(_SC_PAGE_SIZE) will now report the host native page size. This fixes a longstanding POSIX conformance issue, concerning file mappings that overlap the end of file. Other aspects of conformance have been improved too, such as the subtleties of address assignment and and the various subtleties surrounding MAP_FIXED and MAP_FIXED_NOREPLACE On Windows, mappings larger than 100 megabytes won't be broken down into thousands of independent 64kb mappings. Support for MAP_STACK is removed by this change; please use NewCosmoStack() instead. Stack overflow avoidance is now being implemented using the POSIX thread APIs. Please use GetStackBottom() and GetStackAddr(), instead of the old error-prone GetStackAddr() and HaveStackMemory() APIs which are removed.
This commit is contained in:
parent
7f6d0b8709
commit
6ffed14b9c
150 changed files with 1893 additions and 5634 deletions
|
@ -14,17 +14,6 @@
|
|||
*/
|
||||
#define GetGuardSize() 16384
|
||||
|
||||
/**
|
||||
* Align APE main thread stack at startup.
|
||||
*
|
||||
* You need this in your main program module:
|
||||
*
|
||||
* STATIC_STACK_ALIGN(GetStackSize());
|
||||
*
|
||||
* If you want to use GetStackAddr() and HaveStackMemory() safely on
|
||||
* your main thread in your process. It causes crt.S to waste a tiny
|
||||
* amount of memory to ensure those macros go extremely fast.
|
||||
*/
|
||||
#define STATIC_STACK_ALIGN(BYTES) \
|
||||
_STACK_SYMBOL("ape_stack_align", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)
|
||||
|
||||
|
@ -62,29 +51,12 @@ COSMOPOLITAN_C_START_
|
|||
extern char ape_stack_prot[] __attribute__((__weak__));
|
||||
extern char ape_stack_memsz[] __attribute__((__weak__));
|
||||
extern char ape_stack_align[] __attribute__((__weak__));
|
||||
extern char ape_stack_round[] __attribute__((__weak__));
|
||||
|
||||
/**
|
||||
* Returns address of bottom of current stack.
|
||||
*
|
||||
* This always works on threads. If you want it to work on the main
|
||||
* process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
|
||||
* which will burn O(256kb) of memory to ensure thread invariants.
|
||||
*/
|
||||
#define GetStackAddr() ((GetStackPointer() - 1) & -GetStackSize())
|
||||
uintptr_t GetStackBottom(void) pureconst;
|
||||
|
||||
#define GetStaticStackSize() ((uintptr_t)ape_stack_memsz)
|
||||
|
||||
/**
|
||||
* Returns true if at least `n` bytes of stack are available.
|
||||
*
|
||||
* This always works on threads. If you want it to work on the main
|
||||
* process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
|
||||
* which will burn O(256kb) of memory to ensure thread invariants,
|
||||
* which make this check exceedingly fast.
|
||||
*/
|
||||
#define HaveStackMemory(n) \
|
||||
(GetStackPointer() >= GetStackAddr() + GetGuardSize() + (n))
|
||||
|
||||
/**
|
||||
* Extends stack memory by poking large allocations.
|
||||
*
|
||||
|
@ -137,8 +109,6 @@ int FreeCosmoStack(void *) libcesque;
|
|||
: "i"(ADDEND)); \
|
||||
vAddr; \
|
||||
})
|
||||
#else
|
||||
#define GetStaticStackAddr(ADDEND) (GetStackAddr() + ADDEND)
|
||||
#endif
|
||||
|
||||
#define GetStackPointer() \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue