Hi,
I need to skip faulting operations in a C program. On linux I do the following:
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void install_segv_handler()
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
#endif
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED))
siglongjmp(segv_env, 1);
_exit(1);
}
And then I can do for potentially faulting operations:
NONFAILING(*p = 1);
On Akaros it almost works. This skips over the first fault, but for
the second I get:
Uthread sighandler faulted, signal: 11
[user] HW TRAP frame 0x0000000000005d08
rax 0x000000002066e002
rbx 0x0000000000000000
rcx 0x0000000000000001
rdx 0xfeffff3fd9a00000
rbp 0x00007f7fff9fed90
rsi 0x0000000000000000
rdi 0x0000100000002370
r8 0x0000000000000000
r9 0x0000000000000000
r10 0x0000000000000000
r11 0x0000000000000200
r12 0xfffffffffffffffe
r13 0x0000000000000002
r14 0x0000000000415fe0
r15 0x0000000000000000
trap 0x0000000e
gsbs 0x0000000000000000
fsbs 0x00001000000028c0
err 0x--------00000006
rip 0x0000000000401852
cs 0x------------0023
flag 0x0000000000010246
rsp 0x00007f7fff9fecd0
ss 0x------------001b
Is there any way to achieve this on Akaros?
I've tried to sigreturn from the handler, but sigreturn returns (it must not!).
I've also tried to alter ucontext passed to the handler, but it does
not seem to have any effect.
Is it possible to return from handler and alter thread's context? Just
altering RIP would do, because I can set RIP a another function which
will longjmp.
Is there any way to turn "Uthread sighandler faulted" into a
non-error? I don't see why it should terminate my program. Faulting in
a signal handler should be OK.
Thanks
--
You received this message because you are subscribed to the Google Groups
"Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.