2016-05-12 19:59:59 +03:00
/*
* Check decoding of ptrace syscall .
*
* Copyright ( c ) 2016 Dmitry V . Levin < ldv @ altlinux . org >
2018-02-14 01:00:00 +03:00
* Copyright ( c ) 2016 - 2018 The strace developers .
2016-05-12 19:59:59 +03:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
# include "tests.h"
2016-08-09 17:38:29 +03:00
# include <asm/unistd.h>
2016-05-12 19:59:59 +03:00
2017-02-20 03:10:35 +03:00
# include <errno.h>
2018-02-11 03:26:09 +03:00
# include "ptrace.h"
2018-02-21 21:20:54 +03:00
# include <inttypes.h>
2017-02-20 03:10:35 +03:00
# include <signal.h>
2018-02-21 21:20:54 +03:00
# include <stdint.h>
2017-02-20 03:10:35 +03:00
# include <stdio.h>
# include <string.h>
# include <sys/wait.h>
# include <unistd.h>
# include <linux/audit.h>
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
static const char * errstr ;
2016-05-12 19:59:59 +03:00
static long
do_ptrace ( unsigned long request , unsigned long pid ,
unsigned long addr , unsigned long data )
{
2016-09-20 18:17:37 +03:00
long rc = syscall ( __NR_ptrace , request , pid , addr , data ) ;
errstr = sprintrc ( rc ) ;
return rc ;
2016-05-12 19:59:59 +03:00
}
static void
test_peeksiginfo ( unsigned long pid , const unsigned long bad_request )
{
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_PEEKSIGINFO , pid , 0 , bad_request ) ;
printf ( " ptrace(PTRACE_PEEKSIGINFO, %u, NULL, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2016-05-12 19:59:59 +03:00
struct {
unsigned long long off ;
unsigned int flags , nr ;
} * const psi = tail_alloc ( sizeof ( * psi ) ) ;
2016-09-20 18:17:37 +03:00
psi - > off = 0xdeadbeeffacefeedULL ;
2016-05-12 19:59:59 +03:00
psi - > flags = 1 ;
psi - > nr = 42 ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_PEEKSIGINFO , pid , ( unsigned long ) psi , bad_request ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_PEEKSIGINFO, %u, {off=%llu "
2016-09-20 18:17:37 +03:00
" , flags=PTRACE_PEEKSIGINFO_SHARED, nr=%u}, %#lx) = %s \n " ,
( unsigned ) pid , psi - > off , psi - > nr , bad_request , errstr ) ;
2016-05-12 19:59:59 +03:00
pid = fork ( ) ;
2016-06-06 02:39:59 +03:00
if ( ( pid_t ) pid < 0 )
2016-05-12 19:59:59 +03:00
perror_msg_and_fail ( " fork " ) ;
if ( ! pid ) {
sigset_t mask ;
sigemptyset ( & mask ) ;
sigaddset ( & mask , SIGUSR1 ) ;
sigaddset ( & mask , SIGUSR2 ) ;
sigaddset ( & mask , SIGALRM ) ;
if ( sigprocmask ( SIG_BLOCK , & mask , NULL ) )
perror_msg_and_fail ( " sigprocmask " ) ;
raise ( SIGUSR1 ) ;
raise ( SIGUSR2 ) ;
raise ( SIGALRM ) ;
if ( do_ptrace ( PTRACE_TRACEME , 0 , 0 , 0 ) )
perror_msg_and_fail ( " child: PTRACE_TRACEME " ) ;
raise ( SIGSTOP ) ;
_exit ( 0 ) ;
}
const unsigned int nsigs = 4 ;
const uid_t uid = geteuid ( ) ;
siginfo_t * sigs = tail_alloc ( sizeof ( * sigs ) * nsigs ) ;
psi - > off = 0 ;
psi - > flags = 0 ;
psi - > nr = nsigs ;
for ( ; ; ) {
int status , tracee , saved ;
errno = 0 ;
tracee = wait ( & status ) ;
if ( tracee < = 0 ) {
if ( errno = = EINTR )
continue ;
saved = errno ;
2017-06-18 01:23:09 +03:00
kill ( pid , SIGKILL ) ;
2016-05-12 19:59:59 +03:00
errno = saved ;
perror_msg_and_fail ( " wait " ) ;
}
if ( WIFEXITED ( status ) ) {
if ( WEXITSTATUS ( status ) = = 0 )
break ;
error_msg_and_fail ( " unexpected exit status %u " ,
WEXITSTATUS ( status ) ) ;
}
if ( WIFSIGNALED ( status ) )
error_msg_and_fail ( " unexpected signal %u " ,
WTERMSIG ( status ) ) ;
if ( ! WIFSTOPPED ( status ) | | WSTOPSIG ( status ) ! = SIGSTOP ) {
kill ( pid , SIGKILL ) ;
error_msg_and_fail ( " unexpected wait status %x " ,
status ) ;
}
2016-09-20 18:17:37 +03:00
long rc = do_ptrace ( PTRACE_PEEKSIGINFO , pid ,
( unsigned long ) psi , ( unsigned long ) sigs ) ;
2016-05-12 19:59:59 +03:00
if ( rc < 0 ) {
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKSIGINFO, %u "
" , {off=%llu, flags=0, nr=%u}, %p) = %s \n " ,
2016-05-12 19:59:59 +03:00
( unsigned ) pid , psi - > off , psi - > nr , sigs ,
2016-09-20 18:17:37 +03:00
errstr ) ;
2016-05-12 19:59:59 +03:00
} else {
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKSIGINFO, %u "
" , {off=%llu, flags=0, nr=%u} "
2016-05-12 19:59:59 +03:00
" , [{si_signo=SIGUSR1, si_code=SI_TKILL "
" , si_pid=%u, si_uid=%u} "
" , {si_signo=SIGUSR2, si_code=SI_TKILL "
" , si_pid=%u, si_uid=%u} "
" , {si_signo=SIGALRM, si_code=SI_TKILL "
" , si_pid=%u, si_uid=%u} "
2016-09-20 18:17:37 +03:00
" ]) = %s \n " ,
2016-05-12 19:59:59 +03:00
( unsigned ) pid , psi - > off , psi - > nr ,
( unsigned ) pid , ( unsigned ) uid ,
( unsigned ) pid , ( unsigned ) uid ,
( unsigned ) pid , ( unsigned ) uid ,
2016-09-20 18:17:37 +03:00
errstr ) ;
2016-05-12 19:59:59 +03:00
}
if ( do_ptrace ( PTRACE_CONT , pid , 0 , 0 ) ) {
saved = errno ;
2017-06-18 01:23:09 +03:00
kill ( pid , SIGKILL ) ;
2016-05-12 19:59:59 +03:00
errno = saved ;
perror_msg_and_fail ( " ptrace " ) ;
}
printf ( " ptrace(PTRACE_CONT, %ld, NULL, SIG_0) = 0 \n " , pid ) ;
}
}
int
main ( void )
{
const unsigned long bad_request =
2016-09-20 18:17:37 +03:00
( unsigned long ) 0xdeadbeeffffffeedULL ;
2016-05-12 19:59:59 +03:00
const unsigned long bad_data =
2016-09-20 18:17:37 +03:00
( unsigned long ) 0xdeadcafefffff00dULL ;
2016-05-12 19:59:59 +03:00
const unsigned long pid =
2016-09-20 18:17:37 +03:00
( unsigned long ) 0xdefaced00000000ULL | ( unsigned ) getpid ( ) ;
2016-05-12 19:59:59 +03:00
2018-02-21 21:20:54 +03:00
uint64_t * filter_off = tail_alloc ( sizeof ( * filter_off ) ) ;
2017-02-20 03:10:35 +03:00
const unsigned int sigset_size = get_sigset_size ( ) ;
2016-05-12 19:59:59 +03:00
void * const k_set = tail_alloc ( sigset_size ) ;
2017-03-16 16:46:36 +03:00
TAIL_ALLOC_OBJECT_CONST_PTR ( siginfo_t , sip ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( bad_request , pid , 0 , 0 ) ;
printf ( " ptrace(%#lx /* PTRACE_??? */, %u, NULL, NULL) = %s \n " ,
bad_request , ( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_PEEKDATA , pid , bad_request , bad_data ) ;
2017-02-20 03:10:35 +03:00
# ifdef IA64
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKDATA, %u, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2017-02-20 03:10:35 +03:00
# else
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKDATA, %u, %#lx, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , bad_data , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_PEEKTEXT , pid , bad_request , bad_data ) ;
2017-02-20 03:10:35 +03:00
# ifdef IA64
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKTEXT, %u, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2017-02-20 03:10:35 +03:00
# else
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKTEXT, %u, %#lx, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , bad_data , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_PEEKUSER , pid , bad_request , bad_data ) ;
2017-02-20 03:10:35 +03:00
# ifdef IA64
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKUSER, %u, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2017-02-20 03:10:35 +03:00
# else
2016-09-20 18:17:37 +03:00
printf ( " ptrace(PTRACE_PEEKUSER, %u, %#lx, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , bad_data , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_POKEUSER , pid , bad_request , bad_data ) ;
printf ( " ptrace(PTRACE_POKEUSER, %u, %#lx, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , bad_data , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_ATTACH , pid , 0 , 0 ) ;
printf ( " ptrace(PTRACE_ATTACH, %u) = %s \n " , ( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_INTERRUPT , pid , 0 , 0 ) ;
printf ( " ptrace(PTRACE_INTERRUPT, %u) = %s \n " , ( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_KILL , pid , 0 , 0 ) ;
printf ( " ptrace(PTRACE_KILL, %u) = %s \n " , ( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_LISTEN , pid , 0 , 0 ) ;
printf ( " ptrace(PTRACE_LISTEN, %u) = %s \n " , ( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
sigset_t libc_set ;
sigemptyset ( & libc_set ) ;
sigaddset ( & libc_set , SIGUSR1 ) ;
memcpy ( k_set , & libc_set , sigset_size ) ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGMASK , pid , sigset_size , ( unsigned long ) k_set ) ;
printf ( " ptrace(PTRACE_SETSIGMASK, %u, %u, [USR1]) = %s \n " ,
( unsigned ) pid , sigset_size , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_GETSIGMASK , pid , sigset_size , ( unsigned long ) k_set ) ;
printf ( " ptrace(PTRACE_GETSIGMASK, %u, %u, %p) = %s \n " ,
( unsigned ) pid , sigset_size , k_set , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SECCOMP_GET_FILTER , pid , 42 , 0 ) ;
printf ( " ptrace(PTRACE_SECCOMP_GET_FILTER, %u, 42, NULL) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2018-02-21 21:20:54 +03:00
do_ptrace ( PTRACE_SECCOMP_GET_METADATA , pid , bad_data , 0 ) ;
printf ( " ptrace(PTRACE_SECCOMP_GET_METADATA, %u, %lu, NULL) = %s \n " ,
( unsigned ) pid , bad_data , errstr ) ;
do_ptrace ( PTRACE_SECCOMP_GET_METADATA , pid , 7 ,
( unsigned long ) filter_off ) ;
printf ( " ptrace(PTRACE_SECCOMP_GET_METADATA, %u, 7, %p) = %s \n " ,
( unsigned ) pid , filter_off , errstr ) ;
* filter_off = 0xfacefeeddeadc0deULL ;
do_ptrace ( PTRACE_SECCOMP_GET_METADATA , pid , bad_data ,
( unsigned long ) filter_off ) ;
printf ( " ptrace(PTRACE_SECCOMP_GET_METADATA, %u, %lu, "
" {filter_off=% " PRIu64 " }) = %s \n " ,
( unsigned ) pid , bad_data , * filter_off , errstr ) ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_GETEVENTMSG , pid , bad_request , bad_data ) ;
printf ( " ptrace(PTRACE_GETEVENTMSG, %u, %#lx, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , bad_data , errstr ) ;
2016-05-12 19:59:59 +03:00
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGIO ;
sip - > si_code = 1 ;
sip - > si_errno = ENOENT ;
sip - > si_band = - 2 ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGIO "
2016-09-20 18:17:37 +03:00
" , si_code=POLL_IN, si_errno=ENOENT, si_band=-2}) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2016-05-12 19:59:59 +03:00
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGTRAP ;
sip - > si_code = 1 ;
sip - > si_errno = ENOENT ;
sip - > si_pid = 2 ;
sip - > si_uid = 3 ;
sip - > si_ptr = ( void * ) bad_request ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGTRAP "
" , si_code=TRAP_BRKPT, si_errno=ENOENT, si_pid=2, si_uid=3 "
2016-09-20 18:17:37 +03:00
" , si_value={int=%d, ptr=%p}}) = %s \n " ,
( unsigned ) pid , bad_request , sip - > si_int , sip - > si_ptr ,
errstr ) ;
2016-05-12 19:59:59 +03:00
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGILL ;
sip - > si_code = 1 ;
sip - > si_errno = ENOENT ;
2016-09-20 18:17:37 +03:00
sip - > si_addr = ( void * ) ( unsigned long ) 0xfacefeeddeadbeefULL ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGILL "
2016-09-20 18:17:37 +03:00
" , si_code=ILL_ILLOPC, si_errno=ENOENT, si_addr=%p}) = %s \n " ,
( unsigned ) pid , bad_request , sip - > si_addr , errstr ) ;
2016-05-12 19:59:59 +03:00
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGFPE ;
sip - > si_code = 1 ;
sip - > si_errno = ENOENT ;
2016-09-20 18:17:37 +03:00
sip - > si_addr = ( void * ) ( unsigned long ) 0xfacefeeddeadbeefULL ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGFPE "
2016-09-20 18:17:37 +03:00
" , si_code=FPE_INTDIV, si_errno=ENOENT, si_addr=%p}) = %s \n " ,
( unsigned ) pid , bad_request , sip - > si_addr , errstr ) ;
2016-05-12 19:59:59 +03:00
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGBUS ;
sip - > si_code = 1 ;
sip - > si_errno = - 2 ;
2016-09-20 18:17:37 +03:00
sip - > si_addr = ( void * ) ( unsigned long ) 0xfacefeeddeadbeefULL ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGBUS "
2016-09-20 18:17:37 +03:00
" , si_code=BUS_ADRALN, si_errno=%d, si_addr=%p}) = %s \n " ,
2016-05-12 19:59:59 +03:00
( unsigned ) pid , bad_request , sip - > si_errno , sip - > si_addr ,
2016-09-20 18:17:37 +03:00
errstr ) ;
2016-05-12 19:59:59 +03:00
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGPROF ;
sip - > si_code = 0xbadc0ded ;
sip - > si_errno = - 2 ;
sip - > si_pid = 0 ;
sip - > si_uid = 3 ;
sip - > si_ptr = 0 ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGPROF "
2016-09-20 18:17:37 +03:00
" , si_code=%#x, si_errno=%d, si_pid=0, si_uid=3}) = %s \n " ,
2016-05-12 19:59:59 +03:00
( unsigned ) pid , bad_request , sip - > si_code , sip - > si_errno ,
2016-09-20 18:17:37 +03:00
errstr ) ;
2016-05-12 19:59:59 +03:00
# ifdef HAVE_SIGINFO_T_SI_SYSCALL
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGSYS ;
sip - > si_code = 1 ;
sip - > si_errno = ENOENT ;
2016-09-20 18:17:37 +03:00
sip - > si_call_addr = ( void * ) ( unsigned long ) 0xfacefeeddeadbeefULL ;
2016-05-12 19:59:59 +03:00
sip - > si_syscall = - 1U ;
sip - > si_arch = AUDIT_ARCH_X86_64 ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGSYS "
" , si_code=SYS_SECCOMP, si_errno=ENOENT, si_call_addr=%p "
2016-11-30 23:43:51 +03:00
" , si_syscall=%u, si_arch=AUDIT_ARCH_X86_64}) "
2016-09-20 18:17:37 +03:00
" = %s \n " ,
2016-05-12 19:59:59 +03:00
( unsigned ) pid , bad_request , sip - > si_call_addr , sip - > si_syscall ,
2016-09-20 18:17:37 +03:00
errstr ) ;
2016-11-30 23:50:26 +03:00
sip - > si_errno = 3141592653U ;
sip - > si_call_addr = NULL ;
sip - > si_syscall = __NR_read ;
sip - > si_arch = 0xda7a1057 ;
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGSYS "
" , si_code=SYS_SECCOMP, si_errno=%d, si_call_addr=NULL "
" , si_syscall=__NR_read, si_arch=%#x /* AUDIT_ARCH_??? */}) "
" = %s \n " ,
( unsigned ) pid , bad_request , sip - > si_errno , sip - > si_arch ,
errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
# if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
memset ( sip , - 1 , sizeof ( * sip ) ) ;
sip - > si_signo = SIGHUP ;
sip - > si_code = SI_TIMER ;
sip - > si_errno = ENOENT ;
sip - > si_timerid = 0xdeadbeef ;
sip - > si_overrun = - 1 ;
2016-09-20 18:17:37 +03:00
sip - > si_ptr = ( void * ) ( unsigned long ) 0xfacefeeddeadbeefULL ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGHUP "
" , si_code=SI_TIMER, si_errno=ENOENT, si_timerid=%#x "
2016-09-20 18:17:37 +03:00
" , si_overrun=%d, si_value={int=%d, ptr=%p}}) = %s \n " ,
2016-05-12 19:59:59 +03:00
( unsigned ) pid , bad_request , sip - > si_timerid , sip - > si_overrun ,
2016-09-20 18:17:37 +03:00
sip - > si_int , sip - > si_ptr , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_GETSIGINFO , pid , bad_request , ( unsigned long ) sip ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_GETSIGINFO, %u, %#lx, %p) "
2016-09-20 18:17:37 +03:00
" = %s \n " , ( unsigned ) pid , bad_request , sip , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_CONT , pid , 0 , SIGUSR1 ) ;
printf ( " ptrace(PTRACE_CONT, %u, NULL, SIGUSR1) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_DETACH , pid , 0 , SIGUSR2 ) ;
printf ( " ptrace(PTRACE_DETACH, %u, NULL, SIGUSR2) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SYSCALL , pid , 0 , SIGUSR1 ) ;
printf ( " ptrace(PTRACE_SYSCALL, %u, NULL, SIGUSR1) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
# ifdef PTRACE_SINGLESTEP
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SINGLESTEP , pid , 0 , SIGUSR2 ) ;
printf ( " ptrace(PTRACE_SINGLESTEP, %u, NULL, SIGUSR2) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
# ifdef PTRACE_SINGLEBLOCK
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SINGLEBLOCK , pid , 0 , SIGUSR1 ) ;
printf ( " ptrace(PTRACE_SINGLEBLOCK, %u, NULL, SIGUSR1) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
# ifdef PTRACE_SYSEMU
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SYSEMU , pid , 0 , SIGUSR2 ) ;
printf ( " ptrace(PTRACE_SYSEMU, %u, NULL, SIGUSR2) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
# ifdef PTRACE_SYSEMU_SINGLESTEP
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SYSEMU_SINGLESTEP , pid , 0 , SIGUSR1 ) ;
printf ( " ptrace(PTRACE_SYSEMU_SINGLESTEP, %u, NULL, SIGUSR1) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
# endif
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETOPTIONS ,
pid , 0 , PTRACE_O_TRACEFORK | PTRACE_O_TRACECLONE ) ;
2016-05-12 19:59:59 +03:00
printf ( " ptrace(PTRACE_SETOPTIONS, %u, NULL "
2016-09-20 18:17:37 +03:00
" , PTRACE_O_TRACEFORK|PTRACE_O_TRACECLONE) = %s \n " ,
( unsigned ) pid , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SEIZE , pid , bad_request , PTRACE_O_TRACESYSGOOD ) ;
printf ( " ptrace(PTRACE_SEIZE, %u, %#lx, PTRACE_O_TRACESYSGOOD) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_SETREGSET , pid , 1 , bad_request ) ;
printf ( " ptrace(PTRACE_SETREGSET, %u, NT_PRSTATUS, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2016-05-12 19:59:59 +03:00
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_GETREGSET , pid , 3 , bad_request ) ;
printf ( " ptrace(PTRACE_GETREGSET, %u, NT_PRPSINFO, %#lx) = %s \n " ,
( unsigned ) pid , bad_request , errstr ) ;
2016-05-12 19:59:59 +03:00
test_peeksiginfo ( pid , bad_request ) ;
2016-09-20 18:17:37 +03:00
do_ptrace ( PTRACE_TRACEME , 0 , 0 , 0 ) ;
printf ( " ptrace(PTRACE_TRACEME) = %s \n " , errstr ) ;
2016-05-12 19:59:59 +03:00
puts ( " +++ exited with 0 +++ " ) ;
return 0 ;
}