1 | /* |
2 | * Copyright (c) 2015 Apple Inc. All rights reserved. |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * |
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. |
14 | * |
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 |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
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. |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ |
28 | |
29 | #ifndef _KERN_CDATA_H_ |
30 | #define _KERN_CDATA_H_ |
31 | |
32 | #include <kern/kcdata.h> |
33 | #include <mach/mach_types.h> |
34 | |
35 | /* |
36 | * Do not use these macros! |
37 | * |
38 | * Instead, you should use kcdata_iter_* functions defined in kcdata.h. These |
39 | * macoros have no idea where the kcdata buffer ends, so they are all unsafe. |
40 | */ |
41 | #define (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint64_t)) |
42 | #define KCDATA_ITEM_ITER(item) kcdata_iter_unsafe((void*)(item)) |
43 | #define KCDATA_ITEM_TYPE(item) kcdata_iter_type(KCDATA_ITEM_ITER(item)) |
44 | #define KCDATA_ITEM_SIZE(item) kcdata_iter_size(KCDATA_ITEM_ITER(item)) |
45 | #define KCDATA_ITEM_FLAGS(item) kcdata_iter_flags(KCDATA_ITEM_ITER(item)) |
46 | #define KCDATA_ITEM_ARRAY_GET_EL_TYPE(item) kcdata_iter_array_elem_type(KCDATA_ITEM_ITER(item)) |
47 | #define KCDATA_ITEM_ARRAY_GET_EL_COUNT(item) kcdata_iter_array_elem_count(KCDATA_ITEM_ITER(item)) |
48 | #define KCDATA_ITEM_ARRAY_GET_EL_SIZE(item) kcdata_iter_array_elem_size(KCDATA_ITEM_ITER(item)) |
49 | #define KCDATA_CONTAINER_ID(item) kcdata_iter_container_id(KCDATA_ITEM_ITER(item)) |
50 | #define (itemx) (kcdata_iter_next(KCDATA_ITEM_ITER(itemx)).item) |
51 | #define KCDATA_ITEM_FOREACH(head) for (; KCDATA_ITEM_TYPE(head) != KCDATA_TYPE_BUFFER_END; (head) = KCDATA_ITEM_NEXT_HEADER(head)) |
52 | #define KCDATA_ITEM_DATA_PTR(item) kcdata_iter_payload(KCDATA_ITEM_ITER(item)) |
53 | #define KCDATA_ITEM_FIND_TYPE(itemx, type) (kcdata_iter_find_type(KCDATA_ITEM_ITER(itemx), type).item) |
54 | #define kcdata_get_container_type(buffer) kcdata_iter_container_type(KCDATA_ITEM_ITER(buffer)) |
55 | #define kcdata_get_data_with_desc(buf,desc,data) kcdata_iter_get_data_with_desc(KCDATA_ITEM_ITER(buf),desc,data,NULL) |
56 | /* Do not use these macros! */ |
57 | |
58 | #ifdef KERNEL |
59 | |
60 | #ifdef XNU_KERNEL_PRIVATE |
61 | |
62 | /* Structure to save information about corpse data */ |
63 | struct kcdata_descriptor { |
64 | uint32_t kcd_length; |
65 | uint16_t kcd_flags; |
66 | #define KCFLAG_USE_MEMCOPY 0x0 |
67 | #define KCFLAG_USE_COPYOUT 0x1 |
68 | #define KCFLAG_NO_AUTO_ENDBUFFER 0x2 |
69 | uint16_t kcd_user_flags; /* reserved for subsystems using kcdata */ |
70 | mach_vm_address_t kcd_addr_begin; |
71 | mach_vm_address_t kcd_addr_end; |
72 | }; |
73 | |
74 | typedef struct kcdata_descriptor * kcdata_descriptor_t; |
75 | |
76 | kcdata_descriptor_t kcdata_memory_alloc_init(mach_vm_address_t crash_data_p, unsigned data_type, unsigned size, unsigned flags); |
77 | kern_return_t kcdata_memory_static_init( |
78 | kcdata_descriptor_t data, mach_vm_address_t buffer_addr_p, unsigned data_type, unsigned size, unsigned flags); |
79 | kern_return_t kcdata_memory_destroy(kcdata_descriptor_t data); |
80 | kern_return_t |
81 | kcdata_add_container_marker(kcdata_descriptor_t data, uint32_t , uint32_t container_type, uint64_t identifier); |
82 | kern_return_t kcdata_add_type_definition(kcdata_descriptor_t data, |
83 | uint32_t type_id, |
84 | char * type_name, |
85 | struct kcdata_subtype_descriptor * elements_array_addr, |
86 | uint32_t elements_count); |
87 | |
88 | kern_return_t kcdata_add_uint64_with_description(kcdata_descriptor_t crashinfo, uint64_t data, const char * description); |
89 | kern_return_t kcdata_add_uint32_with_description(kcdata_descriptor_t crashinfo, uint32_t data, const char * description); |
90 | |
91 | kern_return_t kcdata_undo_add_container_begin(kcdata_descriptor_t data); |
92 | |
93 | kern_return_t kcdata_write_buffer_end(kcdata_descriptor_t data); |
94 | void *kcdata_memory_get_begin_addr(kcdata_descriptor_t data); |
95 | |
96 | #else /* XNU_KERNEL_PRIVATE */ |
97 | |
98 | typedef void * kcdata_descriptor_t; |
99 | |
100 | #endif /* XNU_KERNEL_PRIVATE */ |
101 | |
102 | uint32_t kcdata_estimate_required_buffer_size(uint32_t num_items, uint32_t payload_size); |
103 | uint64_t kcdata_memory_get_used_bytes(kcdata_descriptor_t kcd); |
104 | kern_return_t kcdata_memcpy(kcdata_descriptor_t data, mach_vm_address_t dst_addr, const void * src_addr, uint32_t size); |
105 | kern_return_t kcdata_bzero(kcdata_descriptor_t data, mach_vm_address_t dst_addr, uint32_t size); |
106 | kern_return_t kcdata_get_memory_addr(kcdata_descriptor_t data, uint32_t type, uint32_t size, mach_vm_address_t * user_addr); |
107 | kern_return_t kcdata_get_memory_addr_for_array( |
108 | kcdata_descriptor_t data, uint32_t type_of_element, uint32_t size_of_element, uint32_t count, mach_vm_address_t * user_addr); |
109 | |
110 | #endif /* KERNEL */ |
111 | #endif /* _KERN_CDATA_H_ */ |
112 | |