1 #include "tests.h"
2 #include <asm/unistd.h>
3 
4 #ifdef __NR_reboot
5 
6 # include <stdio.h>
7 # include <linux/reboot.h>
8 # include <unistd.h>
9 
10 # define INVALID_MAGIC 319887762
11 # define INVALID_CMD 0x01234568
12 
13 # define STR32 "AbCdEfGhIjKlMnOpQrStUvWxYz012345"
14 # define STR128 STR32 STR32 STR32 STR32
15 
16 int
main(void)17 main(void)
18 {
19 	static const kernel_ulong_t bogus_magic1 =
20 		(kernel_ulong_t) 0xFFFFFFFFFFFFFFFFULL;
21 	static const kernel_ulong_t bogus_magic2 =
22 		(kernel_ulong_t) 0xdeadfacefa57beefULL;
23 	static const kernel_ulong_t bogus_cmd =
24 		(kernel_ulong_t) 0xbadda7a09caffee1ULL;
25 	static const char buf[] = "reboot";
26 	static const char str256_buf[] = STR128 STR128;
27 
28 	long rc;
29 	char *str256 = tail_memdup(str256_buf, sizeof(str256_buf) - 1);
30 
31 	rc = syscall(__NR_reboot, 0, 0, 0, 0);
32 	printf("reboot(0 /* LINUX_REBOOT_MAGIC_??? */, "
33 	       "0 /* LINUX_REBOOT_MAGIC_??? */, "
34 	       "LINUX_REBOOT_CMD_CAD_OFF) = %s\n",
35 	       sprintrc(rc));
36 
37 	rc = syscall(__NR_reboot, bogus_magic1, bogus_magic2, bogus_cmd, -1);
38 	printf("reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, "
39 	       "%#x /* LINUX_REBOOT_MAGIC_??? */, "
40 	       "%#x /* LINUX_REBOOT_CMD_??? */) = %s\n",
41 	       (unsigned int) bogus_magic1, (unsigned int) bogus_magic2,
42 	       (unsigned int) bogus_cmd, sprintrc(rc));
43 
44 	rc = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1,
45 			  INVALID_MAGIC, LINUX_REBOOT_CMD_RESTART2, buf);
46 	printf("reboot(LINUX_REBOOT_MAGIC1, %#x /* LINUX_REBOOT_MAGIC_??? */,"
47 	       " LINUX_REBOOT_CMD_RESTART2, \"%s\") = %s\n",
48 	       INVALID_MAGIC, buf, sprintrc(rc));
49 
50 	rc = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1,
51 		     LINUX_REBOOT_MAGIC2, INVALID_CMD);
52 	printf("reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,"
53 	       " %#x /* LINUX_REBOOT_CMD_??? */) = %s\n",
54 	       INVALID_CMD, sprintrc(rc));
55 
56 	rc = syscall(__NR_reboot, INVALID_MAGIC, LINUX_REBOOT_MAGIC2A,
57 			  LINUX_REBOOT_CMD_RESTART2, str256);
58 	printf("reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, LINUX_REBOOT_MAGIC2A, "
59 	       "LINUX_REBOOT_CMD_RESTART2, \"%.255s\"...) = %s\n",
60 	       INVALID_MAGIC, str256, sprintrc(rc));
61 
62 	rc = syscall(__NR_reboot, INVALID_MAGIC, LINUX_REBOOT_MAGIC2B,
63 			  LINUX_REBOOT_CMD_RESTART2, str256 + 1);
64 	printf("reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, LINUX_REBOOT_MAGIC2B, "
65 	       "LINUX_REBOOT_CMD_RESTART2, \"%.255s\"...) = %s\n",
66 	       INVALID_MAGIC, str256 + 1, sprintrc(rc));
67 
68 	rc = syscall(__NR_reboot, INVALID_MAGIC, LINUX_REBOOT_MAGIC2C,
69 			  LINUX_REBOOT_CMD_RESTART2, str256 + 2);
70 	printf("reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, LINUX_REBOOT_MAGIC2C, "
71 	       "LINUX_REBOOT_CMD_RESTART2, %p) = %s\n",
72 	       INVALID_MAGIC, str256 + 2, sprintrc(rc));
73 
74 	str256[255] = '\0';
75 	rc = syscall(__NR_reboot, INVALID_MAGIC, bogus_magic1,
76 			  LINUX_REBOOT_CMD_RESTART2, str256);
77 	printf("reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, "
78 	       "%#x /* LINUX_REBOOT_MAGIC_??? */, "
79 	       "LINUX_REBOOT_CMD_RESTART2, \"%.255s\"...) = %s\n",
80 	       INVALID_MAGIC, (unsigned int) bogus_magic1, str256,
81 	       sprintrc(rc));
82 
83 	rc = syscall(__NR_reboot, INVALID_MAGIC, bogus_magic1,
84 			  LINUX_REBOOT_CMD_RESTART2, str256 + 1);
85 	printf("reboot(%#x /* LINUX_REBOOT_MAGIC_??? */, "
86 	       "%#x /* LINUX_REBOOT_MAGIC_??? */, "
87 	       "LINUX_REBOOT_CMD_RESTART2, \"%.254s\") = %s\n",
88 	       INVALID_MAGIC, (unsigned int) bogus_magic1, str256 + 1,
89 	       sprintrc(rc));
90 
91 	puts("+++ exited with 0 +++");
92 	return 0;
93 }
94 
95 #else
96 
97 SKIP_MAIN_UNDEFINED("__NR_reboot")
98 
99 #endif
100