Skip to content

Instantly share code, notes, and snippets.

@zhuyifei1999
Created October 28, 2018 20:09
Show Gist options
  • Save zhuyifei1999/d435930c562077c8d55e235c3c72f77b to your computer and use it in GitHub Desktop.
Save zhuyifei1999/d435930c562077c8d55e235c3c72f77b to your computer and use it in GitHub Desktop.
LD_PRELOAD glibc wrapper to make sure stacks pointers given to clone(2) wrapper are 16-aligned.
/*
* Make sure stacks pointers given to clone(2) wrapper are 16-byte aligned.
*
* Public Domain / CC0
*
* i386 glibc clone.S has:
* andl $0xfffffff0, %ecx
* x86-64 has no such sort and you hit
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838
* and sadness somtimes happens :(. Compile this with:
* $ gcc -shared ensure_clone_stack_slign.S -o ensure_clone_stack_slign.so
* and run a program with:
* $ LD_PRELOAD=/path/to/ensure_clone_stack_slign.so command args
*/
.globl __clone
.text
.globl clone
.align 4
clone:
#ifdef __x86_64__
andq $-16, %rsi
#endif
jmp __clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment