]>
git.saurik.com Git - apple/xnu.git/blob - tests/proc_info_udata.c
1 #include <darwintest.h>
2 #include "../bsd/sys/proc_info.h"
3 #include "../libsyscall/wrappers/libproc/libproc.h"
7 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
9 T_DECL(proc_udata_info
, "Get and set a proc udata token"){
10 uint64_t token
= mach_absolute_time();
11 proc_info_udata_t udata
;
15 ret
= proc_udata_info(getpid(), PROC_UDATA_INFO_SET
, &udata
, sizeof(udata
));
19 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_SET returns error on non-macOS");
20 T_SKIP("Remaining tests are only supported on macOS");
21 #endif /* CONFIG_EMBEDDED */
24 T_ASSERT_EQ_INT(ret
, 0, "proc_udata_info PROC_UDATA_INFO_SET");
26 T_LOG("udata set to %#llx", udata
);
28 bzero(&udata
, sizeof(udata
));
29 ret
= proc_udata_info(getpid(), PROC_UDATA_INFO_GET
, &udata
, sizeof(udata
));
31 T_ASSERT_EQ_INT(ret
, 0, "proc_udata_info PROC_UDATA_INFO_GET");
33 T_ASSERT_EQ_ULLONG(token
, udata
, "proc_udata_info(): retrieved value matches token");
35 ret
= proc_udata_info(getpid(), PROC_UDATA_INFO_SET
, &udata
, sizeof(uint32_t));
37 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned -1");
38 T_ASSERT_EQ_INT(errno
, EINVAL
, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned EINVAL");
40 ret
= proc_udata_info(getppid(), PROC_UDATA_INFO_GET
, &udata
, sizeof(udata
));
42 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_GET returned -1 on attempt against non-self pid");
43 T_ASSERT_EQ_INT(errno
, EACCES
, "proc_udata_info PROC_UDATA_INFO_GET set errno to EACCES on attempt against non-self pid");
45 ret
= proc_udata_info(getppid(), PROC_UDATA_INFO_SET
, &udata
, sizeof(udata
));
47 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_SET returned -1 on attempt against non-self pid");
48 T_ASSERT_EQ_INT(errno
, EACCES
, "proc_udata_info PROC_UDATA_INFO_SET set errno to EACCES on attempt against non-self pid");