]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/darwintests/task_info_28439149.c
xnu-4570.1.46.tar.gz
[apple/xnu.git] / tools / tests / darwintests / task_info_28439149.c
1 #include <darwintest.h>
2 #include <mach/host_priv.h>
3 #include <mach/mach.h>
4 #include <mach/mach_types.h>
5 #include <mach/processor_set.h>
6 #include <mach/task.h>
7 #include <sys/sysctl.h>
8 #include <unistd.h>
9 #include <mach-o/dyld.h>
10 #include <mach-o/dyld_images.h>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13 #include <stdlib.h>
14
15 static void do_child(int *pipefd){
16 int exit = 0;
17
18 close(pipefd[1]);
19 read(pipefd[0], &exit, sizeof(int));
20 T_QUIET; T_EXPECT_EQ_INT(exit, 1, "exit");
21 close(pipefd[0]);
22 }
23
24 T_DECL(task_info_28439149, "ensure that task_info has the correct permission",
25 T_META_CHECK_LEAKS(false), T_META_ASROOT(true))
26 {
27 int pipefd[2];
28
29 T_QUIET; T_ASSERT_POSIX_SUCCESS(pipe(pipefd), "pipe");
30
31 int pid = fork();
32 T_QUIET; T_ASSERT_POSIX_SUCCESS(pid, "fork");
33
34 if (pid == 0) {
35 do_child(pipefd);
36 return;
37 }
38
39 close(pipefd[0]);
40
41 int exit;
42 mach_msg_type_number_t count;
43 struct task_basic_info_64 ti;
44 task_dyld_info_data_t di;
45
46 task_t self = mach_task_self();
47 task_t other_name;
48 task_t other;
49 int ret;
50
51 T_EXPECT_MACH_SUCCESS(task_for_pid(self, pid, &other), NULL);
52 T_EXPECT_MACH_SUCCESS(task_name_for_pid(self, pid, &other_name), NULL);
53
54 count = TASK_BASIC_INFO_64_COUNT;
55 T_EXPECT_MACH_SUCCESS(task_info(self, TASK_BASIC_INFO_64, (task_info_t)&ti,
56 &count), "task_info(self, TASK_BASIC_INFO_64 ...)");
57 count = TASK_BASIC_INFO_64_COUNT;
58 T_EXPECT_MACH_SUCCESS(task_info(other, TASK_BASIC_INFO_64, (task_info_t)&ti,
59 &count), "task_info(other_name, TASK_BASIC_INFO_64 ...)");
60 count = TASK_BASIC_INFO_64_COUNT;
61 T_EXPECT_MACH_SUCCESS(task_info(other_name, TASK_BASIC_INFO_64, (task_info_t)&ti,
62 &count), "task_info(other_name, TASK_BASIC_INFO_64 ...)");
63
64
65 count = TASK_DYLD_INFO_COUNT;
66 T_EXPECT_MACH_SUCCESS(task_info(self, TASK_DYLD_INFO, (task_info_t)&di,
67 &count), "task_info(self, TASK_DYLD_INFO ...)");
68 count = TASK_DYLD_INFO_COUNT;
69 T_EXPECT_MACH_SUCCESS(task_info(other, TASK_DYLD_INFO, (task_info_t)&di,
70 &count), "task_info(other_name, TASK_DYLD_INFO ...)");
71 count = TASK_DYLD_INFO_COUNT;
72 ret = task_info(other_name, TASK_DYLD_INFO, (task_info_t)&di, &count);
73 T_EXPECT_EQ_INT(ret, KERN_INVALID_ARGUMENT, "task info TASK_DYLD_INFO should fail with mach_port_name");
74
75 exit = 1;
76 write(pipefd[1], &exit, sizeof(int));
77 close(pipefd[1]);
78
79 wait(NULL);
80 }
81