Skip to content

Commit

Permalink
Merge 60d4410 into fd60410
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-guene committed Feb 20, 2015
2 parents fd60410 + 60d4410 commit ed4b9f6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tests/ptrace-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <stdlib.h> /* exit, EXIT_*, */
#include <stdio.h> /* fprintf(3), stderr, */
#include <stdint.h> /* *int*_t, */
#include <sys/uio.h> /* struct iovec */
#include <elf.h> /* NT_PRSTATUS */

#if !defined(ARCH_X86_64) && !defined(ARCH_ARM_EABI) && !defined(ARCH_X86) && !defined(ARCH_SH4)
# if defined(__x86_64__)
Expand Down Expand Up @@ -178,6 +180,24 @@ typedef enum {

#endif

#if defined(PTRACE_GETREGS)
static long read_regs(pid_t pid, struct user_regs_struct *regs)
{
return ptrace(PTRACE_GETREGS, pid, NULL, regs);
}
#elif defined(PTRACE_GETREGSET)
static long read_regs(pid_t pid, struct user_regs_struct *regs)
{
struct iovec data;

data.iov_base = regs;
data.iov_len = sizeof(struct user_regs_struct);
return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &data);
}
#else
#error "PTRACE_GETREGS and PTRACE_GETREGSET not defined"
#endif

int main(int argc, char *argv[])
{
enum __ptrace_request restart_how;
Expand Down Expand Up @@ -289,7 +309,7 @@ int main(int argc, char *argv[])
case SIGTRAP:
fprintf(stderr, "sid %d: SIGTRAP\n", sid);

status = ptrace(PTRACE_GETREGS, pid, NULL, &regs);
status = read_regs(pid, &regs);
if (status < 0) {
fprintf(stderr,
"sigtrap: ?, ?\n");
Expand Down Expand Up @@ -341,7 +361,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "sid %d: PTRACE_EVENT_SYSGOOD\n", sid);
signal = 0;

status = ptrace(PTRACE_GETREGS, pid, NULL, &regs);
status = read_regs(pid, &regs);
if (status < 0) {
fprintf(stderr,
"syscall(?) = ?\n");
Expand Down
7 changes: 7 additions & 0 deletions tests/readlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <limits.h> /* PATH_MAX, */
#include <stdlib.h> /* exit(3), */
#include <sys/syscall.h> /* SYS_readlink, */
#include <fcntl.h> /* AT_FDCWD */

int main(int argc, char *argv[])
{
Expand All @@ -14,7 +15,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}

#if defined(SYS_readlink)
status = syscall(SYS_readlink, argv[1], path, PATH_MAX);
#elif defined(SYS_readlinkat)
status = syscall(SYS_readlinkat, AT_FDCWD, argv[1], path, PATH_MAX);
#else
#error "SYS_readlink and SYS_readlinkat doesn't exists"
#endif
if (status < 0) {
perror("readlink()");
exit(EXIT_FAILURE);
Expand Down
7 changes: 7 additions & 0 deletions tests/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h> /* perror(3), fprintf(3), */
#include <stdlib.h> /* exit(3), */
#include <sys/syscall.h> /* SYS_symlink, */
#include <fcntl.h> /* AT_FDCWD */

int main(int argc, char *argv[])
{
Expand All @@ -12,7 +13,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}

#if defined(SYS_symlink)
status = syscall(SYS_symlink, argv[1], argv[2]);
#elif defined(SYS_symlinkat)
status = syscall(SYS_symlinkat, argv[1], AT_FDCWD, argv[2]);
#else
#error "SYS_symlink and SYS_symlinkat doesn't exists"
#endif
if (status < 0) {
perror("symlink()");
exit(EXIT_FAILURE);
Expand Down
7 changes: 7 additions & 0 deletions tests/test-a8e69d6f.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
#include <stdlib.h> /* exit(3), */
#include <sys/syscall.h> /* SYS_lstat, */
#include <sys/stat.h> /* struct stat, */
#include <fcntl.h> /* AT_FDCWD */

int main(void)
{
struct stat stat;
int status;

#if defined(SYS_lstat)
status = syscall(SYS_lstat, "/proc/self/cwd/", &stat);
#elif defined(SYS_newfstatat)
status = syscall(SYS_newfstatat, AT_FDCWD, "/proc/self/cwd/", &stat, 0);
#else
#error "SYS_lstat and SYS_newfstatat doesn't exists"
#endif
if (status < 0) {
perror("lstat()");
exit(EXIT_FAILURE);
Expand Down
7 changes: 7 additions & 0 deletions tests/test-c10e2073.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
#include <stdlib.h> /* exit(3), */
#include <string.h> /* strlen(3), */
#include <sys/syscall.h> /* SYS_readlink, SYS_getcwd, */
#include <fcntl.h> /* AT_FDCWD */

int main(void)
{
char path[PATH_MAX];
int status;

#if defined(SYS_readlink)
status = syscall(SYS_readlink, "/proc/self/cwd", path, PATH_MAX);
#elif defined(SYS_readlinkat)
status = syscall(SYS_readlinkat, AT_FDCWD, "/proc/self/cwd", path, PATH_MAX);
#else
#error "SYS_readlink and SYS_readlinkat doesn't exists"
#endif
if (status < 0) {
perror("readlink()");
exit(EXIT_FAILURE);
Expand Down
7 changes: 7 additions & 0 deletions tests/test-d2175fc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h> /* exit(3), */
#include <strings.h> /* bzero(3), */
#include <sys/syscall.h> /* SYS_readlink, */
#include <fcntl.h> /* AT_FDCWD */

int main(int argc, char *argv[])
{
Expand All @@ -12,7 +13,13 @@ int main(int argc, char *argv[])

bzero(path, sizeof(path));

#if defined(SYS_readlink)
status = syscall(SYS_readlink, "/proc/self/exe", path, PATH_MAX);
#elif defined(SYS_readlinkat)
status = syscall(SYS_readlinkat, AT_FDCWD, "/proc/self/exe", path, PATH_MAX);
#else
#error "SYS_readlink and SYS_readlinkat doesn't exists"
#endif
if (status < 0) {
perror("readlink()");
exit(EXIT_FAILURE);
Expand Down

0 comments on commit ed4b9f6

Please sign in to comment.