summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorChris Wailes <chriswailes@google.com>2021-05-03 14:27:12 -0700
committerChris Wailes <chriswailes@google.com>2021-05-07 15:00:55 -0700
commit559f27828cbc51851978c5781618fe5b3d34e4ba (patch)
tree4b6cb79ec78207cbe3faa1fab72597db1c436b07 /libc
parent3e0defac5d546c3a0ed0f5faae1a40502ffac003 (diff)
Clear the stack frame pointer in _start and __bionic_clone
This CL adds an instruction to the _start label that clears the frame pointer. This allows stack walking code to determine when it has reached the end of the stack. The __bionic_clone function is similarly modified, for architectures that weren't already doing both. Test: bionic-unit-tests Test: CtsBionicTestCases Change-Id: Iea3949f52c44f7931f9fff2d60d4d9e5c742c120
Diffstat (limited to 'libc')
-rw-r--r--libc/arch-arm/bionic/__bionic_clone.S2
-rw-r--r--libc/arch-common/bionic/crtbegin.c10
-rw-r--r--libc/arch-x86/bionic/__bionic_clone.S1
3 files changed, 9 insertions, 4 deletions
diff --git a/libc/arch-arm/bionic/__bionic_clone.S b/libc/arch-arm/bionic/__bionic_clone.S
index 6669b93a2..3fe212b47 100644
--- a/libc/arch-arm/bionic/__bionic_clone.S
+++ b/libc/arch-arm/bionic/__bionic_clone.S
@@ -61,6 +61,8 @@ ENTRY_PRIVATE(__bionic_clone)
b __set_errno_internal
.L_bc_child:
+ # We're in the child now. Set the end of the frame record chain.
+ mov fp, #0
# Setting lr to 0 will make the unwinder stop at __start_thread.
mov lr, #0
# Call __start_thread with the 'fn' and 'arg' we stored on the child stack.
diff --git a/libc/arch-common/bionic/crtbegin.c b/libc/arch-common/bionic/crtbegin.c
index 628783789..5f681c53c 100644
--- a/libc/arch-common/bionic/crtbegin.c
+++ b/libc/arch-common/bionic/crtbegin.c
@@ -49,13 +49,15 @@ __used static void _start_main(void* raw_args) {
#define POST "; .size _start, .-_start"
#if defined(__aarch64__)
-__asm__(PRE "bti j; mov x0,sp; b _start_main" POST);
+__asm__(PRE "bti j; mov x29,#0; mov x30,#0; mov x0,sp; b _start_main" POST);
#elif defined(__arm__)
-__asm__(PRE "mov r0,sp; b _start_main" POST);
+__asm__(PRE "mov fp,#0; mov lr,#0; mov r0,sp; b _start_main" POST);
#elif defined(__i386__)
-__asm__(PRE "movl %esp,%eax; andl $~0xf,%esp; subl $12,%esp; pushl %eax; calll _start_main" POST);
+__asm__(PRE
+ "xorl %ebp,%ebp; movl %esp,%eax; andl $~0xf,%esp; subl $12,%esp; pushl %eax;"
+ "calll _start_main" POST);
#elif defined(__x86_64__)
-__asm__(PRE "movq %rsp,%rdi; andq $~0xf,%rsp; callq _start_main" POST);
+__asm__(PRE "xorl %ebp, %ebp; movq %rsp,%rdi; andq $~0xf,%rsp; callq _start_main" POST);
#else
#error unsupported architecture
#endif
diff --git a/libc/arch-x86/bionic/__bionic_clone.S b/libc/arch-x86/bionic/__bionic_clone.S
index b682b4863..f0c58a00d 100644
--- a/libc/arch-x86/bionic/__bionic_clone.S
+++ b/libc/arch-x86/bionic/__bionic_clone.S
@@ -45,6 +45,7 @@ ENTRY_PRIVATE(__bionic_clone)
.L_bc_child:
# We don't want anyone to unwind past this point.
.cfi_undefined %eip
+ .cfi_undefined %ebp
call __start_thread
hlt