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