소스 검색

fix async thread cancellation on sh-fdpic

if __cp_cancel was reached via __syscall_cp, r12 will necessarily
still contain a GOT pointer (for libc.so or for the static-linked main
program) valid for entering __cancel. however, in the case of async
cancellation, r12 may contain any scratch value; it's not necessarily
even a valid GOT pointer for the code that was interrupted.

unlike in commit 0ec49dab6794166d67fae4764ce7fdea42ea6103 where the
corresponding issue was fixed for powerpc64, there is fundamentally no
way for fdpic code to recompute its GOT pointer. so a new mechanism is
introduced for cancel_handler to write a GOT register value into the
interrupted context on archs where it is needed.
Rich Felker 6 년 전
부모
커밋
35cd7c0950
2개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      arch/sh/pthread_arch.h
  2. 3 0
      src/thread/pthread_cancel.c

+ 5 - 0
arch/sh/pthread_arch.h

@@ -10,3 +10,8 @@ static inline struct pthread *__pthread_self()
 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread))
 
 #define MC_PC sc_pc
+
+#ifdef __FDPIC__
+#define MC_GOT sc_regs[12]
+#define CANCEL_GOT (*(uintptr_t *)((char *)__syscall_cp_asm+sizeof(uintptr_t)))
+#endif

+ 3 - 0
src/thread/pthread_cancel.c

@@ -61,6 +61,9 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
 
 	if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
 		uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
+#ifdef CANCEL_GOT
+		uc->uc_mcontext.MC_GOT = CANCEL_GOT;
+#endif
 		return;
 	}