]> git.saurik.com Git - apple/xnu.git/blob - tests/proc_info_udata.c
xnu-6153.81.5.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
7 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
8
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;
12 int ret;
13
14 udata = token;
15 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata));
16
17 #if CONFIG_EMBEDDED
18 T_WITH_ERRNO;
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 */
22
23 T_WITH_ERRNO;
24 T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_SET");
25
26 T_LOG("udata set to %#llx", udata);
27
28 bzero(&udata, sizeof(udata));
29 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata));
30 T_WITH_ERRNO;
31 T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_GET");
32
33 T_ASSERT_EQ_ULLONG(token, udata, "proc_udata_info(): retrieved value matches token");
34
35 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(uint32_t));
36 T_WITH_ERRNO;
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");
39
40 ret = proc_udata_info(getppid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata));
41 T_WITH_ERRNO;
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");
44
45 ret = proc_udata_info(getppid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata));
46 T_WITH_ERRNO;
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");
49 }