Skip to content

Commit 5a7573f

Browse files
committed
Add syscall buffering for the new glibc syscall wrapper.
glibc reworked the code for async-cancelable syscalls: bminor/glibc@89b5307
1 parent bc65288 commit 5a7573f

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/preload/syscall_hook.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,11 @@ SYSCALLHOOK_START(_syscall_hook_trampoline_48_89_e5)
664664
callq __morestack
665665
SYSCALLHOOK_END(_syscall_hook_trampoline_48_89_e5)
666666

667+
SYSCALLHOOK_START(_syscall_hook_trampoline_48_8b_45_10)
668+
mov 0x10(%rbp),%rax
669+
callq __morestack
670+
SYSCALLHOOK_END(_syscall_hook_trampoline_48_8b_45_10)
671+
667672
SYSCALLHOOK_START(_syscall_hook_trampoline_48_89_fb)
668673
mov %rdi,%rbx
669674
callq __morestack

src/preload/syscallbuf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ static void __attribute__((constructor)) init_process(void) {
829829
extern RR_HIDDEN void _syscall_hook_trampoline_4c_8b_0d(void);
830830
extern RR_HIDDEN void _syscall_hook_trampoline_48_89_e5(void);
831831
extern RR_HIDDEN void _syscall_hook_trampoline_48_89_fb(void);
832+
extern RR_HIDDEN void _syscall_hook_trampoline_48_8b_45_10(void);
832833
extern RR_HIDDEN void _syscall_hook_trampoline_48_8d_b3_f0_08_00_00(void);
833834
extern RR_HIDDEN void _syscall_hook_trampoline_nops(void);
834835

@@ -1060,6 +1061,11 @@ static void __attribute__((constructor)) init_process(void) {
10601061
3,
10611062
{ 0x48, 0x89, 0xfb },
10621063
(uintptr_t)_syscall_hook_trampoline_48_89_fb },
1064+
/* glibc-2.41-5.fc42.x86_64 has 'mov 0x10(%rbp),%rax' followed by 'syscall' */
1065+
{ PATCH_SYSCALL_INSTRUCTION_IS_LAST,
1066+
4,
1067+
{ 0x48, 0x8b, 0x45, 0x10 },
1068+
(uintptr_t)_syscall_hook_trampoline_48_8b_45_10 },
10631069
/* Support explicit 5 byte nop (`nopl 0(%ax, %ax, 1)`) before 'rdtsc' or syscall (may ignore interfering branches) */
10641070
{ PATCH_SYSCALL_INSTRUCTION_IS_LAST |
10651071
PATCH_IS_NOP_INSTRUCTIONS,

src/test/x86/morestack_unwind.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ static void breakpoint(void) {
88
}
99

1010
int main(void) {
11+
// glibc write() might only be patched after the first time it is executed.
12+
atomic_puts("Ensure glibc write() is patched...");
13+
// The test requires this write() be buffered:
1114
atomic_puts("EXIT-SUCCESS");
1215
breakpoint();
1316
return 0;

0 commit comments

Comments
 (0)