1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #include <stdbool.h> 3 #include <stdlib.h> 4 5 #include "../kselftest.h" 6 7 #define PAGE_SIZE 4096 8 9 #define MB(x) (x << 20) 10 11 #define USEC_PER_SEC 1000000L 12 #define NSEC_PER_SEC 1000000000L 13 14 #define TEST_UID 65534 /* usually nobody, any !root is fine */ 15 16 /* 17 * Checks if two given values differ by less than err% of their sum. 18 */ 19 static inline int values_close(long a, long b, int err) 20 { 21 return abs(a - b) <= (a + b) / 100 * err; 22 } 23 24 extern int cg_find_unified_root(char *root, size_t len, bool *nsdelegate); 25 extern char *cg_name(const char *root, const char *name); 26 extern char *cg_name_indexed(const char *root, const char *name, int index); 27 extern char *cg_control(const char *cgroup, const char *control); 28 extern int cg_create(const char *cgroup); 29 extern int cg_destroy(const char *cgroup); 30 extern int cg_read(const char *cgroup, const char *control, 31 char *buf, size_t len); 32 extern int cg_read_strcmp(const char *cgroup, const char *control, 33 const char *expected); 34 extern int cg_read_strstr(const char *cgroup, const char *control, 35 const char *needle); 36 extern long cg_read_long(const char *cgroup, const char *control); 37 long cg_read_key_long(const char *cgroup, const char *control, const char *key); 38 extern long cg_read_lc(const char *cgroup, const char *control); 39 extern int cg_write(const char *cgroup, const char *control, char *buf); 40 int cg_write_numeric(const char *cgroup, const char *control, long value); 41 extern int cg_run(const char *cgroup, 42 int (*fn)(const char *cgroup, void *arg), 43 void *arg); 44 extern int cg_enter(const char *cgroup, int pid); 45 extern int cg_enter_current(const char *cgroup); 46 extern int cg_enter_current_thread(const char *cgroup); 47 extern int cg_run_nowait(const char *cgroup, 48 int (*fn)(const char *cgroup, void *arg), 49 void *arg); 50 extern int get_temp_fd(void); 51 extern int alloc_pagecache(int fd, size_t size); 52 extern int alloc_anon(const char *cgroup, void *arg); 53 extern int is_swap_enabled(void); 54 extern int set_oom_adj_score(int pid, int score); 55 extern int cg_wait_for_proc_count(const char *cgroup, int count); 56 extern int cg_killall(const char *cgroup); 57 int proc_mount_contains(const char *option); 58 extern ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size); 59 extern int proc_read_strstr(int pid, bool thread, const char *item, const char *needle); 60 extern pid_t clone_into_cgroup(int cgroup_fd); 61 extern int clone_reap(pid_t pid, int options); 62 extern int clone_into_cgroup_run_wait(const char *cgroup); 63 extern int dirfd_open_opath(const char *dir); 64 extern int cg_prepare_for_wait(const char *cgroup); 65 extern int memcg_prepare_for_wait(const char *cgroup); 66 extern int cg_wait_for(int fd); 67