mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 10:05:29 +00:00
Add ptrace getreset testcase from Andreas Arnez
arnez AT linux DOT vnet DOT ibm DOT com git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13110
This commit is contained in:
parent
5bbaebd031
commit
6c0b993485
76
memcheck/tests/linux/getregset.c
Normal file
76
memcheck/tests/linux/getregset.c
Normal file
@ -0,0 +1,76 @@
|
||||
/* -*- mode: C; c-basic-offset: 3; -*- */
|
||||
|
||||
#include <assert.h>
|
||||
#include <elf.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static int
|
||||
err_out(const char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
non_empty(const char *buf, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
int c;
|
||||
volatile const char *p = buf;
|
||||
|
||||
for (i = 0; i != len; i++)
|
||||
c |= p[i];
|
||||
return c;
|
||||
}
|
||||
|
||||
static int
|
||||
do_child(void)
|
||||
{
|
||||
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) == -1)
|
||||
return err_out("ptrace traceme");
|
||||
raise(SIGUSR1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char buf[1024];
|
||||
struct iovec iov;
|
||||
pid_t cpid, pid;
|
||||
int status;
|
||||
|
||||
cpid = fork();
|
||||
if (cpid == -1)
|
||||
return err_out("fork");
|
||||
if (cpid == 0)
|
||||
return do_child();
|
||||
|
||||
pid = wait(&status);
|
||||
if (pid == -1)
|
||||
return err_out("wait");
|
||||
|
||||
/* Intentionally provide an uninitialized buffer to ptrace. */
|
||||
iov.iov_len = sizeof(buf);
|
||||
iov.iov_base = buf;
|
||||
if (ptrace(0x4204, cpid, NT_PRSTATUS, &iov) == -1)
|
||||
return err_out("ptrace getregset");
|
||||
|
||||
assert(iov.iov_base == buf);
|
||||
assert(iov.iov_len > 0 && iov.iov_len < sizeof(buf));
|
||||
|
||||
/* We're assuming here that NT_PRSTATUS never contains
|
||||
all-zeros. */
|
||||
assert(non_empty(buf, iov.iov_len));
|
||||
puts("OK");
|
||||
return 0;
|
||||
}
|
||||
0
memcheck/tests/linux/getregset.stderr.exp
Normal file
0
memcheck/tests/linux/getregset.stderr.exp
Normal file
1
memcheck/tests/linux/getregset.stdout.exp
Normal file
1
memcheck/tests/linux/getregset.stdout.exp
Normal file
@ -0,0 +1 @@
|
||||
OK
|
||||
2
memcheck/tests/linux/getregset.vgtest
Normal file
2
memcheck/tests/linux/getregset.vgtest
Normal file
@ -0,0 +1,2 @@
|
||||
prog: getregset
|
||||
vgopts: -q
|
||||
Loading…
x
Reference in New Issue
Block a user