2  * Copyright (c) 2019 Apple Inc. All rights reserved. 
   4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 
   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. 
  15  * Please obtain a copy of the License at 
  16  * http://www.opensource.apple.com/apsl/ and read it before using this file. 
  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. 
  26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 
  29 #ifndef _KERN_RESTARTABLE_H_ 
  30 #define _KERN_RESTARTABLE_H_ 
  32 #include <sys/cdefs.h> 
  33 #include <mach/message.h> 
  34 #include <mach/task.h> 
  39  * @typedef task_restartable_range_t 
  42  * Describes a userspace recoverable range. 
  45  * The pointer to the beginning of a restartable section. 
  48  * The length of the critical section anchored at location. 
  50  * @field recovery_offs 
  51  * The offset from the initial location that should be used for the recovery 
  55  * Currently unused, pass 0. 
  58         mach_vm_address_t location
; 
  59         unsigned short    length
; 
  60         unsigned short    recovery_offs
; 
  62 } task_restartable_range_t
; 
  64 typedef task_restartable_range_t 
*task_restartable_range_array_t
; 
  67  * @function task_restartable_ranges_register 
  70  * Register a set of restartable ranges for the current task. 
  73  * The task to operate on 
  76  * An array of address ranges for which PC resets are performed. 
  79  * The number of address ranges. 
  82  * - KERN_SUCCESS on success 
  83  * - KERN_FAILURE if the task isn't the current one 
  84  * - KERN_INVALID_ARGUMENT for various invalid inputs 
  85  * - KERN_NOT_SUPPORTED the request is not supported (second registration on 
  86  *   release kernels, registration when the task has gone wide) 
  87  * - KERN_RESOURCE_SHORTAGE if not enough memory 
  89 extern kern_return_t 
task_restartable_ranges_register( 
  91         task_restartable_range_array_t ranges
, 
  92         mach_msg_type_number_t         count
); 
  95  * @function task_restartable_ranges_synchronize 
  98  * Require for all threads in the task to reset their PC 
  99  * if within a restartable range. 
 102  * The task to operate on (needs to be current task) 
 106  * - KERN_FAILURE if the task isn't the current one 
 108 extern kern_return_t 
task_restartable_ranges_synchronize(task_t task
); 
 111  * @const TASK_RESTARTABLE_OFFSET_MAX 
 112  * The maximum value length / recovery_offs can have. 
 114 #define TASK_RESTARTABLE_OFFSET_MAX  4096u 
 116 #ifdef KERNEL_PRIVATE 
 118 struct restartable_ranges
; 
 121  * @function restartable_init 
 124  * Initializes the restartable module. 
 126 extern void restartable_init(void); 
 129  * @function restartable_ranges_release 
 132  * Release a reference on a restartable range. 
 134 extern void restartable_ranges_release(struct restartable_ranges 
*ranges
); 
 137  * @function thread_reset_pcs_ast 
 140  * Perform the work at the AST boundary to reset thread PCS. 
 142 extern void thread_reset_pcs_ast(struct thread 
*thread
); 
 144 #endif // KERNEL_PRIVATE 
 148 #endif  /* _KERN_RESTARTABLE_H_ */