+/* Called with proc locked */
+static void
+set_thread_extra_flags(struct uthread *uth, os_reason_t reason)
+{
+ extern int vm_shared_region_reslide_restrict;
+ assert(uth != NULL);
+ /*
+ * Check whether the userland fault address falls within the shared
+ * region and notify userland if so. This allows launchd to apply
+ * special policies around this fault type.
+ */
+ if (reason->osr_namespace == OS_REASON_SIGNAL &&
+ reason->osr_code == SIGSEGV) {
+ mach_vm_address_t fault_address = uth->uu_subcode;
+
+#if defined(__arm64__)
+ /* taken from osfmk/arm/misc_protos.h */
+ #define TBI_MASK 0xff00000000000000
+ #define tbi_clear(addr) ((addr) & ~(TBI_MASK))
+ fault_address = tbi_clear(fault_address);
+#endif /* __arm64__ */
+
+ if (fault_address >= SHARED_REGION_BASE &&
+ fault_address <= SHARED_REGION_BASE + SHARED_REGION_SIZE) {
+ /*
+ * Always report whether the fault happened within the shared cache
+ * region, but only stale the slide if the resliding is extended
+ * to all processes or if the process faulting is a platform one.
+ */
+ reason->osr_flags |= OS_REASON_FLAG_SHAREDREGION_FAULT;
+
+#if __has_feature(ptrauth_calls)
+ if (!vm_shared_region_reslide_restrict || csproc_get_platform_binary(current_proc())) {
+ vm_shared_region_reslide_stale();
+ }
+#endif /* __has_feature(ptrauth_calls) */
+ }
+ }
+}
+