mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 14:28:30 +00:00
Improve memory manager and signal handling
On Windows, mmap() now chooses addresses transactionally. It reduces the risk of badness when interacting with the WIN32 memory manager. We don't throw darts anymore. There is also no more retry limit, since we recover from mystery maps more gracefully. The subroutine for combining adjacent maps has been rewritten for clarity. The print maps subroutine is better This change goes to great lengths to perfect the stack overflow code. On Windows you can now longjmp() out of a crash signal handler. Guard pages previously weren't being restored properly by the signal handler. That's fixed, so on Windows you can now handle a stack overflow multiple times. Great thought has been put into selecting the perfect SIGSTKSZ constants so you can save sigaltstack() memory. You can now use kprintf() with 512 bytes of stack available. The guard pages beneath the main stack are now recorded in the memory manager. This change fixes getcontext() so it works right with the %rax register.
This commit is contained in:
parent
36e5861b0c
commit
379cd77078
48 changed files with 834 additions and 570 deletions
|
@ -113,7 +113,7 @@ static int sigaltstack_bsd(const struct sigaltstack *neu,
|
|||
* struct sigaction sa;
|
||||
* struct sigaltstack ss;
|
||||
* ss.ss_flags = 0;
|
||||
* ss.ss_size = sysconf(_SC_MINSIGSTKSZ) + 8192;
|
||||
* ss.ss_size = sysconf(_SC_SIGSTKSZ);
|
||||
* ss.ss_sp = malloc(ss.ss_size);
|
||||
* sigaltstack(&ss, 0);
|
||||
* sigemptyset(&sa.ss_mask);
|
||||
|
@ -121,11 +121,16 @@ static int sigaltstack_bsd(const struct sigaltstack *neu,
|
|||
* sa.sa_handler = OnStackOverflow;
|
||||
* sigaction(SIGSEGV, &sa, 0);
|
||||
*
|
||||
* Your stack size should be `sysconf(_SC_SIGSTKSZ)` which should be
|
||||
* somewhere in the ballpark of 32kb to 64kb. You should go no lower
|
||||
* than `sysconf(_SC_MINSIGSTKSZ) + 2048` which could be 4kb - 34kb.
|
||||
* Cosmo also defines `SIGSTKSZ` as 32kb, which should also be safe.
|
||||
*
|
||||
* @param neu if non-null will install new signal alt stack
|
||||
* @param old if non-null will receive current signal alt stack
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @raise EFAULT if bad memory was supplied
|
||||
* @raise ENOMEM if `neu->ss_size` is less than `MINSIGSTKSZ`
|
||||
* @raise ENOMEM if `neu->ss_size` is beneath `sysconf(_SC_MINSIGSTKSZ)`
|
||||
*/
|
||||
int sigaltstack(const struct sigaltstack *neu, struct sigaltstack *old) {
|
||||
int rc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue