From: Tom Hughes Date: Sat, 12 Nov 2005 00:13:20 +0000 (+0000) Subject: Add named constants for si_code values to replace the magic numbers. X-Git-Tag: svn/VALGRIND_3_1_0~140 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=09d3b7060d5183228ff91a9cd0af89e0101aec65;p=thirdparty%2Fvalgrind.git Add named constants for si_code values to replace the magic numbers. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5092 --- diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c index 80ab4d4ffc..ce06ef8953 100644 --- a/coregrind/m_signals.c +++ b/coregrind/m_signals.c @@ -1015,8 +1015,8 @@ static void default_action(const vki_siginfo_t *info, ThreadId tid) switch(sigNo) { case VKI_SIGSEGV: switch(info->si_code) { - case 1: event = "Access not within mapped region"; break; - case 2: event = "Bad permissions for mapped region"; break; + case VKI_SEGV_MAPERR: event = "Access not within mapped region"; break; + case VKI_SEGV_ACCERR: event = "Bad permissions for mapped region"; break; case 128: /* General Protection Fault: The CPU/kernel isn't telling us anything useful, but this @@ -1038,35 +1038,35 @@ static void default_action(const vki_siginfo_t *info, ThreadId tid) case VKI_SIGILL: switch(info->si_code) { - case 1: event = "Illegal opcode"; break; - case 2: event = "Illegal operand"; break; - case 3: event = "Illegal addressing mode"; break; - case 4: event = "Illegal trap"; break; - case 5: event = "Privileged opcode"; break; - case 6: event = "Privileged register"; break; - case 7: event = "Coprocessor error"; break; - case 8: event = "Internal stack error"; break; + case VKI_ILL_ILLOPC: event = "Illegal opcode"; break; + case VKI_ILL_ILLOPN: event = "Illegal operand"; break; + case VKI_ILL_ILLADR: event = "Illegal addressing mode"; break; + case VKI_ILL_ILLTRP: event = "Illegal trap"; break; + case VKI_ILL_PRVOPC: event = "Privileged opcode"; break; + case VKI_ILL_PRVREG: event = "Privileged register"; break; + case VKI_ILL_COPROC: event = "Coprocessor error"; break; + case VKI_ILL_BADSTK: event = "Internal stack error"; break; } break; case VKI_SIGFPE: switch (info->si_code) { - case 1: event = "Integer divide by zero"; break; - case 2: event = "Integer overflow"; break; - case 3: event = "FP divide by zero"; break; - case 4: event = "FP overflow"; break; - case 5: event = "FP underflow"; break; - case 6: event = "FP inexact"; break; - case 7: event = "FP invalid operation"; break; - case 8: event = "FP subscript out of range"; break; + case VKI_FPE_INTDIV: event = "Integer divide by zero"; break; + case VKI_FPE_INTOVF: event = "Integer overflow"; break; + case VKI_FPE_FLTDIV: event = "FP divide by zero"; break; + case VKI_FPE_FLTOVF: event = "FP overflow"; break; + case VKI_FPE_FLTUND: event = "FP underflow"; break; + case VKI_FPE_FLTRES: event = "FP inexact"; break; + case VKI_FPE_FLTINV: event = "FP invalid operation"; break; + case VKI_FPE_FLTSUB: event = "FP subscript out of range"; break; } break; case VKI_SIGBUS: switch (info->si_code) { - case 1: event = "Invalid address alignment"; break; - case 2: event = "Non-existent physical address"; break; - case 3: event = "Hardware error"; break; + case VKI_BUS_ADRALN: event = "Invalid address alignment"; break; + case VKI_BUS_ADRERR: event = "Non-existent physical address"; break; + case VKI_BUS_OBJERR: event = "Hardware error"; break; } break; } @@ -1249,7 +1249,7 @@ void VG_(synth_sigill)(ThreadId tid, Addr addr) vg_assert(VG_(threads)[tid].status == VgTs_Runnable); info.si_signo = VKI_SIGILL; - info.si_code = 1; /* jrs: no idea what this should be */ + info.si_code = VKI_ILL_ILLOPC; /* jrs: no idea what this should be */ info._sifields._sigfault._addr = (void*)addr; resume_scheduler(tid); @@ -1563,7 +1563,7 @@ void sync_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext *u "seg=%p-%p", info->si_code, fault, tid, esp, seg->start, seg->end); } - if (info->si_code == 1 /* SEGV_MAPERR */ + if (info->si_code == VKI_SEGV_MAPERR && seg && seg->kind == SkResvn && seg->smode == SmUpper diff --git a/include/vki-linux.h b/include/vki-linux.h index 4d986c58fd..f61152308c 100644 --- a/include/vki-linux.h +++ b/include/vki-linux.h @@ -431,6 +431,8 @@ typedef struct vki_siginfo { } _sifields; } vki_siginfo_t; +#define __VKI_SI_FAULT 0 + /* * si_code values * Digital reserves positive values for kernel-generated signals. @@ -438,6 +440,43 @@ typedef struct vki_siginfo { #define VKI_SI_USER 0 /* sent by kill, sigsend, raise */ #define VKI_SI_TKILL -6 /* sent by tkill system call */ +/* + * SIGILL si_codes + */ +#define VKI_ILL_ILLOPC (__VKI_SI_FAULT|1) /* illegal opcode */ +#define VKI_ILL_ILLOPN (__VKI_SI_FAULT|2) /* illegal operand */ +#define VKI_ILL_ILLADR (__VKI_SI_FAULT|3) /* illegal addressing mode */ +#define VKI_ILL_ILLTRP (__VKI_SI_FAULT|4) /* illegal trap */ +#define VKI_ILL_PRVOPC (__VKI_SI_FAULT|5) /* privileged opcode */ +#define VKI_ILL_PRVREG (__VKI_SI_FAULT|6) /* privileged register */ +#define VKI_ILL_COPROC (__VKI_SI_FAULT|7) /* coprocessor error */ +#define VKI_ILL_BADSTK (__VKI_SI_FAULT|8) /* internal stack error */ + +/* + * SIGFPE si_codes + */ +#define VKI_FPE_INTDIV (__VKI_SI_FAULT|1) /* integer divide by zero */ +#define VKI_FPE_INTOVF (__VKI_SI_FAULT|2) /* integer overflow */ +#define VKI_FPE_FLTDIV (__VKI_SI_FAULT|3) /* floating point divide by zero */ +#define VKI_FPE_FLTOVF (__VKI_SI_FAULT|4) /* floating point overflow */ +#define VKI_FPE_FLTUND (__VKI_SI_FAULT|5) /* floating point underflow */ +#define VKI_FPE_FLTRES (__VKI_SI_FAULT|6) /* floating point inexact result */ +#define VKI_FPE_FLTINV (__VKI_SI_FAULT|7) /* floating point invalid operation */ +#define VKI_FPE_FLTSUB (__VKI_SI_FAULT|8) /* subscript out of range */ + +/* + * SIGSEGV si_codes + */ +#define VKI_SEGV_MAPERR (__VKI_SI_FAULT|1) /* address not mapped to object */ +#define VKI_SEGV_ACCERR (__VKI_SI_FAULT|2) /* invalid permissions for mapped object */ + +/* + * SIGBUS si_codes + */ +#define VKI_BUS_ADRALN (__VKI_SI_FAULT|1) /* invalid address alignment */ +#define VKI_BUS_ADRERR (__VKI_SI_FAULT|2) /* non-existant physical address */ +#define VKI_BUS_OBJERR (__VKI_SI_FAULT|3) /* object specific hardware error */ + /* * This works because the alignment is ok on all current architectures * but we leave open this being overridden in the future