]> git.saurik.com Git - apple/xnu.git/blob - tests/proc_info_udata.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / tests / proc_info_udata.c
1 #include <darwintest.h>
2 #include "../bsd/sys/proc_info.h"
3 #include "../libsyscall/wrappers/libproc/libproc.h"
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <TargetConditionals.h>
7
8 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
9
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;
13 int ret;
14
15 udata = token;
16 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata));
17
18 #if !TARGET_OS_OSX
19 T_WITH_ERRNO;
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");
22 #endif
23
24 T_WITH_ERRNO;
25 T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_SET");
26
27 T_LOG("udata set to %#llx", udata);
28
29 bzero(&udata, sizeof(udata));
30 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata));
31 T_WITH_ERRNO;
32 T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_GET");
33
34 T_ASSERT_EQ_ULLONG(token, udata, "proc_udata_info(): retrieved value matches token");
35
36 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(uint32_t));
37 T_WITH_ERRNO;
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");
40
41 ret = proc_udata_info(getppid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata));
42 T_WITH_ERRNO;
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");
45
46 ret = proc_udata_info(getppid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata));
47 T_WITH_ERRNO;
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");
50 }