restartable.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (c) 2019 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. #ifndef _KERN_RESTARTABLE_H_
  29. #define _KERN_RESTARTABLE_H_
  30. #include <sys/cdefs.h>
  31. #include <mach/message.h>
  32. #include <mach/task.h>
  33. __BEGIN_DECLS
  34. /*!
  35. * @typedef task_restartable_range_t
  36. *
  37. * @brief
  38. * Describes a userspace recoverable range.
  39. *
  40. * @field location
  41. * The pointer to the beginning of a restartable section.
  42. *
  43. * @field length
  44. * The length of the critical section anchored at location.
  45. *
  46. * @field recovery_offs
  47. * The offset from the initial location that should be used for the recovery
  48. * codepath.
  49. *
  50. * @field flags
  51. * Currently unused, pass 0.
  52. */
  53. typedef struct {
  54. mach_vm_address_t location;
  55. unsigned short length;
  56. unsigned short recovery_offs;
  57. unsigned int flags;
  58. } task_restartable_range_t;
  59. typedef task_restartable_range_t *task_restartable_range_array_t;
  60. /*!
  61. * @function task_restartable_ranges_register
  62. *
  63. * @brief
  64. * Register a set of restartable ranges for the current task.
  65. *
  66. * @param task
  67. * The task to operate on
  68. *
  69. * @param ranges
  70. * An array of address ranges for which PC resets are performed.
  71. *
  72. * @param count
  73. * The number of address ranges.
  74. *
  75. * @returns
  76. * - KERN_SUCCESS on success
  77. * - KERN_FAILURE if the task isn't the current one
  78. * - KERN_INVALID_ARGUMENT for various invalid inputs
  79. * - KERN_NOT_SUPPORTED the request is not supported (second registration on
  80. * release kernels, registration when the task has gone wide)
  81. * - KERN_RESOURCE_SHORTAGE if not enough memory
  82. */
  83. extern kern_return_t task_restartable_ranges_register(
  84. task_t task,
  85. task_restartable_range_array_t ranges,
  86. mach_msg_type_number_t count);
  87. /*!
  88. * @function task_restartable_ranges_synchronize
  89. *
  90. * @brief
  91. * Require for all threads in the task to reset their PC
  92. * if within a restartable range.
  93. *
  94. * @param task
  95. * The task to operate on (needs to be current task)
  96. *
  97. * @returns
  98. * - KERN_SUCCESS
  99. * - KERN_FAILURE if the task isn't the current one
  100. */
  101. extern kern_return_t task_restartable_ranges_synchronize(task_t task);
  102. /*!
  103. * @const TASK_RESTARTABLE_OFFSET_MAX
  104. * The maximum value length / recovery_offs can have.
  105. */
  106. #define TASK_RESTARTABLE_OFFSET_MAX 4096u
  107. #ifdef KERNEL_PRIVATE
  108. struct restartable_ranges;
  109. /**
  110. * @function restartable_init
  111. *
  112. * @brief
  113. * Initializes the restartable module.
  114. */
  115. extern void restartable_init(void);
  116. /**
  117. * @function restartable_ranges_release
  118. *
  119. * @brief
  120. * Release a reference on a restartable range.
  121. */
  122. extern void restartable_ranges_release(struct restartable_ranges *ranges);
  123. /**
  124. * @function thread_reset_pcs_ast
  125. *
  126. * @brief
  127. * Perform the work at the AST boundary to reset thread PCS.
  128. */
  129. extern void thread_reset_pcs_ast(struct thread *thread);
  130. #endif // KERNEL_PRIVATE
  131. __END_DECLS
  132. #endif /* _KERN_RESTARTABLE_H_ */