1 #ifndef MEMORYSTATUS_ASSERTION_HELPERS_H 2 #define MEMORYSTATUS_ASSERTION_HELPERS_H 3 4 #include <stdlib.h> 5 #include <stdint.h> 6 7 #define ASSERTION_STATE_IS_SET true 8 #define ASSERTION_STATE_IS_RELINQUISHED false 9 10 /* Helper functions for setting and checking memorystatus assertions 11 * on processes. 12 */ 13 14 /* 15 * Set the jetsam priority and user data for a process. 16 * 17 * If this request is assertion driven, the kernel will 18 * set the process's assertion priority. 19 * 20 * If this request is not assertion driven, the kernel 21 * will set the process's requested priority. 22 * 23 * The kernel will then apply policy and move the process 24 * to the appropriate jetsam priority. 25 * 26 * Returns: 0 on success 27 * non-0 on failure 28 */ 29 int 30 set_priority(pid_t pid, int32_t priority, uint64_t user_data, boolean_t is_assertion_driven); 31 32 /* 33 * Return: true on success 34 * false on failure --> this asserts a failure and quits test 35 */ 36 boolean_t 37 check_properties(pid_t pid, int32_t expected_priority, int32_t expected_limit_mb, uint64_t expected_user_data, boolean_t expected_assertion_state, const char *test); 38 39 /* 40 * Set the active and inactive memlimits for a process. 41 * Set the fatalness for each limit. 42 * 43 * Returns: 0 on success 44 * non-zero on failure 45 */ 46 int 47 set_memlimits( 48 pid_t pid, 49 int32_t active_limit_mb, int32_t inactive_limit_mb, 50 boolean_t active_is_fatal, boolean_t inactive_is_fatal); 51 52 /* 53 * Returns: 0 on success 54 * non-0 on failure 55 */ 56 int 57 set_assertion_priority(pid_t pid, int32_t priority, uint64_t user_data); 58 59 /* 60 * Returns: 0 on success 61 * non-0 on failure 62 */ 63 int 64 relinquish_assertion_priority(pid_t pid, uint64_t user_data); 65 66 /* 67 * Get the priority properties for a single process. 68 * 69 * This returns the process's effective jetsam priority, jetsam limit, 70 * user_data (not kernel related), and proc's kernel state. 71 * If this call fails, there is no reason to continue the test. 72 * 73 * Return: true on success 74 * false on failure --> this asserts fail and test quits 75 */ 76 boolean_t 77 get_priority_props(pid_t pid, boolean_t verbose, int32_t *priority, int32_t *limit_mb, uint64_t *user_data, uint32_t *state); 78 79 /* 80 * Input: 81 * state: kernel state bits from the get_priority_props() call 82 * expected_assertion_state: 83 * true if process should be holding an assertion state. 84 * false if no assertion state is held (eg: relinquished). 85 * 86 * Return true: verification passed 87 * false: verification failed 88 */ 89 boolean_t 90 verify_assertion_state(uint32_t state, boolean_t expected_assertion_state); 91 92 #endif /* MEMORYSTATUS_ASSERTION_HELPERS_H */ 93