1 #include <darwintest.h>
2 #include <mach/host_priv.h>
4 #include <mach/mach_types.h>
5 #include <mach/processor_set.h>
7 #include <sys/sysctl.h>
9 #include <mach-o/dyld.h>
10 #include <mach-o/dyld_images.h>
11 #include <sys/types.h>
15 static void do_child(int *pipefd
){
19 read(pipefd
[0], &exit
, sizeof(int));
20 T_QUIET
; T_EXPECT_EQ_INT(exit
, 1, "exit");
24 T_DECL(task_info_28439149
, "ensure that task_info has the correct permission",
25 T_META_CHECK_LEAKS(false), T_META_ASROOT(true))
29 T_QUIET
; T_ASSERT_POSIX_SUCCESS(pipe(pipefd
), "pipe");
32 T_QUIET
; T_ASSERT_POSIX_SUCCESS(pid
, "fork");
42 mach_msg_type_number_t count
;
43 struct task_basic_info_64 ti
;
44 task_dyld_info_data_t di
;
46 task_t self
= mach_task_self();
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
);
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 ...)");
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");
76 write(pipefd
[1], &exit
, sizeof(int));