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