2016-04-26 11:03:07 +03:00
# include "tests.h"
2016-08-09 17:38:29 +03:00
# include <asm/unistd.h>
2016-04-26 11:03:07 +03:00
# ifdef __NR_reboot
# include <stdio.h>
# include <linux / reboot.h>
# include <unistd.h>
# define INVALID_MAGIC 319887762
# define INVALID_CMD 0x01234568
2018-01-10 07:31:15 +03:00
# define STR32 "AbCdEfGhIjKlMnOpQrStUvWxYz012345"
# define STR128 STR32 STR32 STR32 STR32
2016-04-26 11:03:07 +03:00
int
main ( void )
{
2018-01-10 07:31:15 +03:00
static const kernel_ulong_t bogus_magic1 =
( kernel_ulong_t ) 0xFFFFFFFFFFFFFFFFULL ;
static const kernel_ulong_t bogus_magic2 =
( kernel_ulong_t ) 0xdeadfacefa57beefULL ;
static const kernel_ulong_t bogus_cmd =
( kernel_ulong_t ) 0xbadda7a09caffee1ULL ;
2016-04-26 11:03:07 +03:00
static const char buf [ ] = " reboot " ;
2018-01-10 07:31:15 +03:00
static const char str256_buf [ ] = STR128 STR128 ;
long rc ;
char * str256 = tail_memdup ( str256_buf , sizeof ( str256_buf ) - 1 ) ;
rc = syscall ( __NR_reboot , 0 , 0 , 0 , 0 ) ;
printf ( " reboot(0 /* LINUX_REBOOT_MAGIC_??? */, "
" 0 /* LINUX_REBOOT_MAGIC_??? */, "
" LINUX_REBOOT_CMD_CAD_OFF) = %s \n " ,
sprintrc ( rc ) ) ;
rc = syscall ( __NR_reboot , bogus_magic1 , bogus_magic2 , bogus_cmd , - 1 ) ;
printf ( " reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, "
" %#x /* LINUX_REBOOT_MAGIC_??? */, "
" %#x /* LINUX_REBOOT_CMD_??? */) = %s \n " ,
( unsigned int ) bogus_magic1 , ( unsigned int ) bogus_magic2 ,
( unsigned int ) bogus_cmd , sprintrc ( rc ) ) ;
rc = syscall ( __NR_reboot , LINUX_REBOOT_MAGIC1 ,
2017-06-18 01:23:09 +03:00
INVALID_MAGIC , LINUX_REBOOT_CMD_RESTART2 , buf ) ;
2016-04-26 11:03:07 +03:00
printf ( " reboot(LINUX_REBOOT_MAGIC1, %#x /* LINUX_REBOOT_MAGIC_??? */, "
2018-01-10 07:30:27 +03:00
" LINUX_REBOOT_CMD_RESTART2, \" %s \" ) = %s \n " ,
INVALID_MAGIC , buf , sprintrc ( rc ) ) ;
2016-04-26 11:03:07 +03:00
2017-06-18 01:23:09 +03:00
rc = syscall ( __NR_reboot , LINUX_REBOOT_MAGIC1 ,
LINUX_REBOOT_MAGIC2 , INVALID_CMD ) ;
2016-04-26 11:03:07 +03:00
printf ( " reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, "
2018-01-10 07:30:27 +03:00
" %#x /* LINUX_REBOOT_CMD_??? */) = %s \n " ,
INVALID_CMD , sprintrc ( rc ) ) ;
2016-04-26 11:03:07 +03:00
2018-01-10 07:31:15 +03:00
rc = syscall ( __NR_reboot , INVALID_MAGIC , LINUX_REBOOT_MAGIC2A ,
LINUX_REBOOT_CMD_RESTART2 , str256 ) ;
printf ( " reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, LINUX_REBOOT_MAGIC2A, "
" LINUX_REBOOT_CMD_RESTART2, \" %.255s \" ...) = %s \n " ,
INVALID_MAGIC , str256 , sprintrc ( rc ) ) ;
rc = syscall ( __NR_reboot , INVALID_MAGIC , LINUX_REBOOT_MAGIC2B ,
LINUX_REBOOT_CMD_RESTART2 , str256 + 1 ) ;
printf ( " reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, LINUX_REBOOT_MAGIC2B, "
" LINUX_REBOOT_CMD_RESTART2, \" %.255s \" ...) = %s \n " ,
INVALID_MAGIC , str256 + 1 , sprintrc ( rc ) ) ;
rc = syscall ( __NR_reboot , INVALID_MAGIC , LINUX_REBOOT_MAGIC2C ,
LINUX_REBOOT_CMD_RESTART2 , str256 + 2 ) ;
printf ( " reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, LINUX_REBOOT_MAGIC2C, "
" LINUX_REBOOT_CMD_RESTART2, %p) = %s \n " ,
INVALID_MAGIC , str256 + 2 , sprintrc ( rc ) ) ;
str256 [ 255 ] = ' \0 ' ;
rc = syscall ( __NR_reboot , INVALID_MAGIC , bogus_magic1 ,
LINUX_REBOOT_CMD_RESTART2 , str256 ) ;
printf ( " reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, "
" %#x /* LINUX_REBOOT_MAGIC_??? */, "
" LINUX_REBOOT_CMD_RESTART2, \" %.255s \" ...) = %s \n " ,
INVALID_MAGIC , ( unsigned int ) bogus_magic1 , str256 ,
sprintrc ( rc ) ) ;
rc = syscall ( __NR_reboot , INVALID_MAGIC , bogus_magic1 ,
LINUX_REBOOT_CMD_RESTART2 , str256 + 1 ) ;
printf ( " reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, "
" %#x /* LINUX_REBOOT_MAGIC_??? */, "
" LINUX_REBOOT_CMD_RESTART2, \" %.254s \" ) = %s \n " ,
INVALID_MAGIC , ( unsigned int ) bogus_magic1 , str256 + 1 ,
sprintrc ( rc ) ) ;
2016-04-26 11:03:07 +03:00
puts ( " +++ exited with 0 +++ " ) ;
return 0 ;
}
# else
SKIP_MAIN_UNDEFINED ( " __NR_reboot " )
# endif