https://github.com/m4b/stackup
Statically modify a program binary's runtime stack size on Mac OS X --- without recompiling.
https://github.com/m4b/stackup
Last synced: about 1 year ago
JSON representation
Statically modify a program binary's runtime stack size on Mac OS X --- without recompiling.
- Host: GitHub
- URL: https://github.com/m4b/stackup
- Owner: m4b
- Created: 2015-02-16T01:38:35.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-12-30T20:31:05.000Z (over 4 years ago)
- Last Synced: 2025-03-29T01:03:36.729Z (about 1 year ago)
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 6
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# stackup
xnu MAXSSIZ got you down? `stackup 0xdeadbeef` makes everything all better.
The Mac OS X kernel 'hardcodes' the stack size (`MAXSSIZ`) to 64MB.
However, check out this kernel code in the `load_main` routine in `xnu/bsd/kern/mach_loader.c`:
```` c
if (epc->stacksize) {
result->prog_stack_size = 1;
result->user_stack_size = epc->stacksize;
} else {
result->prog_stack_size = 0;
result->user_stack_size = MAXSSIZ;
}
````
where `epc` is an `entry_point_command` struct.
In other words, if our binary image contains a non-zero stack size in its `entry_point_command` struct (`LC_MAIN`), the kernel will use that instead of the default `MAXSSIZ`.
So, if for some reason you can't recompile, don't want to, or just simply want to be cool, you can run this command line tool to statically modify your program's runtime max stack size.
Enjoy.
## Compile
`xcrun --sdk macosx swiftc main.swift -o stackup`
## Examples
Set stack to 1GB: `stackup 0x0x40000000`
Set stack to 0xdeadbeef: `stackup 0xdeadbeef`
# Features
* Static binary translation for program max stack size.
* Variable stack size
* No recompilation or source code necessary
* Hackish
## TODO:
1. Enable 32-bit binary translation
2. Enable fat-binary (universal) translation