1
0
mirror of https://github.com/ioacademy-jikim/debugging synced 2026-08-31 09:49:38 +00:00

first commit

This commit is contained in:
jikim
2015-12-13 22:34:58 +09:00
commit 0b589c7986
9455 changed files with 4350134 additions and 0 deletions
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,50 @@
include $(top_srcdir)/Makefile.tool-tests.am
dist_noinst_SCRIPTS = filter_stderr
EXTRA_DIST = \
brk.stderr.exp brk.vgtest \
capget.vgtest capget.stderr.exp capget.stderr.exp2 \
ioctl-tiocsig.vgtest ioctl-tiocsig.stderr.exp \
lsframe1.vgtest lsframe1.stdout.exp lsframe1.stderr.exp \
lsframe2.vgtest lsframe2.stdout.exp lsframe2.stderr.exp \
rfcomm.vgtest rfcomm.stderr.exp \
sigqueue.vgtest sigqueue.stderr.exp \
stack_changes.stderr.exp stack_changes.stdout.exp \
stack_changes.stdout.exp2 stack_changes.vgtest \
stack_switch.stderr.exp stack_switch.vgtest \
syscalls-2007.vgtest syscalls-2007.stderr.exp \
syslog-syscall.vgtest syslog-syscall.stderr.exp \
sys-openat.vgtest sys-openat.stderr.exp sys-openat.stdout.exp \
timerfd-syscall.vgtest timerfd-syscall.stderr.exp \
with-space.stderr.exp with-space.stdout.exp with-space.vgtest \
proc-auxv.vgtest proc-auxv.stderr.exp getregset.vgtest \
getregset.stderr.exp getregset.stdout.exp
check_PROGRAMS = \
brk \
capget \
ioctl-tiocsig \
getregset \
lsframe1 \
lsframe2 \
rfcomm \
sigqueue \
stack_changes \
stack_switch \
syscalls-2007 \
syslog-syscall \
timerfd-syscall \
proc-auxv
if HAVE_AT_FDCWD
check_PROGRAMS += sys-openat
endif
AM_CFLAGS += $(AM_FLAG_M3264_PRI)
AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
stack_switch_LDADD = -lpthread
timerfd_syscall_LDADD = -lrt
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,40 @@
#include <assert.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
// kernel brk() and libc brk() act quite differently...
int main(void)
{
int i;
void* orig_ds = sbrk(0);
void* ds = orig_ds;
void* vals[10];
void* res __attribute__((unused));
#define EOL ((void*)( ~(long)0 ))
vals[0] = (void*)0;
vals[1] = (void*)1;
vals[2] = ds - 0x1; // small shrink
vals[3] = ds;
vals[4] = ds + 0x1000; // small growth
vals[5] = ds + 0x40000000; // too-big growth
vals[6] = ds + 0x500; // shrink a little, but still above start size
vals[7] = ds - 0x1; // shrink below start size
// vals[8] = ds - 0x1000; // shrink a lot below start size (into text)
// vals[9] = EOL;
vals[8] = EOL;
for (i = 0; EOL != vals[i]; i++) {
res = (void*)syscall(__NR_brk, vals[i]);
}
assert( 0 == brk(orig_ds) ); // libc brk()
for (i = 0; EOL != vals[i]; i++) {
res = (void*)(long)brk(vals[i]);
}
return 0;
}
@@ -0,0 +1,12 @@
brk segment overflow in thread #1: can't grow to 0x........
brk segment overflow in thread #1: can't grow to 0x........
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,2 @@
prog: brk
stderr_filter: ../filter_allocs
@@ -0,0 +1,53 @@
#if defined(linux)
#include <stdio.h> /* printf() */
#include <unistd.h> /* syscall() */
#include <sys/syscall.h> /* __NR_capget */
#include <sys/types.h> /* uid_t */
#include <linux/capability.h> /* _LINUX_CAPABILITY_VERSION */
int main()
{
struct __user_cap_header_struct h;
struct __user_cap_data_struct d;
int syscall_result;
if (getuid() == 0)
fprintf(stderr, "Running as root\n");
h.version = _LINUX_CAPABILITY_VERSION;
h.pid = 0;
syscall_result = syscall(__NR_capget, &h, &d);
if (syscall_result >= 0)
{
fprintf(stderr,
"capget result:\n"
"effective %#x\n"
"permitted %#x\n"
"inheritable %#x\n",
d.effective,
d.permitted,
d.inheritable);
}
else
{
perror("capget");
}
return 0;
}
#else
#include <stdio.h>
int main()
{
fprintf(stderr, "This program is Linux-specific\n");
return 0;
}
#endif
@@ -0,0 +1,14 @@
capget result:
effective 0
permitted 0
inheritable 0
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,15 @@
Running as root
capget result:
effective 0x........
permitted 0x........
inheritable 0
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,2 @@
prog: capget
stderr_filter: ../filter_allocs
@@ -0,0 +1,3 @@
#! /bin/sh
../filter_stderr "$@"
@@ -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 = 0;
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,0 +1,4 @@
prog: getregset
vgopts: -q
prereq: ../../../tests/os_test linux 2.6.33 && ! ../../../tests/arch_test mips32 && ! ../../../tests/arch_test ppc64
@@ -0,0 +1,9 @@
#include <sys/ioctl.h>
int main()
{
#ifdef TIOCSIG
ioctl(9, TIOCSIG, 9);
#endif
return 0;
}
@@ -0,0 +1,2 @@
prog: ioctl-tiocsig
vgopts: -q
@@ -0,0 +1,26 @@
/* Demonstrate Memcheck correctly handling a 64M array on the stack.
Requires --max-stackframe=67108884 or above. And since it
generates a very large stack, --main-stacksize=67200000
(approximately) is also required. */
#include <stdio.h>
#define N_MBYTES 64
#define N_INTS ((N_MBYTES * 1048576) / sizeof(int))
int main ( void )
{
int i, sum;
int arr[N_INTS];
fprintf(stderr, "lsframe1: start\n");
for (i = 0; i < N_INTS; i++)
arr[i] = i;
sum = 0;
for (i = 0; i < N_INTS; i++)
sum += arr[i];
fprintf(stderr, "lsframe1: done, result is %d\n", sum);
return 0;
}
@@ -0,0 +1,12 @@
lsframe1: start
lsframe1: done, result is -8388608
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,3 @@
prog: lsframe1
vgopts: --main-stacksize=67200000 --max-stackframe=67200000
stderr_filter: ../filter_allocs
@@ -0,0 +1,34 @@
/* Demonstrate Memcheck correctly handling chain of 64 recursive
calls, each of which allocates a 1 M array on the stack. Requires
--main-stacksize=67117057 (on amd64-linux) or above, but works fine
if you specify that. */
#include <stdio.h>
#define N_MBYTES 64
#define N_INTS_PER_MBYTE (1048576 / sizeof(int))
int rec ( int depth )
{
int i, zzz;
int arr[N_INTS_PER_MBYTE];
if (depth == 0) return 0;
for (i = 0; i < N_INTS_PER_MBYTE; i++)
arr[i] = i * depth;
zzz = rec(depth-1);
for (i = 0; i < N_INTS_PER_MBYTE; i++)
zzz += arr[i];
return zzz;
}
int main ( void )
{
int sum;
fprintf(stderr, "lsframe2: start\n");
sum = rec(N_MBYTES);
fprintf(stderr, "lsframe2: done, result is %d\n", sum);
return 0;
}
@@ -0,0 +1,12 @@
lsframe2: start
lsframe2: done, result is -272629760
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,3 @@
prog: lsframe2
vgopts: --main-stacksize=68500000
stderr_filter: ../filter_allocs
@@ -0,0 +1,62 @@
#include <elf.h>
#include <link.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int
main (int argc, char **argv, char **envp)
{
ElfW(auxv_t) auxv;
ElfW(auxv_t) *auxv_p;
void *entry0 = NULL;
void *entry1 = NULL;
char *platform0 = NULL;
char *platform1 = NULL;
// First try the "traditional" way.
while (*envp++ != NULL)
; /* Skip, skip, skip... and after finding a NULL we have the auxv. */
for (auxv_p = (ElfW(auxv_t) *) envp;
auxv_p->a_type != AT_NULL;
auxv_p++)
{
if (auxv_p->a_type == AT_ENTRY)
entry0 = (void *) auxv_p->a_un.a_val;
if (auxv_p->a_type == AT_PLATFORM)
platform0 = strdup((char *) auxv_p->a_un.a_val);
}
// Now the /proc way as often used in libraries.
int fd = open("/proc/self/auxv", O_RDONLY);
if (fd == -1)
return -1;
while (read(fd, &auxv, sizeof(auxv)) == sizeof(auxv))
{
if (auxv.a_type == AT_ENTRY)
entry1 = (void *) auxv.a_un.a_val;
if (auxv.a_type == AT_PLATFORM)
platform1 = strdup((char *) auxv.a_un.a_val);
}
close(fd);
if (entry0 == entry1 && entry0 != NULL)
fprintf(stderr, "entries OK\n");
if (strcmp (platform0, platform1) == 0)
fprintf(stderr, "platform OK\n");
free (platform0);
free (platform1);
return 0;
}
@@ -0,0 +1,2 @@
entries OK
platform OK
@@ -0,0 +1,3 @@
prereq: LD_SHOW_AUXV=1 /bin/echo | grep -q AT_PLATFORM
prog: proc-auxv
vgopts: -q
@@ -0,0 +1,74 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "../../memcheck.h"
/* user space headers might not be there, define things ourselves. */
typedef struct {
uint8_t b[6];
} __attribute__((packed)) vui_bdaddr_t;
struct vui_sockaddr_rc {
sa_family_t rc_family;
vui_bdaddr_t rc_bdaddr;
uint8_t rc_channel;
};
#define VUI_AF_BLUETOOTH 31
#define VUI_BTPROTO_RFCOMM 3
#define VUI_BDADDR_ANY (&(vui_bdaddr_t) {{0, 0, 0, 0, 0, 0}})
int
main (int argc, char **argv)
{
int nSocket;
nSocket = socket(VUI_AF_BLUETOOTH, SOCK_STREAM, VUI_BTPROTO_RFCOMM);
if (nSocket < 0)
{
// Not supported, nothing to test...
return 1;
}
struct vui_sockaddr_rc aAddr;
// Store correct values in aAddr but marking it undefined
// so as to generate errors. We need to have deterministic
// undefined values to have a reproducible test.
aAddr.rc_family = VUI_AF_BLUETOOTH;
aAddr.rc_bdaddr = *VUI_BDADDR_ANY;
aAddr.rc_channel = 5;
VALGRIND_MAKE_MEM_UNDEFINED(&aAddr, sizeof(aAddr));
// We re-assign below each piece one by one, so as to
// have the piece marked initialised.
// Ignore return values.
// Everything uninit (family, ...)
bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
// Same but with an unknown family (we hope :)
aAddr.rc_family = 12345;
// (reset everything to uninit)
VALGRIND_MAKE_MEM_UNDEFINED(&aAddr, sizeof(aAddr));
bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
aAddr.rc_family = VUI_AF_BLUETOOTH;
// uninit bdaddr and channel.
bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
aAddr.rc_bdaddr = *VUI_BDADDR_ANY;
// uninit channel.
bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
aAddr.rc_channel = 5;
// Everything correctly init.
bind(nSocket, (struct sockaddr *) &aAddr, sizeof(aAddr));
return 0;
}
@@ -0,0 +1,64 @@
Syscall param socketcall.bind(my_addr.sa_family) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:53)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:45)
Syscall param socketcall.bind(my_addr.rc_bdaddr) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:53)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:45)
Syscall param socketcall.bind(my_addr.rc_channel) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:53)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:45)
Syscall param socketcall.bind(my_addr.sa_family) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:59)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:58)
Syscall param socketcall.bind(my_addr.sa_data) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:59)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:58)
Syscall param socketcall.bind(my_addr.rc_bdaddr) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:63)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:58)
Syscall param socketcall.bind(my_addr.rc_channel) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:63)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:58)
Syscall param socketcall.bind(my_addr.rc_channel) points to uninitialised byte(s)
...
by 0x........: main (rfcomm.c:67)
Address 0x........ is on thread 1's stack
in frame #1, created by main (rfcomm.c:26)
Uninitialised value was created by a client request
at 0x........: main (rfcomm.c:58)
@@ -0,0 +1,5 @@
prog: rfcomm
vgopts: -q --track-origins=yes
# Will exit -1 if AF_BLUETOOTH not supported
prereq: ./rfcomm
@@ -0,0 +1,36 @@
/* Test program that invokes the Linux system call rt_sigqueueinfo(). */
#include <signal.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <syscall.h>
#include <unistd.h>
int main(int argc, char **argv)
{
siginfo_t *si;
const size_t sz = sizeof(*si);
if (argc == 1) {
fprintf(stderr, "sizeof(*si) = %zu\n", sz);
fprintf(stdout, "offsetof(siginfo_t, si_signo) = %zd\n",
offsetof(siginfo_t, si_signo));
fprintf(stdout, "offsetof(siginfo_t, si_errno) = %zd\n",
offsetof(siginfo_t, si_errno));
fprintf(stdout, "offsetof(siginfo_t, si_code) = %zd\n",
offsetof(siginfo_t, si_code));
fprintf(stdout, "offsetof(siginfo_t, _sifields) = %zd\n",
offsetof(siginfo_t, _sifields));
}
si = calloc(1, sz);
si->si_signo = SIGWINCH;
si->si_code = SI_QUEUE;
si->si_pid = getpid();
si->si_uid = getuid();
syscall(__NR_rt_sigqueueinfo, getpid(), SIGWINCH, si);
free(si);
fprintf(stderr, "Done.\n");
return 0;
}
@@ -0,0 +1,11 @@
Done.
HEAP SUMMARY:
in use at exit: 0 bytes in 0 blocks
total heap usage: 1 allocs, 1 frees, 128 bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,2 @@
prog: sigqueue
args: -q
@@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
#include "tests/sys_mman.h"
#include "valgrind.h"
#define STACK_SIZE (10 * 4096)
// This test is checking the libc context calls (setcontext, etc.) and
// checks that Valgrind notices their stack changes properly.
typedef struct ucontext mycontext;
mycontext ctx1, ctx2, oldc;
int count;
void hello(mycontext *newc)
{
printf("hello, world: %d\n", count);
if (count++ == 2)
newc = &oldc;
setcontext(newc);
}
int init_context(mycontext *uc)
{
void *stack;
int ret;
if (getcontext(uc) == -1) {
//perror("getcontext");
printf("getcontext() doesn't seem to work\n");
exit(1);
}
stack = (void *)mmap(0, STACK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (stack == (void*)-1) {
perror("mmap");
exit(1);
}
ret = VALGRIND_STACK_REGISTER(stack, stack + STACK_SIZE);
uc->uc_link = NULL;
uc->uc_stack.ss_sp = stack;
uc->uc_stack.ss_size = STACK_SIZE;
uc->uc_stack.ss_flags = 0;
return ret;
}
int main(int argc, char **argv)
{
int c1 = init_context(&ctx1);
int c2 = init_context(&ctx2);
makecontext(&ctx1, (void (*)()) hello, 1, &ctx2);
makecontext(&ctx2, (void (*)()) hello, 1, &ctx1);
swapcontext(&oldc, &ctx1);
VALGRIND_STACK_DEREGISTER(c1);
//free(ctx1.uc_stack.ss_sp);
VALGRIND_STACK_DEREGISTER(c2);
//free(ctx2.uc_stack.ss_sp);
return 0;
}
@@ -0,0 +1,3 @@
hello, world: 0
hello, world: 1
hello, world: 2
@@ -0,0 +1 @@
getcontext() doesn't seem to work
@@ -0,0 +1,2 @@
prog: stack_changes
vgopts: -q
@@ -0,0 +1,57 @@
#define _XOPEN_SOURCE 600
#define _BSD_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <sched.h>
#include <stdlib.h>
#include <string.h>
#include "tests/sys_mman.h"
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
#include "valgrind.h"
#define STACK_SIZE 8192
#ifndef CLONE_THREAD
#define CLONE_THREAD 0x00010000 /* Same thread group? */
#endif
static int thread_main(void *arg)
{
char buffer[1024];
memset( buffer, 1, sizeof( buffer ) );
sleep(2); /* ppc64-linux hack */
return memchr( buffer, 1, sizeof( buffer ) ) == NULL;
}
int main(int argc, char **argv)
{
void *stack;
int stackid __attribute__((unused));
pid_t pid;
/* "2*" is a ppc64-linux hack */
if ( ( stack = mmap( NULL, 2* STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 ) ) == MAP_FAILED )
{
perror( "mmap" );
exit( 1 );
}
stackid = VALGRIND_STACK_REGISTER( stack, stack + STACK_SIZE );
if ( ( pid = clone( thread_main, stack + STACK_SIZE, CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|SIGCHLD, NULL ) ) == -1 )
{
perror( "clone" );
exit( 1 );
}
sleep( 1 );
exit( 0 );
}
@@ -0,0 +1,2 @@
prog: stack_switch
vgopts: -q
@@ -0,0 +1,19 @@
/* The bug that gave rise to this is
https://bugs.kde.org/show_bug.cgi?id=307103
*/
#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
int main (void)
{
int dfd = open ("/tmp", O_RDONLY);
__attribute__((unused)) int fd1 = openat (dfd, "abc", O_RDONLY);
/* This is fine, absolute path. */
__attribute__((unused)) int fd2 = openat (0x12345678, "/tmp/abc", O_RDONLY);
__attribute__((unused)) int fd3 = openat (AT_FDCWD, "abc", O_RDONLY);
/* This is the only one that should warn. */
__attribute__((unused)) int fd4 = openat (0x12345678, "abc", O_RDONLY);
return 0;
}
@@ -0,0 +1,11 @@
Warning: invalid file descriptor 305419896 in syscall openat()
HEAP SUMMARY:
in use at exit: 0 bytes in 0 blocks
total heap usage: 0 allocs, 0 frees, 0 bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,2 @@
prereq: test -e ./sys-openat
prog: sys-openat
@@ -0,0 +1,83 @@
/**
* Test program for some Linux syscalls introduced during 2006 and 2007:
* - epoll_pwait() was introduced in the 2.6.19 kernel, released in November
* 2006.
* - utimensat(), eventfd(), timerfd() and signalfd() were introduced in the
* 2.6.22 kernel, released in July 2007.
*
* See also http://bugs.kde.org/show_bug.cgi?id=160907.
*/
#define _GNU_SOURCE
#include "../../config.h"
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#if defined(HAVE_SYS_EPOLL_H)
#include <sys/epoll.h>
#endif
#if defined(HAVE_SYS_EVENTFD_H)
#include <sys/eventfd.h>
#endif
#if defined(HAVE_SYS_POLL_H)
#include <sys/poll.h>
#endif
#if defined(HAVE_SYS_SIGNALFD_H)
#include <sys/signalfd.h>
#endif
#include <sys/stat.h>
#include <unistd.h>
int main (void)
{
#if defined(HAVE_SIGNALFD) && defined(HAVE_EVENTFD) \
&& defined(HAVE_EVENTFD_READ) && defined(HAVE_PPOLL)
{
sigset_t mask;
int fd, fd2;
eventfd_t ev;
struct timespec ts = { .tv_sec = 1, .tv_nsec = 0 };
struct pollfd pfd[2];
sigemptyset (&mask);
sigaddset (&mask, SIGUSR1);
fd = signalfd (-1, &mask, 0);
sigaddset (&mask, SIGUSR2);
fd = signalfd (fd, &mask, 0);
fd2 = eventfd (5, 0);
eventfd_read (fd2, &ev);
pfd[0].fd = fd;
pfd[0].events = POLLIN|POLLOUT;
pfd[1].fd = fd2;
pfd[1].events = POLLIN|POLLOUT;
ppoll (pfd, 2, &ts, &mask);
}
#endif
#if defined(HAVE_UTIMENSAT)
unlink("/tmp/valgrind-utimensat-test");
close (creat ("/tmp/valgrind-utimensat-test", S_IRUSR | S_IWUSR));
{
struct timespec ts2[2] = { [0].tv_sec = 10000000, [1].tv_sec = 20000000 };
utimensat (AT_FDCWD, "/tmp/valgrind-utimensat-test", ts2, 0);
}
unlink("/tmp/valgrind-utimensat-test");
#endif
#if defined(HAVE_EPOLL_CREATE) && defined(HAVE_EPOLL_PWAIT)
{
int fd3;
struct epoll_event evs[10];
sigset_t mask;
sigemptyset (&mask);
sigaddset (&mask, SIGUSR1);
sigaddset (&mask, SIGUSR2);
fd3 = epoll_create (10);
epoll_pwait (fd3, evs, 10, 0, &mask);
}
#endif
return 0;
}
@@ -0,0 +1,10 @@
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,2 @@
prog: syscalls-2007
stderr_filter: ../filter_allocs
@@ -0,0 +1,23 @@
/** Test program for the syslog() system call.
* From the syslog(2) man page:
* If you need the libc function syslog() (which talks to syslogd(8)),
* then look at syslog(3). The system call of this name is about control-
* ling the kernel printk() buffer, and the glibc version is called
* klogctl().
*/
#include "../../config.h"
#include <stdio.h>
#if defined(HAVE_SYS_KLOG_H)
#include <sys/klog.h>
#endif
int main(int argc, char** argv)
{
int number_of_unread_characters;
#if defined HAVE_KLOGCTL
number_of_unread_characters = klogctl(9, 0, 0);
#endif
fprintf(stderr, "Done.\n");
return 0 * number_of_unread_characters;
}
@@ -0,0 +1,11 @@
Done.
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,2 @@
prog: syslog-syscall
stderr_filter: ../filter_allocs
@@ -0,0 +1,316 @@
/** Test Valgrind's interception of the Linux syscalls timerfd_create(),
* timerfd_gettime() and timerfd_settime().
*
* This is a modified version of
* timerfd-test2 by Davide Libenzi (test app for timerfd)
* Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
* Modified for inclusion in Valgrind.
* Copyright (C) 2008 Bart Van Assche <bvanassche@acm.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* See also http://www.xmailserver.org/timerfd-test2.c
*/
#define _GNU_SOURCE
#include "../../../config.h"
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#if defined(HAVE_SYS_SIGNAL_H)
#include <sys/signal.h>
#endif
#if defined(HAVE_SYS_SYSCALL_H)
#include <sys/syscall.h>
#endif
#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif
#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif
/*
* timerfd_* system call numbers introduced in 2.6.23. These constants are
* not yet in the glibc 2.7 headers, that is why they are defined here.
*/
#ifndef __NR_timerfd_create
#if defined(__x86_64__)
#define __NR_timerfd_create 283
#elif defined(__i386__)
#define __NR_timerfd_create 322
#elif defined(__powerpc__)
#define __NR_timerfd_create 306
#elif defined(__s390x__)
#define __NR_timerfd_create 319
#else
#error Cannot detect your architecture!
#endif
#endif
#ifndef __NR_timerfd_settime
#if defined(__x86_64__)
#define __NR_timerfd_settime 286
#define __NR_timerfd_gettime 287
#elif defined(__i386__)
#define __NR_timerfd_settime 325
#define __NR_timerfd_gettime 326
#elif defined(__powerpc__)
#define __NR_timerfd_settime 311
#define __NR_timerfd_gettime 312
#elif defined(__s390x__)
#define __NR_timerfd_settime 320
#define __NR_timerfd_gettime 321
#else
#error Cannot detect your architecture!
#endif
#endif
/* Definitions from include/linux/timerfd.h */
#define TFD_TIMER_ABSTIME (1 << 0)
struct tmr_type
{
int id;
char const *name;
};
#if defined(HAVE_CLOCK_GETTIME)
unsigned long long getustime(int clockid)
{
struct timespec tp;
if (clock_gettime((clockid_t) clockid, &tp))
{
perror("clock_gettime");
return 0;
}
return 1000000ULL * tp.tv_sec + tp.tv_nsec / 1000;
}
#else
unsigned long long getustime(int clockid)
{
fprintf(stderr, "error: clock_gettime\n");
return 0;
}
#endif
void set_timespec(struct timespec *tmr, unsigned long long ustime)
{
tmr->tv_sec = (time_t) (ustime / 1000000ULL);
tmr->tv_nsec = (long) (1000ULL * (ustime % 1000000ULL));
}
int timerfd_create(int clockid, int flags)
{
return syscall(__NR_timerfd_create, clockid, flags);
}
int timerfd_settime(int ufc, int flags, const struct itimerspec *utmr,
struct itimerspec *otmr)
{
return syscall(__NR_timerfd_settime, ufc, flags, utmr, otmr);
}
int timerfd_gettime(int ufc, struct itimerspec *otmr)
{
return syscall(__NR_timerfd_gettime, ufc, otmr);
}
long waittmr(int tfd, int timeo)
{
u_int64_t ticks;
struct pollfd pfd;
pfd.fd = tfd;
pfd.events = POLLIN;
pfd.revents = 0;
if (poll(&pfd, 1, timeo) < 0)
{
perror("poll");
return -1;
}
if ((pfd.revents & POLLIN) == 0)
{
fprintf(stderr, "no ticks happened\n");
return -1;
}
if (read(tfd, &ticks, sizeof(ticks)) != sizeof(ticks))
{
perror("timerfd read");
return -1;
}
return ticks;
}
int main(int ac, char **av)
{
int i, tfd;
long ticks;
unsigned long long tnow, ttmr;
u_int64_t uticks;
struct itimerspec tmr;
struct tmr_type clks[] =
{
#if defined(HAVE_CLOCK_MONOTONIC)
{ CLOCK_MONOTONIC, "CLOCK MONOTONIC" },
#endif
{ CLOCK_REALTIME, "CLOCK REALTIME" },
};
for (i = 0; i < sizeof(clks) / sizeof(clks[0]); i++)
{
fprintf(stderr, "\n\n---------------------------------------\n");
fprintf(stderr, "| testing %s\n", clks[i].name);
fprintf(stderr, "---------------------------------------\n\n");
fprintf(stderr, "relative timer test (at 500 ms) ...\n");
set_timespec(&tmr.it_value, 500 * 1000);
set_timespec(&tmr.it_interval, 0);
tnow = getustime(clks[i].id);
if ((tfd = timerfd_create(clks[i].id, 0)) == -1)
{
perror("timerfd_create");
return 1;
}
if (timerfd_settime(tfd, 0, &tmr, NULL))
{
perror("timerfd_settime");
return 1;
}
fprintf(stderr, "waiting timer ...\n");
ticks = waittmr(tfd, -1);
ttmr = getustime(clks[i].id);
if (ticks <= 0)
fprintf(stderr, "whooops! no timer showed up!\n");
else
fprintf(stderr, "got timer ticks (%ld) after %.1f s\n",
ticks, (ttmr - tnow) * 1e-6);
fprintf(stderr, "absolute timer test (at 500 ms) ...\n");
tnow = getustime(clks[i].id);
set_timespec(&tmr.it_value, tnow + 500 * 1000);
set_timespec(&tmr.it_interval, 0);
if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &tmr, NULL))
{
perror("timerfd_settime");
return 1;
}
fprintf(stderr, "waiting timer ...\n");
ticks = waittmr(tfd, -1);
ttmr = getustime(clks[i].id);
if (ticks <= 0)
fprintf(stderr, "whooops! no timer showed up!\n");
else
fprintf(stderr, "got timer ticks (%ld) after %.1f s\n",
ticks, (ttmr - tnow) * 1e-6);
fprintf(stderr, "sequential timer test (100 ms clock) ...\n");
tnow = getustime(clks[i].id);
set_timespec(&tmr.it_value, tnow + 100 * 1000);
set_timespec(&tmr.it_interval, 100 * 1000);
if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &tmr, NULL))
{
perror("timerfd_settime");
return 1;
}
fprintf(stderr, "sleeping one second ...\n");
sleep(1);
if (timerfd_gettime(tfd, &tmr))
{
perror("timerfd_gettime");
return 1;
}
fprintf(stderr, "timerfd_gettime returned:\n"
"\tit_value = %.1f it_interval = %.1f\n",
tmr.it_value.tv_sec + 1e-9 * tmr.it_value.tv_nsec,
tmr.it_interval.tv_sec + 1e-9 * tmr.it_interval.tv_nsec);
fprintf(stderr, "sleeping 1 second ...\n");
sleep(1);
fprintf(stderr, "waiting timer ...\n");
ticks = waittmr(tfd, -1);
ttmr = getustime(clks[i].id);
if (ticks <= 0)
fprintf(stderr, "whooops! no timer showed up!\n");
else
{
const double delta = (ttmr - tnow) * 1e-6;
if (19 <= ticks && ticks <= 55 && 1.9 < delta && delta < 5.5)
fprintf(stderr, "got about 20 timer ticks after about 2s\n");
else
fprintf(stderr, "got timer ticks (%ld) after %.2f s\n", ticks, delta);
}
fprintf(stderr, "O_NONBLOCK test ...\n");
tnow = getustime(clks[i].id);
set_timespec(&tmr.it_value, 100 * 1000);
set_timespec(&tmr.it_interval, 0);
if (timerfd_settime(tfd, 0, &tmr, NULL))
{
perror("timerfd_settime");
return 1;
}
#if 0
fprintf(stderr, "timerfd = %d\n", tfd);
#endif
fprintf(stderr, "waiting timer (flush the single tick) ...\n");
ticks = waittmr(tfd, -1);
ttmr = getustime(clks[i].id);
if (ticks <= 0)
fprintf(stderr, "whooops! no timer showed up!\n");
else
fprintf(stderr, "got timer ticks (%ld) after %.1f s\n",
ticks, (ttmr - tnow) * 1e-6);
fcntl(tfd, F_SETFL, fcntl(tfd, F_GETFL, 0) | O_NONBLOCK);
if (read(tfd, &uticks, sizeof(uticks)) > 0)
fprintf(stderr, "whooops! timer ticks not zero when should have been\n");
else if (errno != EAGAIN)
fprintf(stderr, "whooops! bad errno value (%d = '%s')!\n",
errno, strerror(errno));
else
fprintf(stderr, "success\n");
fcntl(tfd, F_SETFL, fcntl(tfd, F_GETFL, 0) & ~O_NONBLOCK);
close(tfd);
}
return 0;
}
@@ -0,0 +1,56 @@
---------------------------------------
| testing CLOCK MONOTONIC
---------------------------------------
relative timer test (at 500 ms) ...
waiting timer ...
got timer ticks (1) after 0.5 s
absolute timer test (at 500 ms) ...
waiting timer ...
got timer ticks (1) after 0.5 s
sequential timer test (100 ms clock) ...
sleeping one second ...
timerfd_gettime returned:
it_value = 0.1 it_interval = 0.1
sleeping 1 second ...
waiting timer ...
got about 20 timer ticks after about 2s
O_NONBLOCK test ...
waiting timer (flush the single tick) ...
got timer ticks (1) after 0.1 s
success
---------------------------------------
| testing CLOCK REALTIME
---------------------------------------
relative timer test (at 500 ms) ...
waiting timer ...
got timer ticks (1) after 0.5 s
absolute timer test (at 500 ms) ...
waiting timer ...
got timer ticks (1) after 0.5 s
sequential timer test (100 ms clock) ...
sleeping one second ...
timerfd_gettime returned:
it_value = 0.1 it_interval = 0.1
sleeping 1 second ...
waiting timer ...
got about 20 timer ticks after about 2s
O_NONBLOCK test ...
waiting timer (flush the single tick) ...
got timer ticks (1) after 0.1 s
success
HEAP SUMMARY:
in use at exit: 0 bytes in 0 blocks
total heap usage: 0 allocs, 0 frees, 0 bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@@ -0,0 +1,2 @@
prereq: ../../../tests/os_test linux 2.6.25
prog: timerfd-syscall
@@ -0,0 +1,3 @@
Conditional jump or move depends on uninitialised value(s)
at 0x........: main (manuel1.c:7)
@@ -0,0 +1,15 @@
# Use the "prereq" command to copy manuel1 to a filename containing a space.
# This used to not work properly, because the debug info would not be read
# correctly for filenames containing spaces (bug #88678).
#
# Nb: we only run this test on Linux. This is because on Darwin you can't
# easily rename an executable with a .dSYM -- the original executable name
# gets baked into the .dSYM, so renaming the .dSYM as well isn't enough, you
# have to modify the contents of the .dSYM. Another idea would be to avoid
# the renaming in the first place by just using 'with space' as the
# filename, but automake doesn't seem to like files containing spaces.
prereq: cp ../manuel1 'with space'
prog: 'with space'
vgopts: -q
cleanup: rm 'with space'
stderr_filter_args: manuel1.c