]>
Commit | Line | Data |
---|---|---|
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_DECL(proc_udata_info, "Get and set a proc udata token"){ | |
8 | uint64_t token = mach_absolute_time(); | |
9 | proc_info_udata_t udata; | |
10 | int ret; | |
11 | ||
12 | udata = token; | |
13 | ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof (udata)); | |
14 | ||
15 | #if CONFIG_EMBEDDED | |
16 | T_WITH_ERRNO; | |
17 | T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_SET returns error on non-macOS"); | |
18 | T_SKIP("Remaining tests are only supported on macOS"); | |
19 | #endif /* CONFIG_EMBEDDED */ | |
20 | ||
21 | T_WITH_ERRNO; | |
22 | T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_SET"); | |
23 | ||
24 | T_LOG("udata set to %#llx", udata); | |
25 | ||
26 | bzero(&udata, sizeof (udata)); | |
27 | ret = proc_udata_info(getpid(), PROC_UDATA_INFO_GET, &udata, sizeof (udata)); | |
28 | T_WITH_ERRNO; | |
29 | T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_GET"); | |
30 | ||
31 | T_ASSERT_EQ_ULLONG(token, udata, "proc_udata_info(): retrieved value matches token"); | |
32 | ||
33 | ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof (uint32_t)); | |
34 | T_WITH_ERRNO; | |
35 | T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned -1"); | |
36 | T_ASSERT_EQ_INT(errno, EINVAL, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned EINVAL"); | |
37 | ||
38 | ret = proc_udata_info(getppid(), PROC_UDATA_INFO_GET, &udata, sizeof (udata)); | |
39 | T_WITH_ERRNO; | |
40 | T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_GET returned -1 on attempt against non-self pid"); | |
41 | T_ASSERT_EQ_INT(errno, EACCES, "proc_udata_info PROC_UDATA_INFO_GET set errno to EACCES on attempt against non-self pid"); | |
42 | ||
43 | ret = proc_udata_info(getppid(), PROC_UDATA_INFO_SET, &udata, sizeof (udata)); | |
44 | T_WITH_ERRNO; | |
45 | T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_SET returned -1 on attempt against non-self pid"); | |
46 | T_ASSERT_EQ_INT(errno, EACCES, "proc_udata_info PROC_UDATA_INFO_SET set errno to EACCES on attempt against non-self pid"); | |
47 | } |