static void atm_value_get_ref(atm_value_t atm_value);
static kern_return_t atm_listener_insert(atm_value_t atm_value, atm_task_descriptor_t task_descriptor, atm_guard_t guard);
static void atm_listener_delete_all(atm_value_t atm_value);
-static atm_task_descriptor_t atm_task_descriptor_alloc_init(mach_port_t trace_buffer,uint64_t buffer_size, __assert_only task_t task);
+static atm_task_descriptor_t atm_task_descriptor_alloc_init(mach_port_t trace_buffer, uint64_t buffer_size, __assert_only task_t task);
static void atm_descriptor_get_reference(atm_task_descriptor_t task_descriptor);
static void atm_task_descriptor_dealloc(atm_task_descriptor_t task_descriptor);
static kern_return_t atm_value_unregister(atm_value_t atm_value, atm_task_descriptor_t task_descriptor, atm_guard_t guard);
.ivam_release_value = atm_release_value,
.ivam_get_value = atm_get_value,
.ivam_extract_content = atm_extract_content,
- .ivam_command = atm_command,
+ .ivam_command = atm_command,
.ivam_release = atm_release,
.ivam_flags = IVAM_FLAGS_NONE,
};
decl_lck_mtx_data(, atm_descriptors_list_lock);
decl_lck_mtx_data(, atm_values_list_lock);
-lck_grp_t atm_dev_lock_grp;
-lck_attr_t atm_dev_lock_attr;
-lck_grp_attr_t atm_dev_lock_grp_attr;
+lck_grp_t atm_dev_lock_grp;
+lck_attr_t atm_dev_lock_attr;
+lck_grp_attr_t atm_dev_lock_grp_attr;
#endif
extern vm_map_t kernel_map;
/*
* Lock group attributes for atm sub system.
*/
-lck_grp_t atm_lock_grp;
-lck_attr_t atm_lock_attr;
-lck_grp_attr_t atm_lock_grp_attr;
+lck_grp_t atm_lock_grp;
+lck_attr_t atm_lock_attr;
+lck_grp_attr_t atm_lock_grp_attr;
/*
* Global that is set by diagnosticd and readable by userspace
char temp_buf[20];
/* Disable atm if disable_atm present in device-tree properties or in boot-args */
- if ((PE_get_default("kern.disable_atm", temp_buf, sizeof(temp_buf))) ||
+ if ((PE_get_default("kern.disable_atm", temp_buf, sizeof(temp_buf))) ||
(PE_parse_boot_argn("-disable_atm", temp_buf, sizeof(temp_buf)))) {
disable_atm = TRUE;
}
if (!PE_parse_boot_argn("atm_diagnostic_config", &atm_diagnostic_config, sizeof(atm_diagnostic_config))) {
- if (!PE_get_default("kern.atm_diagnostic_config", &atm_diagnostic_config, sizeof(atm_diagnostic_config))) {
+ if (!PE_get_default("kern.atm_diagnostic_config", &atm_diagnostic_config, sizeof(atm_diagnostic_config))) {
atm_diagnostic_config = 0;
}
}
/* setup zones for descriptors, values and link objects */
atm_value_zone = zinit(sizeof(struct atm_value),
- MAX_ATM_VALUES * sizeof(struct atm_value),
- sizeof(struct atm_value),
- "atm_values");
+ MAX_ATM_VALUES * sizeof(struct atm_value),
+ sizeof(struct atm_value),
+ "atm_values");
atm_descriptors_zone = zinit(sizeof(struct atm_task_descriptor),
- MAX_ATM_VALUES * sizeof(struct atm_task_descriptor),
- sizeof(struct atm_task_descriptor),
- "atm_task_descriptors");
+ MAX_ATM_VALUES * sizeof(struct atm_task_descriptor),
+ sizeof(struct atm_task_descriptor),
+ "atm_task_descriptors");
atm_link_objects_zone = zinit(sizeof(struct atm_link_object),
- MAX_ATM_VALUES * sizeof(struct atm_link_object),
- sizeof(struct atm_link_object),
- "atm_link_objects");
+ MAX_ATM_VALUES * sizeof(struct atm_link_object),
+ sizeof(struct atm_link_object),
+ "atm_link_objects");
/* Initialize atm lock group and lock attributes. */
lck_grp_attr_setdefault(&atm_lock_grp_attr);
/* Register the atm manager with the Vouchers sub system. */
kr = ipc_register_well_known_mach_voucher_attr_manager(
- &atm_manager,
- 0,
- MACH_VOUCHER_ATTR_KEY_ATM,
- &voucher_attr_control);
- if (kr != KERN_SUCCESS )
+ &atm_manager,
+ 0,
+ MACH_VOUCHER_ATTR_KEY_ATM,
+ &voucher_attr_control);
+ if (kr != KERN_SUCCESS) {
panic("ATM subsystem initialization failed");
+ }
kprintf("ATM subsystem is initialized\n");
- return ;
+ return;
}
*/
kern_return_t
atm_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)
{
atm_value_t atm_value = ATM_VALUE_NULL;
*/
kern_return_t
atm_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 __assert_only 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 __assert_only 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)
{
atm_value_t atm_value = ATM_VALUE_NULL;
mach_voucher_attr_value_handle_t atm_handle;
*out_value_voucher = IPC_VOUCHER_NULL;
*out_flags = MACH_VOUCHER_ATTR_VALUE_FLAGS_NONE;
- if (disable_atm || (atm_get_diagnostic_config() & ATM_TRACE_DISABLE))
+ if (disable_atm || (atm_get_diagnostic_config() & ATM_TRACE_DISABLE)) {
return KERN_NOT_SUPPORTED;
+ }
switch (command) {
-
case MACH_VOUCHER_ATTR_ATM_REGISTER:
for (i = 0; i < prev_value_count; i++) {
atm_handle = prev_values[i];
atm_value = HANDLE_TO_ATM_VALUE(atm_handle);
- if (atm_value == VAM_DEFAULT_VALUE)
+ if (atm_value == VAM_DEFAULT_VALUE) {
continue;
+ }
if (recipe_size != sizeof(atm_guard_t)) {
kr = KERN_INVALID_ARGUMENT;
task = current_task();
task_descriptor = task->atm_context;
-
+
kr = atm_value_register(atm_value, task_descriptor, guard);
if (kr != KERN_SUCCESS) {
break;
kr = KERN_INVALID_ARGUMENT;
break;
}
-
+
/* Allocate a new atm value. */
atm_value = atm_value_alloc_init(aid);
if (atm_value == ATM_VALUE_NULL) {
kr = KERN_RESOURCE_SHORTAGE;
break;
}
-redrive:
+redrive:
kr = atm_value_hash_table_insert(atm_value);
if (kr != KERN_SUCCESS) {
if (recipe_size == 0) {
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_ATM == key);
assert(manager == &atm_manager);
- for (i = 0; i < value_count; i++) {
+ for (i = 0; i < value_count && *in_out_recipe_size > 0; i++) {
atm_handle = values[i];
atm_value = HANDLE_TO_ATM_VALUE(atm_handle);
- if (atm_value == VAM_DEFAULT_VALUE)
+ if (atm_value == VAM_DEFAULT_VALUE) {
continue;
+ }
- if (( sizeof(aid_t)) > *in_out_recipe_size) {
+ if ((sizeof(aid_t)) > *in_out_recipe_size) {
*in_out_recipe_size = 0;
return KERN_NO_SPACE;
}
* Routine: atm_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
atm_command(
- 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_voucher_attr_command_t command,
- mach_voucher_attr_content_t 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 values,
+ mach_msg_type_number_t value_count,
+ mach_voucher_attr_command_t command,
+ mach_voucher_attr_content_t in_content,
mach_voucher_attr_content_size_t in_content_size,
- mach_voucher_attr_content_t out_content,
+ mach_voucher_attr_content_t out_content,
mach_voucher_attr_content_size_t *out_content_size)
{
assert(MACH_VOUCHER_ATTR_KEY_ATM == key);
task_t task;
kern_return_t kr = KERN_SUCCESS;
atm_guard_t guard;
-
+
switch (command) {
case ATM_ACTION_COLLECT:
- /* Fall through */
+ /* Fall through */
case ATM_ACTION_LOGFAIL:
return KERN_NOT_SUPPORTED;
case ATM_FIND_MIN_SUB_AID:
- if ((in_content_size/sizeof(aid_t)) > (*out_content_size/sizeof(mach_atm_subaid_t)))
+ if ((in_content_size / sizeof(aid_t)) > (*out_content_size / sizeof(mach_atm_subaid_t))) {
return KERN_FAILURE;
+ }
aid_array_count = in_content_size / sizeof(aid_t);
- if (aid_array_count > AID_ARRAY_COUNT_MAX)
+ if (aid_array_count > AID_ARRAY_COUNT_MAX) {
return KERN_FAILURE;
+ }
subaid_array = (mach_atm_subaid_t *) (void *) out_content;
for (i = 0; i < aid_array_count; i++) {
/* find the first non-default atm_value */
for (i = 0; i < value_count; i++) {
atm_value = HANDLE_TO_ATM_VALUE(values[i]);
- if (atm_value != VAM_DEFAULT_VALUE)
+ if (atm_value != VAM_DEFAULT_VALUE) {
break;
+ }
}
/* if we are not able to find any atm values
if (atm_value == NULL) {
return KERN_FAILURE;
}
- if (in_content == NULL || in_content_size != sizeof(atm_guard_t)){
+ if (in_content == NULL || in_content_size != sizeof(atm_guard_t)) {
return KERN_INVALID_ARGUMENT;
}
case ATM_ACTION_REGISTER:
for (i = 0; i < value_count; i++) {
atm_value = HANDLE_TO_ATM_VALUE(values[i]);
- if (atm_value != VAM_DEFAULT_VALUE)
+ if (atm_value != VAM_DEFAULT_VALUE) {
break;
+ }
}
/* if we are not able to find any atm values
* in stack then this call was made in error
if (atm_value == NULL) {
return KERN_FAILURE;
}
- if (in_content == NULL || in_content_size != sizeof(atm_guard_t)){
+ if (in_content == NULL || in_content_size != sizeof(atm_guard_t)) {
return KERN_INVALID_ARGUMENT;
}
break;
case ATM_ACTION_GETSUBAID:
- if (out_content == NULL || *out_content_size != sizeof(mach_atm_subaid_t))
+ if (out_content == NULL || *out_content_size != sizeof(mach_atm_subaid_t)) {
return KERN_FAILURE;
+ }
next_subaid = get_subaid();
memcpy(out_content, &next_subaid, sizeof(mach_atm_subaid_t));
void
atm_release(
- ipc_voucher_attr_manager_t __assert_only manager)
+ ipc_voucher_attr_manager_t __assert_only manager)
{
assert(manager == &atm_manager);
}
atm_value_t new_atm_value = ATM_VALUE_NULL;
new_atm_value = (atm_value_t) zalloc(atm_value_zone);
- if (new_atm_value == ATM_VALUE_NULL)
+ if (new_atm_value == ATM_VALUE_NULL) {
panic("Ran out of ATM values structure.\n\n");
+ }
new_atm_value->aid = aid;
queue_init(&new_atm_value->listeners);
* aid found. return error.
*/
lck_mtx_unlock(&hash_list_head->hash_list_lock);
- return (KERN_NAME_EXISTS);
+ return KERN_NAME_EXISTS;
}
}
*/
atm_value_get_ref(next);
lck_mtx_unlock(&hash_list_head->hash_list_lock);
- return (next);
+ return next;
}
}
lck_mtx_unlock(&hash_list_head->hash_list_lock);
*/
static kern_return_t
atm_listener_insert(
- atm_value_t atm_value,
- atm_task_descriptor_t task_descriptor,
- atm_guard_t guard)
+ atm_value_t atm_value,
+ atm_task_descriptor_t task_descriptor,
+ atm_guard_t guard)
{
atm_link_object_t new_link_object;
atm_link_object_t next, elem;
continue;
}
- if (element_found)
+ if (element_found) {
continue;
+ }
if (elem->descriptor == task_descriptor) {
/* Increment reference count on Link object. */
elem->guard = guard;
element_found = TRUE;
KERNEL_DEBUG_CONSTANT((ATM_CODE(ATM_GETVALUE_INFO, (ATM_VALUE_REPLACED))) | DBG_FUNC_NONE,
- VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, guard, 0, 0);
-
+ VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, guard, 0, 0);
}
}
zfree(atm_link_objects_zone, new_link_object);
} else {
KERNEL_DEBUG_CONSTANT((ATM_CODE(ATM_GETVALUE_INFO, (ATM_VALUE_ADDED))) | DBG_FUNC_NONE,
- VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, guard, 0, 0);
+ VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, guard, 0, 0);
queue_enter(&atm_value->listeners, new_link_object, atm_link_object_t, listeners_element);
atm_listener_count_incr_internal(atm_value);
}
/* Free the link objects */
- while(!queue_empty(&free_listeners)) {
+ while (!queue_empty(&free_listeners)) {
queue_remove_first(&free_listeners, next, atm_link_object_t, listeners_element);
/* Deallocate the link object */
}
KERNEL_DEBUG_CONSTANT((ATM_CODE(ATM_SUBAID_INFO, (ATM_LINK_LIST_TRIM))) | DBG_FUNC_NONE,
- listener_count, freed_count, dead_but_not_freed, VM_KERNEL_ADDRPERM(atm_value), 1);
+ listener_count, freed_count, dead_but_not_freed, VM_KERNEL_ADDRPERM(atm_value), 1);
return KERN_SUCCESS;
}
{
atm_link_object_t next;
- while(!queue_empty(&atm_value->listeners)) {
+ while (!queue_empty(&atm_value->listeners)) {
queue_remove_first(&atm_value->listeners, next, atm_link_object_t, listeners_element);
/* Deallocate the link object */
if (elem->descriptor == task_descriptor) {
if (elem->guard == guard) {
KERNEL_DEBUG_CONSTANT((ATM_CODE(ATM_UNREGISTER_INFO,
- (ATM_VALUE_UNREGISTERED))) | DBG_FUNC_NONE,
- VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, guard, elem->reference_count, 0);
+ (ATM_VALUE_UNREGISTERED))) | DBG_FUNC_NONE,
+ VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, guard, elem->reference_count, 0);
elem->guard = 0;
kr = KERN_SUCCESS;
} else {
KERNEL_DEBUG_CONSTANT((ATM_CODE(ATM_UNREGISTER_INFO,
- (ATM_VALUE_DIFF_MAILBOX))) | DBG_FUNC_NONE,
- VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, elem->guard, elem->reference_count, 0);
+ (ATM_VALUE_DIFF_MAILBOX))) | DBG_FUNC_NONE,
+ VM_KERNEL_ADDRPERM(atm_value), atm_value->aid, elem->guard, elem->reference_count, 0);
kr = KERN_INVALID_VALUE;
}
if (0 == atm_link_object_release_internal(elem)) {
}
lck_mtx_unlock(&atm_value->listener_lock);
- while(!queue_empty(&free_listeners)) {
+ while (!queue_empty(&free_listeners)) {
queue_remove_first(&free_listeners, next, atm_link_object_t, listeners_element);
-
+
/* Deallocate the link object */
atm_link_dealloc(next);
}
*/
static atm_task_descriptor_t
atm_task_descriptor_alloc_init(
- mach_port_t trace_buffer,
- uint64_t buffer_size,
- task_t __assert_only task)
+ mach_port_t trace_buffer,
+ uint64_t buffer_size,
+ task_t __assert_only task)
{
atm_task_descriptor_t new_task_descriptor;
*/
kern_return_t
atm_register_trace_memory(
- task_t task,
- uint64_t trace_buffer_address,
- uint64_t buffer_size)
+ task_t task,
+ uint64_t trace_buffer_address,
+ uint64_t buffer_size)
{
atm_task_descriptor_t task_descriptor;
mach_port_t trace_buffer = MACH_PORT_NULL;
kern_return_t kr = KERN_SUCCESS;
- if (disable_atm || (atm_get_diagnostic_config() & ATM_TRACE_DISABLE))
+ if (disable_atm || (atm_get_diagnostic_config() & ATM_TRACE_DISABLE)) {
return KERN_NOT_SUPPORTED;
+ }
- if (task != current_task())
+ if (task != current_task()) {
return KERN_INVALID_ARGUMENT;
+ }
if (task->atm_context != NULL
|| (void *)trace_buffer_address == NULL
vm_map_t map = current_map();
memory_object_size_t mo_size = (memory_object_size_t) buffer_size;
kr = mach_make_memory_entry_64(map,
- &mo_size,
- (mach_vm_offset_t)trace_buffer_address,
- VM_PROT_READ,
- &trace_buffer,
- NULL);
- if (kr != KERN_SUCCESS)
+ &mo_size,
+ (mach_vm_offset_t)trace_buffer_address,
+ VM_PROT_READ,
+ &trace_buffer,
+ NULL);
+ if (kr != KERN_SUCCESS) {
return kr;
+ }
task_descriptor = atm_task_descriptor_alloc_init(trace_buffer, buffer_size, task);
if (task_descriptor == ATM_TASK_DESCRIPTOR_NULL) {
kern_return_t
atm_set_diagnostic_config(uint32_t diagnostic_config)
{
- if (disable_atm)
+ if (disable_atm) {
return KERN_NOT_SUPPORTED;
+ }
atm_diagnostic_config = diagnostic_config;
commpage_update_atm_diagnostic_config(atm_diagnostic_config);
{
kern_return_t kr;
- if (task_descriptor == ATM_TASK_DESCRIPTOR_NULL)
+ if (task_descriptor == ATM_TASK_DESCRIPTOR_NULL) {
return KERN_INVALID_TASK;
-
+ }
+
kr = atm_listener_delete(atm_value, task_descriptor, guard);
return kr;
}
{
kern_return_t kr;
- if (task_descriptor == ATM_TASK_DESCRIPTOR_NULL)
+ if (task_descriptor == ATM_TASK_DESCRIPTOR_NULL) {
return KERN_INVALID_TASK;
+ }
kr = atm_listener_insert(atm_value, task_descriptor, guard);
return kr;