Skip to content

Commit c1ecb0e

Browse files
committed
x86: switch back to using x86-specific trampoline
Jumping into the generic trampoline causes the stack pointer to get clobbered. Fixes #61
1 parent 5445f70 commit c1ecb0e

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

arch/x86/defs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757

5858
#define MCONTEXT_GREGS (20)
5959

60-
#define FETCH_LINKPTR(dest) \
61-
asm("movl (%%esp, %%ebx, 4), %0" : "=r" ((dest)));
62-
6360
#include "common-defs.h"
6461

6562
#endif

arch/x86/startcontext.S

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2018, 2020 Ariadne Conill <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* This software is provided 'as is' and without any warranty, express or
9+
* implied. In no event shall the authors be liable for any damages arising
10+
* from the use of this software.
11+
*/
12+
13+
#include "defs.h"
14+
15+
FUNC(libucontext_trampoline)
16+
/* get the proper context into position and test for NULL */
17+
leal (%esp,%ebx,4), %esp
18+
cmpl $0, (%esp)
19+
20+
/* restore global offset table, exit@plt and libucontext_setcontext@plt need this */
21+
call __i686_get_pc_thunk_bx
22+
addl $_GLOBAL_OFFSET_TABLE_, %ebx
23+
24+
/* if we have no linked context, lets get out of here */
25+
je no_linked_context
26+
27+
/* call setcontext to switch to the linked context */
28+
call libucontext_setcontext@plt
29+
movl %eax, (%esp)
30+
31+
no_linked_context:
32+
/* we are returning into a null context, it seems, so maybe we should exit */
33+
call exit@plt
34+
35+
/* something is really hosed, call hlt to force termination */
36+
hlt
37+
38+
__i686_get_pc_thunk_bx:
39+
mov (%esp), %ebx
40+
ret
41+
END(libucontext_trampoline)

arch/x86/trampoline.c

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)