Skip to content

Commit ca53203

Browse files
Merge pull request #539 from LudwigOrtmann/native_signal_patches
Native signal patches
2 parents 8ebc315 + 2b4a323 commit ca53203

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

cpu/native/irq_cpu.c

+5-25
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ char __isr_stack[SIGSTKSZ];
5757
ucontext_t native_isr_context;
5858
ucontext_t *_native_cur_ctx, *_native_isr_ctx;
5959

60-
int *process_heap_address;
61-
6260
volatile unsigned int _native_saved_eip;
6361
volatile int _native_sigpend;
6462
int _sig_pipefd[2];
@@ -318,32 +316,20 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
318316

319317
if (_native_in_syscall == 0) {
320318
DEBUG("\n\n\t\treturn to _native_sig_leave_tramp\n\n");
321-
#ifdef __MACH__
319+
/* disable interrupts in context */
322320
isr_set_sigmask((ucontext_t *)context);
323321
_native_in_isr = 1;
322+
#ifdef __MACH__
324323
_native_saved_eip = ((ucontext_t *)context)->uc_mcontext->__ss.__eip;
325324
((ucontext_t *)context)->uc_mcontext->__ss.__eip = (unsigned int)&_native_sig_leave_tramp;
326325
#elif BSD
327-
_native_in_isr = 1;
328326
_native_saved_eip = ((struct sigcontext *)context)->sc_eip;
329327
((struct sigcontext *)context)->sc_eip = (unsigned int)&_native_sig_leave_tramp;
330328
#else
331-
if (
332-
((void*)(((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP]))
333-
> ((void*)process_heap_address)
334-
) {
335-
//printf("\n\033[36mEIP:\t%p\nHEAP:\t%p\nnot switching\n\n\033[0m", (void*)((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP], (void*)process_heap_address);
336-
}
337-
else {
338-
/* disable interrupts in context */
339-
isr_set_sigmask((ucontext_t *)context);
340-
_native_in_isr = 1;
341-
//printf("\n\033[31mEIP:\t%p\nHEAP:\t%p\ngo switching\n\n\033[0m", (void*)((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP], (void*)process_heap_address);
342-
_native_saved_eip = ((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP];
343-
((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP] = (unsigned int)&_native_sig_leave_tramp;
344-
}
329+
//printf("\n\033[31mEIP:\t%p\ngo switching\n\n\033[0m", (void*)((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP]);
330+
_native_saved_eip = ((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP];
331+
((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP] = (unsigned int)&_native_sig_leave_tramp;
345332
#endif
346-
// TODO: change sigmask?
347333
}
348334
else {
349335
DEBUG("\n\n\t\treturn to syscall\n\n");
@@ -446,12 +432,6 @@ void native_interrupt_init(void)
446432
struct sigaction sa;
447433
DEBUG("XXX: native_interrupt_init()\n");
448434

449-
process_heap_address = malloc(sizeof(int));
450-
if (process_heap_address == NULL) {
451-
err(EXIT_FAILURE, "native_interrupt_init: malloc");
452-
}
453-
free(process_heap_address);
454-
455435
VALGRIND_STACK_REGISTER(__isr_stack, __isr_stack + sizeof(__isr_stack));
456436
VALGRIND_DEBUG("VALGRIND_STACK_REGISTER(%p, %p)\n", __isr_stack, (void*)((int)__isr_stack + sizeof(__isr_stack)));
457437

cpu/native/tramp.S

+14-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#ifdef __MACH__
44
.globl __native_sig_leave_tramp
55
__native_sig_leave_tramp:
6-
pushf
7-
pusha
6+
pushl __native_saved_eip
7+
pushfl
8+
pushal
89

910
pushl __native_isr_ctx
1011
pushl __native_cur_ctx
@@ -14,10 +15,11 @@ __native_sig_leave_tramp:
1415
call _eINT
1516

1617
movl $0x0, __native_in_isr
17-
popa
18-
popf
18+
popal
19+
popfl
1920

20-
jmp *__native_saved_eip
21+
popl __native_saved_eip
22+
jmp *-4(%esp)
2123
#else
2224
.extern $_native_saved_eip
2325
.extern $_native_isr_ctx
@@ -27,8 +29,9 @@ __native_sig_leave_tramp:
2729
.globl _native_sig_leave_tramp
2830

2931
_native_sig_leave_tramp:
30-
pushf
31-
pusha
32+
pushl _native_saved_eip
33+
pushfl
34+
pushal
3235

3336
pushl _native_isr_ctx
3437
pushl _native_cur_ctx
@@ -38,8 +41,9 @@ _native_sig_leave_tramp:
3841
call eINT
3942

4043
movl $0x0, _native_in_isr
41-
popa
42-
popf
44+
popal
45+
popfl
4346

44-
jmp *_native_saved_eip
47+
popl _native_saved_eip
48+
jmp *-4(%esp)
4549
#endif

0 commit comments

Comments
 (0)