Lines Matching refs:ledger
35 * ledger facility to satisfy the ledger interfaces.
52 #include <kern/ledger.h>
62 /* Utility routine to handle entries to a ledger */
65 ledger_t ledger,
68 /* Need to lock the ledger */
69 ledger_lock(ledger);
72 if (ledger->ledger_limit != LEDGER_ITEM_INFINITY &&
73 ledger->ledger_balance + amount > ledger->ledger_limit) {
75 printf("Ledger limit exceeded ! ledger=%p lim=%d balance=%d\n",
76 ledger, ledger->ledger_limit,
77 ledger->ledger_balance);
78 ledger_unlock(ledger);
81 if ((ledger->ledger_balance + amount)
83 ledger->ledger_balance += amount;
85 ledger->ledger_balance = LEDGER_ITEM_INFINITY;
88 if (ledger->ledger_balance + amount > 0)
89 ledger->ledger_balance += amount;
91 ledger->ledger_balance = 0;
93 ledger_unlock(ledger);
97 /* Utility routine to create a new ledger */
104 ledger_t ledger;
106 ledger = (ledger_t)kalloc(sizeof(ledger_data_t));
107 if (ledger == LEDGER_NULL)
110 ledger->ledger_self = ipc_port_alloc_kernel();
111 if (ledger->ledger_self == IP_NULL) {
112 kfree(ledger, sizeof(ledger_data_t));
116 ledger_lock_init(ledger);
117 ledger->ledger_limit = limit;
118 ledger->ledger_balance = 0;
119 ledger->ledger_service_port = MACH_PORT_NULL;
120 ledger->ledger_ledger = ledger_ledger;
121 ledger->ledger_parent = ledger_parent;
122 ipc_kobject_set(ledger->ledger_self, (ipc_kobject_t)ledger,
125 return(ledger);
128 /* Utility routine to destroy a ledger */
131 ledger_t ledger)
134 ipc_port_dealloc_kernel(ledger->ledger_self);
137 kfree(ledger, sizeof(*ledger));
142 * Inititalize the ledger facility
152 panic("can't allocate root (wired) ledger");
158 panic("can't allocate root (paged) ledger");
163 * Create a subordinate ledger
178 * Allocate a new ledger and change the ledger_ledger for
196 * Now transfer the limit for the new ledger from the parent
213 /* Charge the ledger against the ledger_ledger */
223 * Destroy a ledger
226 ledger_t ledger)
228 if (ledger == LEDGER_NULL)
232 if (ledger == root_wired_ledger ||
233 ledger == root_paged_ledger)
236 /* Lock the ledger */
237 ledger_lock(ledger);
239 /* the parent ledger gets back the limit */
240 ledger_lock(ledger->ledger_parent);
241 if (ledger->ledger_parent->ledger_limit != LEDGER_ITEM_INFINITY) {
242 assert((natural_t)(ledger->ledger_parent->ledger_limit +
243 ledger->ledger_limit) <
245 ledger->ledger_parent->ledger_limit += ledger->ledger_limit;
247 ledger_unlock(ledger->ledger_parent);
251 * have been created with this ledger. Nice work eh? For now
255 /* XXX the parent ledger inherits the debt ?? */
256 (void) ledger_enter(ledger->ledger_parent, ledger->ledger_balance);
258 /* adjust the balance of the creation ledger */
259 (void) ledger_enter(ledger->ledger_ledger, -sizeof(*ledger));
261 /* delete the ledger */
262 ledger_deallocate(ledger);
268 * Return the ledger limit and balance
271 ledger_t ledger,
275 if (ledger == LEDGER_NULL)
278 ledger_lock(ledger);
279 *balance = ledger->ledger_balance;
280 *limit = ledger->ledger_limit;
281 ledger_unlock(ledger);
287 * Transfer resources from a parent ledger to a child
362 * Convert from a port to a ledger.
363 * Doesn't consume the port ref; the ledger produced may be null.
372 ledger_t ledger = LEDGER_NULL;
378 ledger = (ledger_t) port->ip_kobject;
382 return ledger;
388 * Convert from a ledger to a port.
396 ledger_t ledger)
400 port = ipc_port_make_send(ledger->ledger_self);
406 * Copy a ledger
410 ledger_t ledger)
413 assert(ledger);
414 return(ipc_port_copy_send(ledger->ledger_self));