Julian Seward 7c542ccd39 Add new files resulting from merging in the 2.4.0 line. Many of these
seem to be simply duplication of the x86 instruction set tests into
the addrcheck and helgrind trees.  I'm not sure what this duplication
achieves.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3264
2005-03-10 23:23:45 +00:00

93 lines
2.1 KiB
C

#define _GNU_SOURCE
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/ucontext.h>
#include <asm/unistd.h>
#define VAL1 0x11223344
#define VAL2 0x44332211
static void handler1(int sig, siginfo_t *si, ucontext_t *uc)
{
/* Since the handler will be called as kill leaves the kernel,
this is replacing the kill syscall's return value. */
if (uc->uc_mcontext.gregs[REG_EAX] != 0)
printf("FAILED: handler2 expected eax == 0, not %d\n", uc->uc_mcontext.gregs[REG_EAX]);
uc->uc_mcontext.gregs[REG_EAX] = VAL1;
asm volatile (
"movl $0, %%edx\n"
"movl $0, %%esi\n"
"movl $0, %%edi\n"
: : : "edx", "esi", "edi");
}
static void handler2(int sig, struct sigcontext sc)
{
/* Since the handler will be called as kill leaves the kernel,
this is replacing the kill syscall's return value. */
if (sc.eax != 0)
printf("FAILED: handler2 expected eax == 0, not %d\n", sc.eax);
sc.eax = VAL2;
asm volatile (
"movl $0, %%edx\n"
"movl $0, %%esi\n"
"movl $0, %%edi\n"
: : : "edx", "esi", "edi");
}
int main()
{
struct sigaction sa;
int ret;
int v1, v2, v3, v4;
sa.sa_handler = handler1;
sa.sa_flags = SA_SIGINFO;
sigfillset(&sa.sa_mask);
sigaction(SIGUSR1, &sa, NULL);
sa.sa_handler = handler2;
sa.sa_flags = 0;
sigfillset(&sa.sa_mask);
sigaction(SIGUSR2, &sa, NULL);
asm volatile (
//"movl $0x11111111, %%ebp\n"
"movl $0x22222222, %%edx\n"
"movl $0x33333333, %%esi\n"
"movl $0x44444444, %%edi\n"
"int $0x80"
: "=a" (ret), "=d" (v2), "=S" (v3), "=D" (v4)
: "0" (__NR_kill), "b" (getpid()), "c" (SIGUSR1));
printf("v2=%x v3=%x v4=%x\n", v2, v3, v4);
if (ret == VAL1)
printf("PASS %x\n", ret);
else
printf("FAIL ret=%x not %x\n", ret, VAL1);
asm volatile (
//"movl $0x11111111, %%ebp\n"
"movl $0x22222222, %%edx\n"
"movl $0x33333333, %%esi\n"
"movl $0x44444444, %%edi\n"
"int $0x80"
: "=a" (ret), "=d" (v2), "=S" (v3), "=D" (v4)
: "0" (__NR_kill), "b" (getpid()), "c" (SIGUSR2));
printf("v2=%x v3=%x v4=%x\n", v2, v3, v4);
if (ret == VAL2)
printf("PASS %x\n", ret);
else
printf("FAIL ret=%x not %x\n", ret, VAL2);
return 0;
}