Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 1 | // Copyright 2016 The Fuchsia Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 5 | #ifndef SYSROOT_ZIRCON_SYSCALLS_OBJECT_H_ |
| 6 | #define SYSROOT_ZIRCON_SYSCALLS_OBJECT_H_ |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 7 | |
| 8 | #include <zircon/types.h> |
| 9 | |
| 10 | __BEGIN_CDECLS |
| 11 | |
| 12 | // ask clang format not to mess up the indentation: |
| 13 | // clang-format off |
| 14 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 15 | // Help macro for building versioned topics. Version is the upper 4 bits and starts counting at 0. |
| 16 | #define __ZX_INFO_TOPIC(t, v) ((zx_object_info_topic_t) ((t) | ((v) << 28))) |
| 17 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 18 | // Valid topics for zx_object_get_info. |
| 19 | typedef uint32_t zx_object_info_topic_t; |
| 20 | #define ZX_INFO_NONE ((zx_object_info_topic_t) 0u) |
| 21 | #define ZX_INFO_HANDLE_VALID ((zx_object_info_topic_t) 1u) |
| 22 | #define ZX_INFO_HANDLE_BASIC ((zx_object_info_topic_t) 2u) // zx_info_handle_basic_t[1] |
| 23 | #define ZX_INFO_PROCESS ((zx_object_info_topic_t) 3u) // zx_info_process_t[1] |
| 24 | #define ZX_INFO_PROCESS_THREADS ((zx_object_info_topic_t) 4u) // zx_koid_t[n] |
| 25 | #define ZX_INFO_VMAR ((zx_object_info_topic_t) 7u) // zx_info_vmar_t[1] |
| 26 | #define ZX_INFO_JOB_CHILDREN ((zx_object_info_topic_t) 8u) // zx_koid_t[n] |
| 27 | #define ZX_INFO_JOB_PROCESSES ((zx_object_info_topic_t) 9u) // zx_koid_t[n] |
| 28 | #define ZX_INFO_THREAD ((zx_object_info_topic_t) 10u) // zx_info_thread_t[1] |
| 29 | #define ZX_INFO_THREAD_EXCEPTION_REPORT ((zx_object_info_topic_t) 11u) // zx_exception_report_t[1] |
| 30 | #define ZX_INFO_TASK_STATS ((zx_object_info_topic_t) 12u) // zx_info_task_stats_t[1] |
| 31 | #define ZX_INFO_PROCESS_MAPS ((zx_object_info_topic_t) 13u) // zx_info_maps_t[n] |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 32 | #define ZX_INFO_PROCESS_VMOS_V1 __ZX_INFO_TOPIC(14u, 0) // zx_info_vmo_t[n] |
| 33 | #define ZX_INFO_PROCESS_VMOS __ZX_INFO_TOPIC(14u, 1) // zx_info_vmo_t[n] |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 34 | #define ZX_INFO_THREAD_STATS ((zx_object_info_topic_t) 15u) // zx_info_thread_stats_t[1] |
| 35 | #define ZX_INFO_CPU_STATS ((zx_object_info_topic_t) 16u) // zx_info_cpu_stats_t[n] |
| 36 | #define ZX_INFO_KMEM_STATS ((zx_object_info_topic_t) 17u) // zx_info_kmem_stats_t[1] |
| 37 | #define ZX_INFO_RESOURCE ((zx_object_info_topic_t) 18u) // zx_info_resource_t[1] |
| 38 | #define ZX_INFO_HANDLE_COUNT ((zx_object_info_topic_t) 19u) // zx_info_handle_count_t[1] |
| 39 | #define ZX_INFO_BTI ((zx_object_info_topic_t) 20u) // zx_info_bti_t[1] |
| 40 | #define ZX_INFO_PROCESS_HANDLE_STATS ((zx_object_info_topic_t) 21u) // zx_info_process_handle_stats_t[1] |
| 41 | #define ZX_INFO_SOCKET ((zx_object_info_topic_t) 22u) // zx_info_socket_t[1] |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 42 | #define ZX_INFO_VMO_V1 __ZX_INFO_TOPIC(23u, 0) // zx_info_vmo_t[1] |
| 43 | #define ZX_INFO_VMO __ZX_INFO_TOPIC(23u, 1) // zx_info_vmo_t[1] |
| 44 | #define ZX_INFO_JOB ((zx_object_info_topic_t) 24u) // zx_info_job_t[1] |
| 45 | #define ZX_INFO_TIMER ((zx_object_info_topic_t) 25u) // zx_info_timer_t[1] |
| 46 | #define ZX_INFO_STREAM ((zx_object_info_topic_t) 26u) // zx_info_stream_t[1] |
| 47 | #define ZX_INFO_HANDLE_TABLE ((zx_object_info_topic_t) 27u) // zx_info_handle_extended_t[n] |
| 48 | #define ZX_INFO_MSI ((zx_object_info_topic_t) 28u) // zx_info_msi_t[1] |
| 49 | #define ZX_INFO_GUEST_STATS ((zx_object_info_topic_t) 29u) // zx_info_guest_stats_t[1] |
| 50 | #define ZX_INFO_TASK_RUNTIME ((zx_object_info_topic_t) 30u) // zx_info_task_runtime_t[1] |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 51 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 52 | // Return codes set when a task is killed. |
| 53 | #define ZX_TASK_RETCODE_SYSCALL_KILL ((int64_t) -1024) // via zx_task_kill(). |
| 54 | #define ZX_TASK_RETCODE_OOM_KILL ((int64_t) -1025) // by the OOM killer. |
| 55 | #define ZX_TASK_RETCODE_POLICY_KILL ((int64_t) -1026) // by the Job policy. |
| 56 | #define ZX_TASK_RETCODE_VDSO_KILL ((int64_t) -1027) // by the VDSO. |
| 57 | #define ZX_TASK_RETCODE_EXCEPTION_KILL ((int64_t) -1028) // Exception not handled. |
| 58 | #define ZX_TASK_RETCODE_CRITICAL_PROCESS_KILL ((int64_t) -1029) // by a critical process. |
| 59 | |
| 60 | // Sentinel indicating an invalid or missing CPU. |
| 61 | #define ZX_INFO_INVALID_CPU ((uint32_t)0xFFFFFFFFu) |
| 62 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 63 | |
| 64 | typedef struct zx_info_handle_basic { |
| 65 | // The unique id assigned by kernel to the object referenced by the |
| 66 | // handle. |
| 67 | zx_koid_t koid; |
| 68 | |
| 69 | // The immutable rights assigned to the handle. Two handles that |
| 70 | // have the same koid and the same rights are equivalent and |
| 71 | // interchangeable. |
| 72 | zx_rights_t rights; |
| 73 | |
| 74 | // The object type: channel, event, socket, etc. |
| 75 | zx_obj_type_t type; |
| 76 | |
| 77 | // If the object referenced by the handle is related to another (such |
| 78 | // as the other end of a channel, or the parent of a job) then |
| 79 | // |related_koid| is the koid of that object, otherwise it is zero. |
| 80 | // This relationship is immutable: an object's |related_koid| does |
| 81 | // not change even if the related object no longer exists. |
| 82 | zx_koid_t related_koid; |
| 83 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 84 | uint32_t reserved; |
| 85 | |
| 86 | uint8_t padding1[4]; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 87 | } zx_info_handle_basic_t; |
| 88 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 89 | typedef struct zx_info_handle_extended { |
| 90 | // The object type: channel, event, socket, etc. |
| 91 | zx_obj_type_t type; |
| 92 | |
| 93 | // The handle value which is only valid for the process which |
| 94 | // was passed to ZX_INFO_HANDLE_TABLE. |
| 95 | zx_handle_t handle_value; |
| 96 | |
| 97 | // The immutable rights assigned to the handle. Two handles that |
| 98 | // have the same koid and the same rights are equivalent and |
| 99 | // interchangeable. |
| 100 | zx_rights_t rights; |
| 101 | |
| 102 | uint32_t reserved; |
| 103 | |
| 104 | // The unique id assigned by kernel to the object referenced by the |
| 105 | // handle. |
| 106 | zx_koid_t koid; |
| 107 | |
| 108 | // If the object referenced by the handle is related to another (such |
| 109 | // as the other end of a channel, or the parent of a job) then |
| 110 | // |related_koid| is the koid of that object, otherwise it is zero. |
| 111 | // This relationship is immutable: an object's |related_koid| does |
| 112 | // not change even if the related object no longer exists. |
| 113 | zx_koid_t related_koid; |
| 114 | |
| 115 | // If the object referenced by the handle has a peer, like the |
| 116 | // other end of a channel, then this is the koid of the process |
| 117 | // which currently owns it. This value is not stable; the process |
| 118 | // can change the owner at any moment. |
| 119 | // |
| 120 | // This is currently unimplemented and contains 0. |
| 121 | zx_koid_t peer_owner_koid; |
| 122 | } zx_info_handle_extended_t; |
| 123 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 124 | typedef struct zx_info_handle_count { |
| 125 | // The number of outstanding handles to a kernel object. |
| 126 | uint32_t handle_count; |
| 127 | } zx_info_handle_count_t; |
| 128 | |
| 129 | typedef struct zx_info_process_handle_stats { |
| 130 | // The number of outstanding handles to kernel objects of each type. |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 131 | uint32_t handle_count[ZX_OBJ_TYPE_UPPER_BOUND]; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 132 | } zx_info_process_handle_stats_t; |
| 133 | |
| 134 | typedef struct zx_info_process { |
| 135 | // The process's return code; only valid if |exited| is true. |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 136 | // If the process was killed, it will be one of the ZX_TASK_RETCODE values. |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 137 | int64_t return_code; |
| 138 | |
| 139 | // True if the process has ever left the initial creation state, |
| 140 | // even if it has exited as well. |
| 141 | bool started; |
| 142 | |
| 143 | // If true, the process has exited and |return_code| is valid. |
| 144 | bool exited; |
| 145 | |
| 146 | // True if a debugger is attached to the process. |
| 147 | bool debugger_attached; |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 148 | |
| 149 | uint8_t padding1[5]; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 150 | } zx_info_process_t; |
| 151 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 152 | typedef struct zx_info_job { |
| 153 | // The job's return code; only valid if |exited| is true. |
| 154 | // If the process was killed, it will be one of the ZX_TASK_RETCODE values. |
| 155 | int64_t return_code; |
| 156 | |
| 157 | // If true, the job has exited and |return_code| is valid. |
| 158 | bool exited; |
| 159 | |
| 160 | // True if the ZX_PROP_JOB_KILL_ON_OOM was set. |
| 161 | bool kill_on_oom; |
| 162 | |
| 163 | // True if a debugger is attached to the job. |
| 164 | bool debugger_attached; |
| 165 | |
| 166 | uint8_t padding1[5]; |
| 167 | } zx_info_job_t; |
| 168 | |
| 169 | typedef struct zx_info_timer { |
| 170 | // The options passed to zx_timer_create(). |
| 171 | uint32_t options; |
| 172 | |
| 173 | uint8_t padding1[4]; |
| 174 | |
| 175 | // The deadline with respect to ZX_CLOCK_MONOTONIC at which the timer will |
| 176 | // fire next. |
| 177 | // |
| 178 | // This value will be zero if the timer is not set to fire. |
| 179 | zx_time_t deadline; |
| 180 | |
| 181 | // Specifies a range from deadline - slack to deadline + slack during which |
| 182 | // the timer is allowed to fire. The system uses this parameter as a hint to |
| 183 | // coalesce nearby timers. |
| 184 | // |
| 185 | // The precise coalescing behavior is controlled by the options parameter |
| 186 | // specified when the timer was created. |
| 187 | // |
| 188 | // This value will be zero if the timer is not set to fire. |
| 189 | zx_duration_t slack; |
| 190 | } zx_info_timer_t; |
| 191 | |
| 192 | typedef struct zx_info_stream { |
| 193 | // The options passed to zx_stream_create(). |
| 194 | uint32_t options; |
| 195 | |
| 196 | uint8_t padding1[4]; |
| 197 | |
| 198 | // The current seek offset. |
| 199 | // |
| 200 | // Used by zx_stream_readv and zx_stream_writev to determine where to read |
| 201 | // and write the stream. |
| 202 | zx_off_t seek; |
| 203 | |
| 204 | // The current size of the stream. |
| 205 | // |
| 206 | // The number of bytes in the stream that store data. The stream itself |
| 207 | // might have a larger capacity to avoid reallocating the underlying storage |
| 208 | // as the stream grows or shrinks. |
| 209 | uint64_t content_size; |
| 210 | } zx_info_stream_t; |
| 211 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 212 | typedef uint32_t zx_thread_state_t; |
| 213 | |
| 214 | typedef struct zx_info_thread { |
| 215 | // One of ZX_THREAD_STATE_* values. |
| 216 | zx_thread_state_t state; |
| 217 | |
| 218 | // If |state| is ZX_THREAD_STATE_BLOCKED_EXCEPTION, the thread has gotten |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 219 | // an exception and is waiting for the exception response from the specified |
| 220 | // handler. |
| 221 | |
| 222 | // The value is one of ZX_EXCEPTION_CHANNEL_TYPE_*. |
| 223 | uint32_t wait_exception_channel_type; |
| 224 | |
| 225 | // CPUs this thread may be scheduled on, as specified by |
| 226 | // a profile object applied to this thread. |
| 227 | // |
| 228 | // The kernel may not internally store invalid CPUs in the mask, so |
| 229 | // this may not exactly match the mask applied to the thread for |
| 230 | // CPUs beyond what the system is able to use. |
| 231 | zx_cpu_set_t cpu_affinity_mask; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 232 | } zx_info_thread_t; |
| 233 | |
| 234 | typedef struct zx_info_thread_stats { |
| 235 | // Total accumulated running time of the thread. |
| 236 | zx_duration_t total_runtime; |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 237 | |
| 238 | // CPU number that this thread was last scheduled on, or ZX_INFO_INVALID_CPU |
| 239 | // if the thread has never been scheduled on a CPU. By the time this call |
| 240 | // returns, the thread may have been scheduled elsewhere, so this |
| 241 | // information should only be used as a hint or for statistics. |
| 242 | uint32_t last_scheduled_cpu; |
| 243 | |
| 244 | uint8_t padding1[4]; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 245 | } zx_info_thread_stats_t; |
| 246 | |
| 247 | // Statistics about resources (e.g., memory) used by a task. Can be relatively |
| 248 | // expensive to gather. |
| 249 | typedef struct zx_info_task_stats { |
| 250 | // The total size of mapped memory ranges in the task. |
| 251 | // Not all will be backed by physical memory. |
| 252 | size_t mem_mapped_bytes; |
| 253 | |
| 254 | // For the fields below, a byte is considered committed if it's backed by |
| 255 | // physical memory. Some of the memory may be double-mapped, and thus |
| 256 | // double-counted. |
| 257 | |
| 258 | // Committed memory that is only mapped into this task. |
| 259 | size_t mem_private_bytes; |
| 260 | |
| 261 | // Committed memory that is mapped into this and at least one other task. |
| 262 | size_t mem_shared_bytes; |
| 263 | |
| 264 | // A number that estimates the fraction of mem_shared_bytes that this |
| 265 | // task is responsible for keeping alive. |
| 266 | // |
| 267 | // An estimate of: |
| 268 | // For each shared, committed byte: |
| 269 | // mem_scaled_shared_bytes += 1 / (number of tasks mapping this byte) |
| 270 | // |
| 271 | // This number is strictly smaller than mem_shared_bytes. |
| 272 | size_t mem_scaled_shared_bytes; |
| 273 | } zx_info_task_stats_t; |
| 274 | |
| 275 | typedef struct zx_info_vmar { |
| 276 | // Base address of the region. |
| 277 | uintptr_t base; |
| 278 | |
| 279 | // Length of the region, in bytes. |
| 280 | size_t len; |
| 281 | } zx_info_vmar_t; |
| 282 | |
| 283 | typedef struct zx_info_bti { |
| 284 | // zx_bti_pin will always be able to return addresses that are contiguous for at |
| 285 | // least this many bytes. E.g. if this returns 1MB, then a call to |
| 286 | // zx_bti_pin() with a size of 2MB will return at most two physically-contiguous runs. |
| 287 | // If the size were 2.5MB, it will return at most three physically-contiguous runs. |
| 288 | uint64_t minimum_contiguity; |
| 289 | |
| 290 | // The number of bytes in the device's address space (UINT64_MAX if 2^64). |
| 291 | uint64_t aspace_size; |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 292 | |
| 293 | // The count of the pinned memory object tokens. Requesting this count is |
| 294 | // racy, so this should only be used for informative reasons. |
| 295 | uint64_t pmo_count; |
| 296 | |
| 297 | // The count of the quarantined pinned memory object tokens. Requesting this count is |
| 298 | // racy, so this should only be used for informative reasons. |
| 299 | uint64_t quarantine_count; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 300 | } zx_info_bti_t; |
| 301 | |
| 302 | typedef struct zx_info_socket { |
| 303 | // The options passed to zx_socket_create(). |
| 304 | uint32_t options; |
| 305 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 306 | uint8_t padding1[4]; |
| 307 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 308 | // The maximum size of the receive buffer of a socket, in bytes. |
| 309 | // |
| 310 | // The receive buffer may become full at a capacity less than the maximum |
| 311 | // due to overhead. |
| 312 | size_t rx_buf_max; |
| 313 | |
| 314 | // The size of the receive buffer of a socket, in bytes. |
| 315 | size_t rx_buf_size; |
| 316 | |
| 317 | // The amount of data, in bytes, that is available for reading in a single |
| 318 | // zx_socket_read call. |
| 319 | // |
| 320 | // For stream sockets, this value will match |rx_buf_size|. For datagram |
| 321 | // sockets, this value will be the size of the next datagram in the receive |
| 322 | // buffer. |
| 323 | size_t rx_buf_available; |
| 324 | |
| 325 | // The maximum size of the transmit buffer of a socket, in bytes. |
| 326 | // |
| 327 | // The transmit buffer may become full at a capacity less than the maximum |
| 328 | // due to overhead. |
| 329 | // |
| 330 | // Will be zero if the peer endpoint is closed. |
| 331 | size_t tx_buf_max; |
| 332 | |
| 333 | // The size of the transmit buffer of a socket, in bytes. |
| 334 | // |
| 335 | // Will be zero if the peer endpoint is closed. |
| 336 | size_t tx_buf_size; |
| 337 | } zx_info_socket_t; |
| 338 | |
| 339 | // Types and values used by ZX_INFO_PROCESS_MAPS. |
| 340 | |
| 341 | // Describes a VM mapping. |
| 342 | typedef struct zx_info_maps_mapping { |
| 343 | // MMU flags for the mapping. |
| 344 | // Bitwise OR of ZX_VM_PERM_{READ,WRITE,EXECUTE} values. |
| 345 | zx_vm_option_t mmu_flags; |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 346 | uint8_t padding1[4]; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 347 | // koid of the mapped VMO. |
| 348 | zx_koid_t vmo_koid; |
| 349 | // Offset into the above VMO. |
| 350 | uint64_t vmo_offset; |
| 351 | // The number of PAGE_SIZE pages in the mapped region of the VMO |
| 352 | // that are backed by physical memory. |
| 353 | size_t committed_pages; |
| 354 | } zx_info_maps_mapping_t; |
| 355 | |
| 356 | // Types of entries represented by zx_info_maps_t. |
| 357 | // Can't use zx_obj_type_t because not all of these are |
| 358 | // user-visible kernel object types. |
| 359 | typedef uint32_t zx_info_maps_type_t; |
| 360 | #define ZX_INFO_MAPS_TYPE_NONE ((zx_info_maps_type_t) 0u) |
| 361 | #define ZX_INFO_MAPS_TYPE_ASPACE ((zx_info_maps_type_t) 1u) |
| 362 | #define ZX_INFO_MAPS_TYPE_VMAR ((zx_info_maps_type_t) 2u) |
| 363 | #define ZX_INFO_MAPS_TYPE_MAPPING ((zx_info_maps_type_t) 3u) |
| 364 | |
| 365 | // Describes a node in the aspace/vmar/mapping hierarchy for a user process. |
| 366 | typedef struct zx_info_maps { |
| 367 | // Name if available; empty string otherwise. |
| 368 | char name[ZX_MAX_NAME_LEN]; |
| 369 | // Base address. |
| 370 | zx_vaddr_t base; |
| 371 | // Size in bytes. |
| 372 | size_t size; |
| 373 | |
| 374 | // The depth of this node in the tree. |
| 375 | // Can be used for indentation, or to rebuild the tree from an array |
| 376 | // of zx_info_maps_t entries, which will be in depth-first pre-order. |
| 377 | size_t depth; |
| 378 | // The type of this entry; indicates which union entry is valid. |
| 379 | zx_info_maps_type_t type; |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 380 | uint8_t padding1[4]; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 381 | union { |
| 382 | zx_info_maps_mapping_t mapping; |
| 383 | // No additional fields for other types. |
| 384 | } u; |
| 385 | } zx_info_maps_t; |
| 386 | |
| 387 | |
| 388 | // Values and types used by ZX_INFO_PROCESS_VMOS. |
| 389 | |
| 390 | // The VMO is backed by RAM, consuming memory. |
| 391 | // Mutually exclusive with ZX_INFO_VMO_TYPE_PHYSICAL. |
| 392 | // See ZX_INFO_VMO_TYPE(flags) |
| 393 | #define ZX_INFO_VMO_TYPE_PAGED (1u<<0) |
| 394 | |
| 395 | // The VMO points to a physical address range, and does not consume memory. |
| 396 | // Typically used to access memory-mapped hardware. |
| 397 | // Mutually exclusive with ZX_INFO_VMO_TYPE_PAGED. |
| 398 | // See ZX_INFO_VMO_TYPE(flags) |
| 399 | #define ZX_INFO_VMO_TYPE_PHYSICAL (0u<<0) |
| 400 | |
| 401 | // Returns a VMO's type based on its flags, allowing for checks like |
| 402 | // if (ZX_INFO_VMO_TYPE(f) == ZX_INFO_VMO_TYPE_PAGED) |
| 403 | #define ZX_INFO_VMO_TYPE(flags) ((flags) & (1u<<0)) |
| 404 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 405 | // The VMO is resizable. |
| 406 | #define ZX_INFO_VMO_RESIZABLE (1u<<1) |
| 407 | |
| 408 | // The VMO is a child, and is a copy-on-write clone. |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 409 | #define ZX_INFO_VMO_IS_COW_CLONE (1u<<2) |
| 410 | |
| 411 | // When reading a list of VMOs pointed to by a process, indicates that the |
| 412 | // process has a handle to the VMO, which isn't necessarily mapped. |
| 413 | #define ZX_INFO_VMO_VIA_HANDLE (1u<<3) |
| 414 | |
| 415 | // When reading a list of VMOs pointed to by a process, indicates that the |
| 416 | // process maps the VMO into a VMAR, but doesn't necessarily have a handle to |
| 417 | // the VMO. |
| 418 | #define ZX_INFO_VMO_VIA_MAPPING (1u<<4) |
| 419 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 420 | // The VMO is a pager owned VMO created by zx_pager_create_vmo or is |
| 421 | // a clone of a VMO with this flag set. Will only be set on VMOs with |
| 422 | // the ZX_INFO_VMO_TYPE_PAGED flag set. |
| 423 | #define ZX_INFO_VMO_PAGER_BACKED (1u<<5) |
| 424 | |
| 425 | // The VMO is contiguous |
| 426 | #define ZX_INFO_VMO_CONTIGUOUS (1u<<6) |
| 427 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 428 | // Describes a VMO. For mapping information, see |zx_info_maps_t|. |
| 429 | typedef struct zx_info_vmo { |
| 430 | // The koid of this VMO. |
| 431 | zx_koid_t koid; |
| 432 | |
| 433 | // The name of this VMO. |
| 434 | char name[ZX_MAX_NAME_LEN]; |
| 435 | |
| 436 | // The size of this VMO; i.e., the amount of virtual address space it |
| 437 | // would consume if mapped. |
| 438 | uint64_t size_bytes; |
| 439 | |
| 440 | // If this VMO is a clone, the koid of its parent. Otherwise, zero. |
| 441 | // See |flags| for the type of clone. |
| 442 | zx_koid_t parent_koid; |
| 443 | |
| 444 | // The number of clones of this VMO, if any. |
| 445 | size_t num_children; |
| 446 | |
| 447 | // The number of times this VMO is currently mapped into VMARs. |
| 448 | // Note that the same process will often map the same VMO twice, |
| 449 | // and both mappings will be counted here. (I.e., this is not a count |
| 450 | // of the number of processes that map this VMO; see share_count.) |
| 451 | size_t num_mappings; |
| 452 | |
| 453 | // An estimate of the number of unique address spaces that |
| 454 | // this VMO is mapped into. Every process has its own address space, |
| 455 | // and so does the kernel. |
| 456 | size_t share_count; |
| 457 | |
| 458 | // Bitwise OR of ZX_INFO_VMO_* values. |
| 459 | uint32_t flags; |
| 460 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 461 | uint8_t padding1[4]; |
| 462 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 463 | // If |ZX_INFO_VMO_TYPE(flags) == ZX_INFO_VMO_TYPE_PAGED|, the amount of |
| 464 | // memory currently allocated to this VMO; i.e., the amount of physical |
| 465 | // memory it consumes. Undefined otherwise. |
| 466 | uint64_t committed_bytes; |
| 467 | |
| 468 | // If |flags & ZX_INFO_VMO_VIA_HANDLE|, the handle rights. |
| 469 | // Undefined otherwise. |
| 470 | zx_rights_t handle_rights; |
| 471 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 472 | // VMO mapping cache policy. One of ZX_CACHE_POLICY_* |
| 473 | uint32_t cache_policy; |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 474 | |
| 475 | // Amount of kernel memory, in bytes, allocated to track metadata |
| 476 | // associated with this VMO. |
| 477 | uint64_t metadata_bytes; |
| 478 | |
| 479 | // Running counter of the number of times the kernel, without user request, |
| 480 | // performed actions on this VMO that would have caused |committed_bytes| to |
| 481 | // report a different value. |
| 482 | uint64_t committed_change_events; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 483 | } zx_info_vmo_t; |
| 484 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 485 | typedef struct zx_info_vmo_v1 { |
| 486 | zx_koid_t koid; |
| 487 | char name[ZX_MAX_NAME_LEN]; |
| 488 | uint64_t size_bytes; |
| 489 | zx_koid_t parent_koid; |
| 490 | size_t num_children; |
| 491 | size_t num_mappings; |
| 492 | size_t share_count; |
| 493 | uint32_t flags; |
| 494 | uint8_t padding1[4]; |
| 495 | uint64_t committed_bytes; |
| 496 | zx_rights_t handle_rights; |
| 497 | uint32_t cache_policy; |
| 498 | } zx_info_vmo_v1_t; |
| 499 | |
| 500 | typedef struct zx_info_guest_stats { |
| 501 | uint32_t cpu_number; |
| 502 | uint32_t flags; |
| 503 | |
| 504 | uint64_t vm_entries; |
| 505 | uint64_t vm_exits; |
| 506 | #ifdef __aarch64__ |
| 507 | uint64_t wfi_wfe_instructions; |
| 508 | uint64_t instruction_aborts; |
| 509 | uint64_t data_aborts; |
| 510 | uint64_t system_instructions; |
| 511 | uint64_t smc_instructions; |
| 512 | uint64_t interrupts; |
| 513 | #else |
| 514 | uint64_t interrupts; |
| 515 | uint64_t interrupt_windows; |
| 516 | uint64_t cpuid_instructions; |
| 517 | uint64_t hlt_instructions; |
| 518 | uint64_t control_register_accesses; |
| 519 | uint64_t io_instructions; |
| 520 | uint64_t rdmsr_instructions; |
| 521 | uint64_t wrmsr_instructions; |
| 522 | uint64_t ept_violations; |
| 523 | uint64_t xsetbv_instructions; |
| 524 | uint64_t pause_instructions; |
| 525 | uint64_t vmcall_instructions; |
| 526 | #endif |
| 527 | } zx_info_guest_stats_t; |
| 528 | |
| 529 | // Info on the runtime of a task. |
| 530 | typedef struct zx_info_task_runtime { |
| 531 | // The total amount of time this task and its children were running. |
| 532 | // * Threads include only their own runtime. |
| 533 | // * Processes include the runtime for all of their threads (including threads that previously |
| 534 | // exited). |
| 535 | // * Jobs include the runtime for all of their processes (including processes that previously |
| 536 | // exited). |
| 537 | zx_duration_t cpu_time; |
| 538 | |
| 539 | // The total amount of time this task and its children were queued to run. |
| 540 | // * Threads include only their own queue time. |
| 541 | // * Processes include the queue time for all of their threads (including threads that |
| 542 | // previously exited). |
| 543 | // * Jobs include the queue time for all of their processes (including processes that previously |
| 544 | // exited). |
| 545 | zx_duration_t queue_time; |
| 546 | } zx_info_task_runtime_t; |
| 547 | |
| 548 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 549 | // kernel statistics per cpu |
| 550 | // TODO(cpu), expose the deprecated stats via a new syscall. |
| 551 | typedef struct zx_info_cpu_stats { |
| 552 | uint32_t cpu_number; |
| 553 | uint32_t flags; |
| 554 | |
| 555 | zx_duration_t idle_time; |
| 556 | |
| 557 | // kernel scheduler counters |
| 558 | uint64_t reschedules; |
| 559 | uint64_t context_switches; |
| 560 | uint64_t irq_preempts; |
| 561 | uint64_t preempts; |
| 562 | uint64_t yields; |
| 563 | |
| 564 | // cpu level interrupts and exceptions |
| 565 | uint64_t ints; // hardware interrupts, minus timer interrupts or inter-processor interrupts |
| 566 | uint64_t timer_ints; // timer interrupts |
| 567 | uint64_t timers; // timer callbacks |
| 568 | uint64_t page_faults; // (deprecated, returns 0) page faults |
| 569 | uint64_t exceptions; // (deprecated, returns 0) exceptions such as undefined opcode |
| 570 | uint64_t syscalls; |
| 571 | |
| 572 | // inter-processor interrupts |
| 573 | uint64_t reschedule_ipis; |
| 574 | uint64_t generic_ipis; |
| 575 | } zx_info_cpu_stats_t; |
| 576 | |
| 577 | // Information about kernel memory usage. |
| 578 | // Can be expensive to gather. |
| 579 | typedef struct zx_info_kmem_stats { |
| 580 | // The total amount of physical memory available to the system. |
| 581 | uint64_t total_bytes; |
| 582 | |
| 583 | // The amount of unallocated memory. |
| 584 | uint64_t free_bytes; |
| 585 | |
| 586 | // The amount of memory reserved by and mapped into the kernel for reasons |
| 587 | // not covered by other fields in this struct. Typically for readonly data |
| 588 | // like the ram disk and kernel image, and for early-boot dynamic memory. |
| 589 | uint64_t wired_bytes; |
| 590 | |
| 591 | // The amount of memory allocated to the kernel heap. |
| 592 | uint64_t total_heap_bytes; |
| 593 | |
| 594 | // The portion of |total_heap_bytes| that is not in use. |
| 595 | uint64_t free_heap_bytes; |
| 596 | |
| 597 | // The amount of memory committed to VMOs, both kernel and user. |
| 598 | // A superset of all userspace memory. |
| 599 | // Does not include certain VMOs that fall under |wired_bytes|. |
| 600 | // |
| 601 | // TODO(dbort): Break this into at least two pieces: userspace VMOs that |
| 602 | // have koids, and kernel VMOs that don't. Or maybe look at VMOs |
| 603 | // mapped into the kernel aspace vs. everything else. |
| 604 | uint64_t vmo_bytes; |
| 605 | |
| 606 | // The amount of memory used for architecture-specific MMU metadata |
| 607 | // like page tables. |
| 608 | uint64_t mmu_overhead_bytes; |
| 609 | |
| 610 | // The amount of memory in use by IPC. |
| 611 | uint64_t ipc_bytes; |
| 612 | |
| 613 | // Non-free memory that isn't accounted for in any other field. |
| 614 | uint64_t other_bytes; |
| 615 | } zx_info_kmem_stats_t; |
| 616 | |
| 617 | typedef struct zx_info_resource { |
| 618 | // The resource kind; resource object kinds are detailed in the resource.md |
| 619 | uint32_t kind; |
| 620 | // Resource's creation flags |
| 621 | uint32_t flags; |
| 622 | // Resource's base value (inclusive) |
| 623 | uint64_t base; |
| 624 | // Resource's length value |
| 625 | size_t size; |
| 626 | char name[ZX_MAX_NAME_LEN]; |
| 627 | } zx_info_resource_t; |
| 628 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 629 | typedef struct zx_info_msi { |
| 630 | // The target adress for write transactions. |
| 631 | uint64_t target_addr; |
| 632 | // The data that the device will write when triggering an IRQ. |
| 633 | uint32_t target_data; |
| 634 | // The first IRQ in the allocated block. |
| 635 | uint32_t base_irq_id; |
| 636 | // The number of IRQs in the allocated block. |
| 637 | uint32_t num_irq; |
| 638 | // The number of outstanding interrupt objects created off this Msi object. |
| 639 | uint32_t interrupt_count; |
| 640 | } zx_info_msi_t; |
| 641 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 642 | #define ZX_INFO_CPU_STATS_FLAG_ONLINE (1u<<0) |
| 643 | |
| 644 | // Object properties. |
| 645 | |
| 646 | // Argument is a char[ZX_MAX_NAME_LEN]. |
| 647 | #define ZX_PROP_NAME ((uint32_t) 3u) |
| 648 | |
| 649 | #if __x86_64__ |
| 650 | // Argument is a uintptr_t. |
| 651 | #define ZX_PROP_REGISTER_GS ((uint32_t) 2u) |
| 652 | #define ZX_PROP_REGISTER_FS ((uint32_t) 4u) |
| 653 | #endif |
| 654 | |
| 655 | // Argument is the value of ld.so's _dl_debug_addr, a uintptr_t. If the |
| 656 | // property is set to the magic value of ZX_PROCESS_DEBUG_ADDR_BREAK_ON_SET |
| 657 | // on process startup, ld.so will trigger a debug breakpoint immediately after |
| 658 | // setting the property to the correct value. |
| 659 | #define ZX_PROP_PROCESS_DEBUG_ADDR ((uint32_t) 5u) |
| 660 | #define ZX_PROCESS_DEBUG_ADDR_BREAK_ON_SET ((uintptr_t) 1u) |
| 661 | |
| 662 | // Argument is the base address of the vDSO mapping (or zero), a uintptr_t. |
| 663 | #define ZX_PROP_PROCESS_VDSO_BASE_ADDRESS ((uint32_t) 6u) |
| 664 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 665 | // Whether the dynamic loader should issue a debug trap when loading a shared library, |
| 666 | // either initially or when running (e.g. dlopen). |
| 667 | // |
| 668 | // See docs/reference/syscalls/object_get_property.md |
| 669 | // See third_party/ulib/musl/ldso/dynlink.c. |
| 670 | #define ZX_PROP_PROCESS_BREAK_ON_LOAD ((uint32_t) 7u) |
| 671 | |
| 672 | // The process's context id as recorded by h/w instruction tracing, a uintptr_t. |
| 673 | // On X86 this is the cr3 value. |
| 674 | // TODO(dje): Wasn't sure whether the gaps in property numbers are unusable |
| 675 | // due to being old dleeted values. For now I just picked something. |
| 676 | #define ZX_PROP_PROCESS_HW_TRACE_CONTEXT_ID ((uint32_t) 8u) |
| 677 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 678 | // Argument is a size_t. |
| 679 | #define ZX_PROP_SOCKET_RX_THRESHOLD 12u |
| 680 | #define ZX_PROP_SOCKET_TX_THRESHOLD 13u |
| 681 | |
| 682 | // Terminate this job if the system is low on memory. |
| 683 | #define ZX_PROP_JOB_KILL_ON_OOM 15u |
| 684 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 685 | // Exception close behavior. |
| 686 | #define ZX_PROP_EXCEPTION_STATE 16u |
| 687 | |
| 688 | // The size of the content in a VMO, in bytes. |
| 689 | // |
| 690 | // The content size of a VMO can be larger or smaller than the actual size of |
| 691 | // the VMO. |
| 692 | // |
| 693 | // Argument is a uint64_t. |
| 694 | #define ZX_PROP_VMO_CONTENT_SIZE 17u |
| 695 | |
| 696 | // How an exception should be handled. |
| 697 | // See //docs/concepts/kernel/exceptions.md. |
| 698 | #define ZX_PROP_EXCEPTION_STRATEGY 18u |
| 699 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 700 | // Basic thread states, in zx_info_thread_t.state. |
| 701 | #define ZX_THREAD_STATE_NEW ((zx_thread_state_t) 0x0000u) |
| 702 | #define ZX_THREAD_STATE_RUNNING ((zx_thread_state_t) 0x0001u) |
| 703 | #define ZX_THREAD_STATE_SUSPENDED ((zx_thread_state_t) 0x0002u) |
| 704 | // ZX_THREAD_STATE_BLOCKED is never returned by itself. |
| 705 | // It is always returned with a more precise reason. |
| 706 | // See ZX_THREAD_STATE_BLOCKED_* below. |
| 707 | #define ZX_THREAD_STATE_BLOCKED ((zx_thread_state_t) 0x0003u) |
| 708 | #define ZX_THREAD_STATE_DYING ((zx_thread_state_t) 0x0004u) |
| 709 | #define ZX_THREAD_STATE_DEAD ((zx_thread_state_t) 0x0005u) |
| 710 | |
| 711 | // More precise thread states. |
| 712 | #define ZX_THREAD_STATE_BLOCKED_EXCEPTION ((zx_thread_state_t) 0x0103u) |
| 713 | #define ZX_THREAD_STATE_BLOCKED_SLEEPING ((zx_thread_state_t) 0x0203u) |
| 714 | #define ZX_THREAD_STATE_BLOCKED_FUTEX ((zx_thread_state_t) 0x0303u) |
| 715 | #define ZX_THREAD_STATE_BLOCKED_PORT ((zx_thread_state_t) 0x0403u) |
| 716 | #define ZX_THREAD_STATE_BLOCKED_CHANNEL ((zx_thread_state_t) 0x0503u) |
| 717 | #define ZX_THREAD_STATE_BLOCKED_WAIT_ONE ((zx_thread_state_t) 0x0603u) |
| 718 | #define ZX_THREAD_STATE_BLOCKED_WAIT_MANY ((zx_thread_state_t) 0x0703u) |
| 719 | #define ZX_THREAD_STATE_BLOCKED_INTERRUPT ((zx_thread_state_t) 0x0803u) |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 720 | #define ZX_THREAD_STATE_BLOCKED_PAGER ((zx_thread_state_t) 0x0903u) |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 721 | |
| 722 | // Reduce possibly-more-precise state to a basic state. |
| 723 | // Useful if, for example, you want to check for BLOCKED on anything. |
| 724 | #define ZX_THREAD_STATE_BASIC(n) ((n) & 0xff) |
| 725 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 726 | // How a thread should behave when the current exception is closed. |
| 727 | // ZX_PROP_EXCEPTION_STATE values. |
| 728 | #define ZX_EXCEPTION_STATE_TRY_NEXT 0u |
| 729 | #define ZX_EXCEPTION_STATE_HANDLED 1u |
| 730 | |
| 731 | // How an exception should be handled |
| 732 | // ZX_PROP_EXCEPTION_STRATEGY values. |
| 733 | #define ZX_EXCEPTION_STRATEGY_FIRST_CHANCE 0u |
| 734 | #define ZX_EXCEPTION_STRATEGY_SECOND_CHANCE 1u |
| 735 | |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 736 | __END_CDECLS |
| 737 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 738 | #endif // SYSROOT_ZIRCON_SYSCALLS_OBJECT_H_ |