]>
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"
6 #include <TargetConditionals.h>
8 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
10 T_DECL(proc_udata_info
, "Get and set a proc udata token"){
11 uint64_t token
= mach_absolute_time();
12 proc_info_udata_t udata
;
16 ret
= proc_udata_info(getpid(), PROC_UDATA_INFO_SET
, &udata
, sizeof(udata
));
20 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_SET returns error on non-supported platforms");
21 T_SKIP("Remaining tests are only supported on platforms with CONFIG_PROC_UDATA_STORAGE configured");
25 T_ASSERT_EQ_INT(ret
, 0, "proc_udata_info PROC_UDATA_INFO_SET");
27 T_LOG("udata set to %#llx", udata
);
29 bzero(&udata
, sizeof(udata
));
30 ret
= proc_udata_info(getpid(), PROC_UDATA_INFO_GET
, &udata
, sizeof(udata
));
32 T_ASSERT_EQ_INT(ret
, 0, "proc_udata_info PROC_UDATA_INFO_GET");
34 T_ASSERT_EQ_ULLONG(token
, udata
, "proc_udata_info(): retrieved value matches token");
36 ret
= proc_udata_info(getpid(), PROC_UDATA_INFO_SET
, &udata
, sizeof(uint32_t));
38 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned -1");
39 T_ASSERT_EQ_INT(errno
, EINVAL
, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned EINVAL");
41 ret
= proc_udata_info(getppid(), PROC_UDATA_INFO_GET
, &udata
, sizeof(udata
));
43 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_GET returned -1 on attempt against non-self pid");
44 T_ASSERT_EQ_INT(errno
, EACCES
, "proc_udata_info PROC_UDATA_INFO_GET set errno to EACCES on attempt against non-self pid");
46 ret
= proc_udata_info(getppid(), PROC_UDATA_INFO_SET
, &udata
, sizeof(udata
));
48 T_ASSERT_EQ_INT(ret
, -1, "proc_udata_info PROC_UDATA_INFO_SET returned -1 on attempt against non-self pid");
49 T_ASSERT_EQ_INT(errno
, EACCES
, "proc_udata_info PROC_UDATA_INFO_SET set errno to EACCES on attempt against non-self pid");