1 //===-- PosixSpawnResponsible.h ---------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_HOST_POSIXSPAWNRESPONSIBLE_H 10 #define LLDB_HOST_POSIXSPAWNRESPONSIBLE_H 11 12 #include <spawn.h> 13 14 #if __has_include(<responsibility.h>) 15 #include <dispatch/dispatch.h> 16 #include <dlfcn.h> 17 #include <responsibility.h> 18 19 // Older SDKs have responsibility.h but not this particular function. Let's 20 // include the prototype here. 21 errno_t responsibility_spawnattrs_setdisclaim(posix_spawnattr_t *attrs, 22 bool disclaim); 23 24 #endif 25 setup_posix_spawn_responsible_flag(posix_spawnattr_t * attr)26static inline int setup_posix_spawn_responsible_flag(posix_spawnattr_t *attr) { 27 if (@available(macOS 10.14, *)) { 28 #if __has_include(<responsibility.h>) 29 static __typeof__(responsibility_spawnattrs_setdisclaim) 30 *responsibility_spawnattrs_setdisclaim_ptr; 31 static dispatch_once_t pred; 32 dispatch_once(&pred, ^{ 33 responsibility_spawnattrs_setdisclaim_ptr = 34 #ifdef __cplusplus 35 reinterpret_cast<__typeof__(&responsibility_spawnattrs_setdisclaim)> 36 #endif 37 (dlsym(RTLD_DEFAULT, "responsibility_spawnattrs_setdisclaim")); 38 }); 39 if (responsibility_spawnattrs_setdisclaim_ptr) 40 return responsibility_spawnattrs_setdisclaim_ptr(attr, true); 41 #endif 42 } 43 return 0; 44 } 45 46 #endif // LLDB_HOST_POSIXSPAWNRESPONSIBLE_H 47