]> git.saurik.com Git - apple/xnu.git/blame - tests/proc_info_udata.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / proc_info_udata.c
CommitLineData
a39ff7e2 1#include <darwintest.h>
d9a64523
A
2#include "../bsd/sys/proc_info.h"
3#include "../libsyscall/wrappers/libproc/libproc.h"
a39ff7e2
A
4#include <stdio.h>
5#include <unistd.h>
f427ee49 6#include <TargetConditionals.h>
a39ff7e2 7
cb323159
A
8T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
9
a39ff7e2
A
10T_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;
d9a64523 14
a39ff7e2 15 udata = token;
0a7de745 16 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata));
a39ff7e2 17
f427ee49 18#if !TARGET_OS_OSX
a39ff7e2 19 T_WITH_ERRNO;
f427ee49
A
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
a39ff7e2
A
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
0a7de745
A
29 bzero(&udata, sizeof(udata));
30 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata));
a39ff7e2
A
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
0a7de745 36 ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(uint32_t));
a39ff7e2
A
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
0a7de745 41 ret = proc_udata_info(getppid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata));
a39ff7e2
A
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
0a7de745 46 ret = proc_udata_info(getppid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata));
a39ff7e2
A
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}