]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
316670eb | 2 | * Copyright (c) 2010 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
91447636 | 31 | |
1c79356b A |
32 | #ifndef _KERN_LEDGER_H_ |
33 | #define _KERN_LEDGER_H_ | |
34 | ||
316670eb A |
35 | #define LEDGER_INFO 0 |
36 | #define LEDGER_ENTRY_INFO 1 | |
37 | #define LEDGER_TEMPLATE_INFO 2 | |
38 | #define LEDGER_LIMIT 3 | |
9bccf70c | 39 | |
316670eb | 40 | #define LEDGER_NAME_MAX 32 |
1c79356b | 41 | |
316670eb A |
42 | struct ledger_info { |
43 | char li_name[LEDGER_NAME_MAX]; | |
44 | int64_t li_id; | |
45 | int64_t li_entries; | |
1c79356b A |
46 | }; |
47 | ||
316670eb A |
48 | struct ledger_template_info { |
49 | char lti_name[LEDGER_NAME_MAX]; | |
50 | char lti_group[LEDGER_NAME_MAX]; | |
51 | char lti_units[LEDGER_NAME_MAX]; | |
52 | }; | |
1c79356b | 53 | |
316670eb A |
54 | struct ledger_entry_info { |
55 | int64_t lei_balance; | |
56 | int64_t lei_credit; | |
57 | int64_t lei_debit; | |
58 | uint64_t lei_limit; | |
59 | uint64_t lei_refill_period; /* In milliseconds */ | |
60 | uint64_t lei_last_refill; /* Time since last refill */ | |
61 | }; | |
9bccf70c | 62 | |
316670eb A |
63 | struct ledger_limit_args { |
64 | char lla_name[LEDGER_NAME_MAX]; | |
65 | uint64_t lla_limit; | |
66 | uint64_t lla_refill_period; | |
67 | }; | |
9bccf70c | 68 | |
316670eb A |
69 | #ifdef KERNEL_PRIVATE |
70 | ||
71 | typedef struct ledger_template *ledger_template_t; | |
72 | ||
73 | #define LEDGER_VALID(ledger) (ledger != LEDGER_NULL) | |
74 | ||
75 | /* Action to take when a ledger goes into deficit */ | |
76 | #define LEDGER_ACTION_IGNORE 0x0000 | |
77 | #define LEDGER_ACTION_BLOCK 0x0010 | |
39236c6e | 78 | #define LEDGER_ACTION_CALLBACK 0x0020 |
316670eb A |
79 | #define LEDGER_ACTION_MASK 0x00f0 |
80 | ||
39236c6e A |
81 | /* |
82 | * Types of warnings that trigger a callback. | |
83 | */ | |
84 | #define LEDGER_WARNING_ROSE_ABOVE 1 | |
85 | #define LEDGER_WARNING_DIPPED_BELOW 2 | |
86 | ||
87 | typedef void (*ledger_callback_t)(int warning, const void * param0, const void *param1); | |
316670eb A |
88 | |
89 | extern void ledger_init(void); | |
90 | ||
91 | extern ledger_template_t ledger_template_create(const char *name); | |
92 | extern void ledger_template_dereference(ledger_template_t template); | |
93 | extern int ledger_entry_add(ledger_template_t template, const char *key, | |
94 | const char *group, const char *units); | |
95 | extern kern_return_t ledger_set_callback(ledger_template_t template, int entry, | |
96 | ledger_callback_t callback, const void *param0, const void *param1); | |
39236c6e A |
97 | extern kern_return_t ledger_track_maximum(ledger_template_t template, int entry, |
98 | int period_in_secs); | |
316670eb A |
99 | extern int ledger_key_lookup(ledger_template_t template, const char *key); |
100 | ||
101 | /* value of entry type */ | |
102 | #define LEDGER_CREATE_ACTIVE_ENTRIES 0 | |
103 | #define LEDGER_CREATE_INACTIVE_ENTRIES 1 | |
104 | extern ledger_t ledger_instantiate(ledger_template_t template, int entry_type); | |
105 | extern kern_return_t ledger_disable_callback(ledger_t ledger, int entry); | |
39236c6e A |
106 | extern kern_return_t ledger_enable_callback(ledger_t ledger, int entry); |
107 | extern kern_return_t ledger_get_limit(ledger_t ledger, int entry, | |
108 | ledger_amount_t *limit); | |
316670eb | 109 | extern kern_return_t ledger_set_limit(ledger_t ledger, int entry, |
39236c6e A |
110 | ledger_amount_t limit, uint8_t warn_level_percentage); |
111 | extern kern_return_t ledger_get_maximum(ledger_t ledger, int entry, | |
112 | ledger_amount_t *max_observed_balance); | |
113 | extern kern_return_t ledger_get_actions(ledger_t ledger, int entry, int *actions); | |
316670eb | 114 | extern kern_return_t ledger_set_action(ledger_t ledger, int entry, int action); |
39236c6e A |
115 | extern kern_return_t ledger_get_period(ledger_t ledger, int entry, |
116 | uint64_t *period); | |
316670eb A |
117 | extern kern_return_t ledger_set_period(ledger_t ledger, int entry, |
118 | uint64_t period); | |
39236c6e | 119 | extern kern_return_t ledger_disable_refill(ledger_t l, int entry); |
316670eb A |
120 | extern kern_return_t ledger_entry_setactive(ledger_t ledger, int entry); |
121 | extern kern_return_t ledger_credit(ledger_t ledger, int entry, | |
122 | ledger_amount_t amount); | |
123 | extern kern_return_t ledger_debit(ledger_t ledger, int entry, | |
124 | ledger_amount_t amount); | |
39236c6e | 125 | extern kern_return_t ledger_zero_balance(ledger_t ledger, int entry); |
316670eb A |
126 | extern kern_return_t ledger_get_entries(ledger_t ledger, int entry, |
127 | ledger_amount_t *credit, ledger_amount_t *debit); | |
39236c6e A |
128 | extern kern_return_t ledger_get_balance(ledger_t ledger, int entry, |
129 | ledger_amount_t *balance); | |
316670eb A |
130 | |
131 | extern void ledger_ast(thread_t thread); | |
132 | extern void set_astledger(thread_t thread); | |
133 | ||
134 | extern int ledger_reference_count(ledger_t ledger); | |
135 | extern kern_return_t ledger_reference(ledger_t ledger); | |
136 | extern kern_return_t ledger_dereference(ledger_t ledger); | |
137 | ||
138 | /* Per-pmap ledger operations */ | |
139 | #define pmap_ledger_debit(p, e, a) ledger_debit((p)->ledger, e, a) | |
140 | #define pmap_ledger_credit(p, e, a) ledger_credit((p)->ledger, e, a) | |
141 | ||
142 | /* Support for ledger() syscall */ | |
143 | #ifdef LEDGER_DEBUG | |
144 | extern int ledger_limit(task_t task, struct ledger_limit_args *args); | |
145 | #endif | |
146 | extern int ledger_info(task_t task, struct ledger_info *info); | |
39236c6e A |
147 | |
148 | extern int | |
149 | ledger_get_task_entry_info_multiple(task_t task, void **buf, int *len); | |
150 | ||
151 | extern void | |
152 | ledger_get_entry_info(ledger_t ledger, int entry, | |
153 | struct ledger_entry_info *lei); | |
154 | ||
316670eb A |
155 | extern int ledger_template_info(void **buf, int *len); |
156 | ||
157 | #endif /* KERNEL_PRIVATE */ | |
1c79356b A |
158 | |
159 | #endif /* _KERN_LEDGER_H_ */ |