static bank_task_t bank_task_alloc_init(task_t task);
static bank_account_t bank_account_alloc_init(bank_task_t bank_holder, bank_task_t bank_merchant,
- bank_task_t bank_secureoriginator, bank_task_t bank_proximateprocess, struct thread_group* banktg);
+ bank_task_t bank_secureoriginator, bank_task_t bank_proximateprocess, struct thread_group* banktg);
static bank_task_t get_bank_task_context(task_t task, boolean_t initialize);
static void bank_task_dealloc(bank_task_t bank_task, mach_voucher_attr_value_reference_t sync);
static kern_return_t bank_account_dealloc_with_sync(bank_account_t bank_account, mach_voucher_attr_value_reference_t sync);
static void bank_rollup_chit_to_tasks(ledger_t bill, ledger_t bank_holder_ledger, ledger_t bank_merchant_ledger,
- int bank_holder_pid, int bank_merchant_pid);
+ int bank_holder_pid, int bank_merchant_pid);
static ledger_t bank_get_bank_task_ledger_with_ref(bank_task_t bank_task);
static void bank_destroy_bank_task_ledger(bank_task_t bank_task);
static void init_bank_ledgers(void);
lck_spin_init(&g_bank_task_lock_data, &bank_lock_grp, &bank_lock_attr)
#define global_bank_task_lock_destroy() \
lck_spin_destroy(&g_bank_task_lock_data, &bank_lock_grp)
-#define global_bank_task_lock() \
- lck_spin_lock(&g_bank_task_lock_data)
-#define global_bank_task_lock_try() \
- lck_spin_try_lock(&g_bank_task_lock_data)
-#define global_bank_task_unlock() \
+#define global_bank_task_lock() \
+ lck_spin_lock_grp(&g_bank_task_lock_data, &bank_lock_grp)
+#define global_bank_task_lock_try() \
+ lck_spin_try_lock_grp(&g_bank_task_lock_data, &bank_lock_grp)
+#define global_bank_task_unlock() \
lck_spin_unlock(&g_bank_task_lock_data)
extern uint64_t proc_uniqueid(void *p);
.ivam_release_value = bank_release_value,
.ivam_get_value = bank_get_value,
.ivam_extract_content = bank_extract_content,
- .ivam_command = bank_command,
+ .ivam_command = bank_command,
.ivam_release = bank_release,
.ivam_flags = (IVAM_FLAGS_SUPPORT_SEND_PREPROCESS | IVAM_FLAGS_SUPPORT_RECEIVE_POSTPROCESS),
};
decl_lck_mtx_data(, bank_tasks_list_lock);
decl_lck_mtx_data(, bank_accounts_list_lock);
-lck_grp_t bank_dev_lock_grp;
-lck_attr_t bank_dev_lock_attr;
-lck_grp_attr_t bank_dev_lock_grp_attr;
+lck_grp_t bank_dev_lock_grp;
+lck_attr_t bank_dev_lock_attr;
+lck_grp_attr_t bank_dev_lock_grp_attr;
#endif
/*
* Lock group attributes for bank sub system.
*/
-lck_grp_t bank_lock_grp;
-lck_attr_t bank_lock_attr;
-lck_grp_attr_t bank_lock_grp_attr;
+lck_grp_t bank_lock_grp;
+lck_attr_t bank_lock_attr;
+lck_grp_attr_t bank_lock_grp_attr;
/*
* Routine: bank_init
kern_return_t kr = KERN_SUCCESS;
/* setup zones for bank_task and bank_account objects */
bank_task_zone = zinit(sizeof(struct bank_task),
- MAX_BANK_TASK * sizeof(struct bank_task),
- sizeof(struct bank_task),
- "bank_task");
+ MAX_BANK_TASK * sizeof(struct bank_task),
+ sizeof(struct bank_task),
+ "bank_task");
bank_account_zone = zinit(sizeof(struct bank_account),
- MAX_BANK_ACCOUNT * sizeof(struct bank_account),
- sizeof(struct bank_account),
- "bank_account");
+ MAX_BANK_ACCOUNT * sizeof(struct bank_account),
+ sizeof(struct bank_account),
+ "bank_account");
init_bank_ledgers();
/* Register the bank manager with the Vouchers sub system. */
kr = ipc_register_well_known_mach_voucher_attr_manager(
- &bank_manager,
- 0,
- MACH_VOUCHER_ATTR_KEY_BANK,
- &bank_voucher_attr_control);
- if (kr != KERN_SUCCESS )
+ &bank_manager,
+ 0,
+ MACH_VOUCHER_ATTR_KEY_BANK,
+ &bank_voucher_attr_control);
+ if (kr != KERN_SUCCESS) {
panic("BANK subsystem initialization failed");
+ }
kprintf("BANK subsystem is initialized\n");
- return ;
+ return;
}
*/
kern_return_t
bank_release_value(
- ipc_voucher_attr_manager_t __assert_only manager,
- mach_voucher_attr_key_t __assert_only key,
- mach_voucher_attr_value_handle_t value,
- mach_voucher_attr_value_reference_t sync)
+ ipc_voucher_attr_manager_t __assert_only manager,
+ mach_voucher_attr_key_t __assert_only key,
+ mach_voucher_attr_value_handle_t value,
+ mach_voucher_attr_value_reference_t sync)
{
bank_task_t bank_task = BANK_TASK_NULL;
bank_element_t bank_element = BANK_ELEMENT_NULL;
*/
kern_return_t
bank_get_value(
- ipc_voucher_attr_manager_t __assert_only manager,
- mach_voucher_attr_key_t __assert_only key,
- mach_voucher_attr_recipe_command_t command,
- mach_voucher_attr_value_handle_array_t prev_values,
- mach_msg_type_number_t prev_value_count,
+ ipc_voucher_attr_manager_t __assert_only manager,
+ mach_voucher_attr_key_t __assert_only key,
+ mach_voucher_attr_recipe_command_t command,
+ mach_voucher_attr_value_handle_array_t prev_values,
+ mach_msg_type_number_t prev_value_count,
mach_voucher_attr_content_t __unused recipe,
mach_voucher_attr_content_size_t __unused recipe_size,
mach_voucher_attr_value_handle_t *out_value,
mach_voucher_attr_value_flags_t *out_flags,
- ipc_voucher_t *out_value_voucher)
+ ipc_voucher_t *out_value_voucher)
{
bank_task_t bank_task = BANK_TASK_NULL;
bank_task_t bank_holder = BANK_TASK_NULL;
*out_flags = MACH_VOUCHER_ATTR_VALUE_FLAGS_NONE;
switch (command) {
-
case MACH_VOUCHER_ATTR_BANK_CREATE:
/* Return the default task value instead of bank task */
bank_element = HANDLE_TO_BANK_ELEMENT(bank_handle);
/* Should not have received default task value from an IPC */
- if (bank_element == BANK_DEFAULT_VALUE || bank_element == BANK_DEFAULT_TASK_VALUE)
+ if (bank_element == BANK_DEFAULT_VALUE || bank_element == BANK_DEFAULT_TASK_VALUE) {
continue;
+ }
task = current_task();
if (bank_element->be_type == BANK_TASK) {
bank_secureoriginator = old_bank_account->ba_secureoriginator;
bank_proximateprocess = old_bank_account->ba_proximateprocess;
thread_group = bank_get_bank_account_thread_group(old_bank_account);
-
} else {
panic("Bogus bank type: %d passed in get_value\n", bank_element->be_type);
}
bank_merchant = get_bank_task_context(task, FALSE);
- if (bank_merchant == BANK_TASK_NULL)
+ if (bank_merchant == BANK_TASK_NULL) {
return KERN_RESOURCE_SHORTAGE;
+ }
cur_thread_group = bank_get_bank_task_thread_group(bank_merchant);
}
/* Check if trying to redeem for self task, return the default bank task */
- if (bank_holder == bank_merchant &&
- bank_holder == bank_secureoriginator &&
- bank_holder == bank_proximateprocess &&
- thread_group == cur_thread_group) {
+ if (bank_holder == bank_merchant &&
+ bank_holder == bank_secureoriginator &&
+ bank_holder == bank_proximateprocess &&
+ thread_group == cur_thread_group) {
*out_value = BANK_ELEMENT_TO_HANDLE(BANK_DEFAULT_TASK_VALUE);
*out_flags = MACH_VOUCHER_ATTR_VALUE_FLAGS_PERSIST;
return kr;
}
bank_account = bank_account_alloc_init(bank_holder, bank_merchant,
- bank_secureoriginator, bank_proximateprocess,
- thread_group);
- if (bank_account == BANK_ACCOUNT_NULL)
+ bank_secureoriginator, bank_proximateprocess,
+ thread_group);
+ if (bank_account == BANK_ACCOUNT_NULL) {
return KERN_RESOURCE_SHORTAGE;
+ }
*out_value = BANK_ELEMENT_TO_HANDLE(bank_account);
return kr;
bank_handle = prev_values[i];
bank_element = HANDLE_TO_BANK_ELEMENT(bank_handle);
- if (bank_element == BANK_DEFAULT_VALUE)
+ if (bank_element == BANK_DEFAULT_VALUE) {
continue;
+ }
task = current_task();
if (bank_element == BANK_DEFAULT_TASK_VALUE) {
}
bank_merchant = get_bank_task_context(task, FALSE);
- if (bank_merchant == BANK_TASK_NULL)
+ if (bank_merchant == BANK_TASK_NULL) {
return KERN_RESOURCE_SHORTAGE;
+ }
cur_thread_group = bank_get_bank_task_thread_group(bank_merchant);
*/
if (bank_merchant->bt_hasentitlement == 0) {
KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE,
- (BANK_CODE(BANK_ACCOUNT_INFO, (BANK_SECURE_ORIGINATOR_CHANGED))) | DBG_FUNC_NONE,
- bank_secureoriginator->bt_pid, bank_merchant->bt_pid, 0, 0, 0);
+ (BANK_CODE(BANK_ACCOUNT_INFO, (BANK_SECURE_ORIGINATOR_CHANGED))) | DBG_FUNC_NONE,
+ bank_secureoriginator->bt_pid, bank_merchant->bt_pid, 0, 0, 0);
bank_secureoriginator = bank_merchant;
}
bank_proximateprocess = bank_merchant;
/* Check if trying to redeem for self task, return the bank task */
- if (bank_holder == bank_merchant &&
- bank_holder == bank_secureoriginator &&
- bank_holder == bank_proximateprocess &&
- thread_group == cur_thread_group) {
-
+ if (bank_holder == bank_merchant &&
+ bank_holder == bank_secureoriginator &&
+ bank_holder == bank_proximateprocess &&
+ thread_group == cur_thread_group) {
lck_mtx_lock(&bank_holder->bt_acc_to_pay_lock);
bank_task_made_reference(bank_holder);
if (bank_holder->bt_voucher_ref == 0) {
return kr;
}
bank_account = bank_account_alloc_init(bank_holder, bank_merchant,
- bank_secureoriginator, bank_proximateprocess,
- thread_group);
- if (bank_account == BANK_ACCOUNT_NULL)
+ bank_secureoriginator, bank_proximateprocess,
+ thread_group);
+ if (bank_account == BANK_ACCOUNT_NULL) {
return KERN_RESOURCE_SHORTAGE;
+ }
*out_value = BANK_ELEMENT_TO_HANDLE(bank_account);
return kr;
bank_handle = prev_values[i];
bank_element = HANDLE_TO_BANK_ELEMENT(bank_handle);
- if (bank_element == BANK_DEFAULT_VALUE)
+ if (bank_element == BANK_DEFAULT_VALUE) {
continue;
+ }
task = current_task();
if (bank_element == BANK_DEFAULT_TASK_VALUE) {
panic("Found a bank task in MACH_VOUCHER_ATTR_REDEEM: %p", bank_task);
return kr;
-
} else if (bank_element->be_type == BANK_ACCOUNT) {
bank_account = CAST_TO_BANK_ACCOUNT(bank_element);
bank_merchant = bank_account->ba_merchant;
ipc_voucher_attr_manager_t __assert_only manager,
mach_voucher_attr_key_t __assert_only key,
mach_voucher_attr_value_handle_array_t values,
- mach_msg_type_number_t value_count,
+ mach_msg_type_number_t value_count,
mach_voucher_attr_recipe_command_t *out_command,
mach_voucher_attr_content_t out_recipe,
mach_voucher_attr_content_size_t *in_out_recipe_size)
assert(MACH_VOUCHER_ATTR_KEY_BANK == key);
assert(manager == &bank_manager);
- for (i = 0; i < value_count; i++) {
+ for (i = 0; i < value_count && *in_out_recipe_size > 0; i++) {
bank_handle = values[i];
bank_element = HANDLE_TO_BANK_ELEMENT(bank_handle);
- if (bank_element == BANK_DEFAULT_VALUE)
+ if (bank_element == BANK_DEFAULT_VALUE) {
continue;
+ }
if (bank_element == BANK_DEFAULT_TASK_VALUE) {
bank_element = CAST_TO_BANK_ELEMENT(get_bank_task_context(current_task(), FALSE));
if (bank_element->be_type == BANK_TASK) {
bank_task = CAST_TO_BANK_TASK(bank_element);
- snprintf(buf, MACH_VOUCHER_BANK_CONTENT_SIZE,
- " Bank Context for a pid %d\n", bank_task->bt_pid);
+ snprintf(buf, MACH_VOUCHER_BANK_CONTENT_SIZE,
+ " Bank Context for a pid %d\n", bank_task->bt_pid);
} else if (bank_element->be_type == BANK_ACCOUNT) {
bank_account = CAST_TO_BANK_ACCOUNT(bank_element);
snprintf(buf, MACH_VOUCHER_BANK_CONTENT_SIZE,
- " Bank Account linking holder pid %d with merchant pid %d, originator PID/persona: %d, %u and proximate PID/persona: %d, %u\n",
- bank_account->ba_holder->bt_pid,
- bank_account->ba_merchant->bt_pid,
- bank_account->ba_secureoriginator->bt_pid,
- bank_account->ba_secureoriginator->bt_persona_id,
- bank_account->ba_proximateprocess->bt_pid,
- bank_account->ba_proximateprocess->bt_persona_id);
+ " Bank Account linking holder pid %d with merchant pid %d, originator PID/persona: %d, %u and proximate PID/persona: %d, %u\n",
+ bank_account->ba_holder->bt_pid,
+ bank_account->ba_merchant->bt_pid,
+ bank_account->ba_secureoriginator->bt_pid,
+ bank_account->ba_secureoriginator->bt_persona_id,
+ bank_account->ba_proximateprocess->bt_pid,
+ bank_account->ba_proximateprocess->bt_persona_id);
} else {
panic("Bogus bank type: %d passed in get_value\n", bank_element->be_type);
}
* Routine: bank_command
* Purpose: Execute a command against a set of ATM values.
* Returns: KERN_SUCCESS: On successful execution of command.
- KERN_FAILURE: On failure.
+ * KERN_FAILURE: On failure.
*/
kern_return_t
bank_command(
- ipc_voucher_attr_manager_t __assert_only manager,
- mach_voucher_attr_key_t __assert_only key,
- mach_voucher_attr_value_handle_array_t __unused values,
- mach_msg_type_number_t __unused value_count,
- mach_voucher_attr_command_t __unused command,
- mach_voucher_attr_content_t __unused in_content,
+ ipc_voucher_attr_manager_t __assert_only manager,
+ mach_voucher_attr_key_t __assert_only key,
+ mach_voucher_attr_value_handle_array_t __unused values,
+ mach_msg_type_number_t __unused value_count,
+ mach_voucher_attr_command_t __unused command,
+ mach_voucher_attr_content_t __unused in_content,
mach_voucher_attr_content_size_t __unused in_content_size,
- mach_voucher_attr_content_t __unused out_content,
+ mach_voucher_attr_content_t __unused out_content,
mach_voucher_attr_content_size_t __unused *out_content_size)
{
bank_task_t bank_task = BANK_TASK_NULL;
for (i = 0; i < value_count; i++) {
bank_handle = values[i];
bank_element = HANDLE_TO_BANK_ELEMENT(bank_handle);
- if (bank_element == BANK_DEFAULT_VALUE)
+ if (bank_element == BANK_DEFAULT_VALUE) {
continue;
+ }
if (bank_element == BANK_DEFAULT_TASK_VALUE) {
bank_element = CAST_TO_BANK_ELEMENT(get_bank_task_context(current_task(), FALSE));
for (i = 0; i < value_count; i++) {
bank_handle = values[i];
bank_element = HANDLE_TO_BANK_ELEMENT(bank_handle);
- if (bank_element == BANK_DEFAULT_VALUE)
+ if (bank_element == BANK_DEFAULT_VALUE) {
continue;
+ }
if (bank_element == BANK_DEFAULT_TASK_VALUE) {
bank_element = CAST_TO_BANK_ELEMENT(get_bank_task_context(current_task(), FALSE));
void
bank_release(
- ipc_voucher_attr_manager_t __assert_only manager)
+ ipc_voucher_attr_manager_t __assert_only manager)
{
assert(manager == &bank_manager);
}
* Returns: bank_task_t on Success.
* BANK_TASK_NULL: on Failure.
* Notes: Leaves the task and ledger blank and has only 1 ref,
- needs to take 1 extra ref after the task field is initialized.
+ * needs to take 1 extra ref after the task field is initialized.
*/
static bank_task_t
bank_task_alloc_init(task_t task)
bank_task_t new_bank_task;
new_bank_task = (bank_task_t) zalloc(bank_task_zone);
- if (new_bank_task == BANK_TASK_NULL)
+ if (new_bank_task == BANK_TASK_NULL) {
return BANK_TASK_NULL;
+ }
new_bank_task->bt_type = BANK_TASK;
new_bank_task->bt_voucher_ref = 0;
queue_enter(&bank_tasks_list, new_bank_task, bank_task_t, bt_global_elt);
lck_mtx_unlock(&bank_tasks_list_lock);
#endif
- return (new_bank_task);
+ return new_bank_task;
}
/*
boolean_t entry_found = FALSE;
ledger_t new_ledger = ledger_instantiate(bank_ledger_template, LEDGER_CREATE_INACTIVE_ENTRIES);
- if (new_ledger == LEDGER_NULL)
+ if (new_ledger == LEDGER_NULL) {
return BANK_ACCOUNT_NULL;
+ }
ledger_entry_setactive(new_ledger, bank_ledgers.cpu_time);
ledger_entry_setactive(new_ledger, bank_ledgers.energy);
if (bank_account->ba_merchant != bank_merchant ||
bank_account->ba_secureoriginator != bank_secureoriginator ||
bank_account->ba_proximateprocess != bank_proximateprocess ||
- bank_get_bank_account_thread_group(bank_account) != thread_group)
+ bank_get_bank_account_thread_group(bank_account) != thread_group) {
continue;
+ }
entry_found = TRUE;
/* Take a made ref, since this value would be returned to voucher system. */
}
if (!entry_found) {
-
/* Create a linkage between the holder and the merchant task, Grab both the list locks before adding it to the list. */
lck_mtx_lock(&bank_merchant->bt_acc_to_charge_lock);
-
+
/* Add the account entry into Accounts need to pay account link list. */
queue_enter(&bank_holder->bt_accounts_to_pay, new_bank_account, bank_account_t, ba_next_acc_to_pay);
zfree(bank_account_zone, new_bank_account);
return bank_account;
}
-
+
bank_task_reference(bank_holder);
bank_task_reference(bank_merchant);
bank_task_reference(bank_secureoriginator);
lck_mtx_unlock(&bank_accounts_list_lock);
#endif
- return (new_bank_account);
+ return new_bank_account;
}
/*
*/
static bank_task_t
get_bank_task_context
- (task_t task,
- boolean_t initialize)
+(task_t task,
+ boolean_t initialize)
{
bank_task_t bank_task;
if (task->bank_context || !initialize) {
assert(task->bank_context != NULL);
- return (task->bank_context);
+ return task->bank_context;
}
bank_task = bank_task_alloc_init(task);
task_lock(task);
if (task->bank_context) {
task_unlock(task);
- if (bank_task != BANK_TASK_NULL)
+ if (bank_task != BANK_TASK_NULL) {
bank_task_dealloc(bank_task, 1);
- return (task->bank_context);
+ }
+ return task->bank_context;
} else if (bank_task == BANK_TASK_NULL) {
task_unlock(task);
return BANK_TASK_NULL;
global_bank_task_unlock();
task_unlock(task);
-
- return (bank_task);
+
+ return bank_task;
}
-
+
/*
* Routine: bank_task_dealloc
* Purpose: Drops the reference on bank task.
{
assert(bank_task->bt_refs >= 0);
- if (bank_task_release_num(bank_task, sync) > (int)sync)
+ if (bank_task_release_num(bank_task, sync) > (int)sync) {
return;
+ }
assert(bank_task->bt_refs == 0);
assert(queue_empty(&bank_task->bt_accounts_to_pay));
}
return KERN_FAILURE;
}
-
+
bank_account_made_release_num(bank_account, sync);
- if (bank_account_release_num(bank_account, 1) > 1)
+ if (bank_account_release_num(bank_account, 1) > 1) {
panic("Releasing a non zero ref bank account %p\n", bank_account);
+ }
/* Grab both the acc to pay and acc to charge locks */
/* No need to take ledger reference for bank_holder ledger since bt_acc_to_pay_lock is locked */
bank_rollup_chit_to_tasks(bank_account->ba_bill, bank_holder->bt_ledger, bank_merchant_ledger,
- bank_holder->bt_pid, bank_merchant->bt_pid);
+ bank_holder->bt_pid, bank_merchant->bt_pid);
/* Remove the account entry from Accounts need to pay account link list. */
queue_remove(&bank_holder->bt_accounts_to_pay, bank_account, bank_account_t, ba_next_acc_to_pay);
-
+
/* Remove the account entry from Accounts need to charge account link list. */
queue_remove(&bank_merchant->bt_accounts_to_charge, bank_account, bank_account_t, ba_next_acc_to_charge);
-
+
lck_mtx_unlock(&bank_merchant->bt_acc_to_charge_lock);
lck_mtx_unlock(&bank_holder->bt_acc_to_pay_lock);
queue_remove(&bank_accounts_list, bank_account, bank_account_t, ba_global_elt);
lck_mtx_unlock(&bank_accounts_list_lock);
#endif
-
+
zfree(bank_account_zone, bank_account);
return KERN_SUCCESS;
}
ledger_amount_t debit;
kern_return_t ret;
- if (bank_holder_ledger == bank_merchant_ledger)
+ if (bank_holder_ledger == bank_merchant_ledger) {
return;
+ }
ret = ledger_get_entries(bill, bank_ledgers.cpu_time, &credit, &debit);
if (ret == KERN_SUCCESS) {
KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE,
- (BANK_CODE(BANK_ACCOUNT_INFO, (BANK_SETTLE_CPU_TIME))) | DBG_FUNC_NONE,
- bank_merchant_pid, bank_holder_pid, credit, debit, 0);
+ (BANK_CODE(BANK_ACCOUNT_INFO, (BANK_SETTLE_CPU_TIME))) | DBG_FUNC_NONE,
+ bank_merchant_pid, bank_holder_pid, credit, debit, 0);
if (bank_holder_ledger) {
ledger_credit(bank_holder_ledger, task_ledgers.cpu_time_billed_to_me, credit);
ret = ledger_get_entries(bill, bank_ledgers.energy, &credit, &debit);
if (ret == KERN_SUCCESS) {
KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE,
- (BANK_CODE(BANK_ACCOUNT_INFO, (BANK_SETTLE_ENERGY))) | DBG_FUNC_NONE,
- bank_merchant_pid, bank_holder_pid, credit, debit, 0);
+ (BANK_CODE(BANK_ACCOUNT_INFO, (BANK_SETTLE_ENERGY))) | DBG_FUNC_NONE,
+ bank_merchant_pid, bank_holder_pid, credit, debit, 0);
if (bank_holder_ledger) {
ledger_credit(bank_holder_ledger, task_ledgers.energy_billed_to_me, credit);
* Returns: None.
*/
static void
-init_bank_ledgers(void) {
+init_bank_ledgers(void)
+{
ledger_template_t t;
int idx;
-
+
assert(bank_ledger_template == NULL);
- if ((t = ledger_template_create("Bank ledger")) == NULL)
+ if ((t = ledger_template_create("Bank ledger")) == NULL) {
panic("couldn't create bank ledger template");
+ }
if ((idx = ledger_entry_add(t, "cpu_time", "sched", "ns")) < 0) {
panic("couldn't create cpu_time entry for bank ledger template");
/* Routine: bank_billed_balance_safe
* Purpose: Walk through all the bank accounts billed to me by other tasks and get the current billing balance.
* Called from another task. It takes global bank task lock to make sure the bank context is
- not deallocated while accesing it.
+ * not deallocated while accesing it.
* Returns: cpu balance and energy balance in out paremeters.
*/
void
bank_task_dealloc(bank_task, 1);
} else {
kr = ledger_get_entries(task->ledger, task_ledgers.cpu_time_billed_to_me,
- &credit, &debit);
+ &credit, &debit);
if (kr == KERN_SUCCESS) {
cpu_balance = credit - debit;
}
kr = ledger_get_entries(task->ledger, task_ledgers.energy_billed_to_me,
- &credit, &debit);
+ &credit, &debit);
if (kr == KERN_SUCCESS) {
energy_balance = credit - debit;
}
*energy = 0;
return;
}
-
+
lck_mtx_lock(&bank_task->bt_acc_to_pay_lock);
/* bt_acc_to_pay_lock locked, no need to take ledger reference for bt_ledger */
/* Routine: bank_serviced_balance_safe
* Purpose: Walk through the bank accounts billed to other tasks by me and get the current balance to be charged.
* Called from another task. It takes global bank task lock to make sure the bank context is
- not deallocated while accesing it.
+ * not deallocated while accesing it.
* Returns: cpu balance and energy balance in out paremeters.
*/
void
bank_task_dealloc(bank_task, 1);
} else {
kr = ledger_get_entries(task->ledger, task_ledgers.cpu_time_billed_to_others,
- &credit, &debit);
+ &credit, &debit);
if (kr == KERN_SUCCESS) {
cpu_balance = credit - debit;
}
kr = ledger_get_entries(task->ledger, task_ledgers.energy_billed_to_others,
- &credit, &debit);
+ &credit, &debit);
if (kr == KERN_SUCCESS) {
energy_balance = credit - debit;
}
val_count = MACH_VOUCHER_ATTR_VALUE_MAX_NESTED;
kr = mach_voucher_attr_control_get_values(bank_voucher_attr_control,
- voucher,
- vals,
- &val_count);
+ voucher,
+ vals,
+ &val_count);
- if (kr != KERN_SUCCESS || val_count == 0)
+ if (kr != KERN_SUCCESS || val_count == 0) {
return BANK_ACCOUNT_NULL;
+ }
bank_element = HANDLE_TO_BANK_ELEMENT(vals[0]);
- if (bank_element == BANK_DEFAULT_VALUE)
+ if (bank_element == BANK_DEFAULT_VALUE) {
return BANK_ACCOUNT_NULL;
- if (bank_element == BANK_DEFAULT_TASK_VALUE)
+ }
+ if (bank_element == BANK_DEFAULT_TASK_VALUE) {
bank_element = CAST_TO_BANK_ELEMENT(get_bank_task_context(current_task(), FALSE));
+ }
if (bank_element->be_type == BANK_TASK) {
return BANK_ACCOUNT_NULL;
* voucher to App's thread group when it gets auto redeemed by the App).
*/
if (bank_account->ba_holder != bank_account->ba_merchant ||
- bank_get_bank_account_thread_group(bank_account) !=
- bank_get_bank_task_thread_group(bank_account->ba_merchant)) {
+ bank_get_bank_account_thread_group(bank_account) !=
+ bank_get_bank_task_thread_group(bank_account->ba_merchant)) {
return bank_account;
} else {
return BANK_ACCOUNT_NULL;
ledger_t bankledger = LEDGER_NULL;
if (bank_account != BANK_ACCOUNT_NULL &&
- bank_account->ba_holder != bank_account->ba_merchant)
+ bank_account->ba_holder != bank_account->ba_merchant) {
bankledger = bank_account->ba_bill;
+ }
- return (bankledger);
+ return bankledger;
}
/*
struct thread_group *banktg = NULL;
- return (banktg);
+ return banktg;
}
/*
struct thread_group *banktg = NULL;
- return (banktg);
+ return banktg;
}
/*
/* Return NULL thread group if voucher has current task's thread group */
if (thread_group == bank_get_bank_task_thread_group(
- get_bank_task_context(current_task(), FALSE))) {
+ get_bank_task_context(current_task(), FALSE))) {
thread_group = NULL;
}
*banktg = thread_group;
void
bank_swap_thread_bank_ledger(thread_t thread __unused, ledger_t new_ledger __unused)
{
- spl_t s;
- processor_t processor;
+ spl_t s;
+ processor_t processor;
ledger_t old_ledger = thread->t_bankledger;
- int64_t ctime, effective_ledger_time_consumed = 0;
+ int64_t ctime, effective_ledger_time_consumed = 0;
int64_t remainder = 0, consumed = 0;
int64_t effective_energy_consumed = 0;
uint64_t thread_energy;
-
- if (old_ledger == LEDGER_NULL && new_ledger == LEDGER_NULL)
+
+ if (old_ledger == LEDGER_NULL && new_ledger == LEDGER_NULL) {
return;
+ }
assert((thread == current_thread() || thread->started == 0));
ctime = mach_absolute_time();
processor = thread->last_processor;
if (processor != NULL) {
- if ((int64_t)processor->quantum_end > ctime)
+ if ((int64_t)processor->quantum_end > ctime) {
remainder = (int64_t)processor->quantum_end - ctime;
-
+ }
+
consumed = thread->quantum_remaining - remainder;
effective_ledger_time_consumed = consumed - thread->t_deduct_bank_ledger_time;
}
thread_energy = ml_energy_stat(thread);
effective_energy_consumed =
- thread_energy - thread->t_deduct_bank_ledger_energy;
+ thread_energy - thread->t_deduct_bank_ledger_energy;
assert(effective_energy_consumed >= 0);
thread->t_deduct_bank_ledger_energy = thread_energy;
thread_unlock(thread);
splx(s);
-
+
if (old_ledger != LEDGER_NULL) {
ledger_credit(old_ledger,
- bank_ledgers.cpu_time,
- effective_ledger_time_consumed);
+ bank_ledgers.cpu_time,
+ effective_ledger_time_consumed);
ledger_credit(old_ledger,
- bank_ledgers.energy,
- effective_energy_consumed);
+ bank_ledgers.energy,
+ effective_energy_consumed);
}
}
-