LLDB mainline
PosixSpawnResponsible.h
Go to the documentation of this file.
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.
21errno_t responsibility_spawnattrs_setdisclaim(posix_spawnattr_t *attrs,
22 bool disclaim);
23
24#endif
25
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 reinterpret_cast<__typeof__(&responsibility_spawnattrs_setdisclaim)>
35 (dlsym(RTLD_DEFAULT, "responsibility_spawnattrs_setdisclaim"));
36 });
37 if (responsibility_spawnattrs_setdisclaim_ptr)
38 return responsibility_spawnattrs_setdisclaim_ptr(attr, true);
39#endif
40 }
41 return 0;
42}
43
44#endif // LLDB_HOST_POSIXSPAWNRESPONSIBLE_H
static int setup_posix_spawn_responsible_flag(posix_spawnattr_t *attr)