2 * Copyright (c) 2007-2012 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
21 #ifndef __LAUNCH_INTERNAL_H__
22 #define __LAUNCH_INTERNAL_H__
24 #include "vproc_priv.h"
27 #include <dispatch/dispatch.h>
30 #if __has_include(<os/alloc_once_private.h>)
31 #include <os/alloc_once_private.h>
32 #if defined(OS_ALLOC_ONCE_KEY_LIBLAUNCH)
33 #define _LIBLAUNCH_HAS_ALLOC_ONCE 1
37 typedef struct _launch
*launch_t
;
39 struct launch_globals_s
{
41 pthread_once_t lc_once
;
42 pthread_mutex_t lc_mtx
;
44 launch_data_t async_resp
;
46 launch_t in_flight_msg_recv_client
;
48 int64_t s_am_embedded_god
;
51 dispatch_queue_t _vproc_gone2zero_queue
;
52 _vproc_transaction_callout _vproc_gone2zero_callout
;
53 void *_vproc_gone2zero_ctx
;
55 dispatch_once_t _vproc_transaction_once
;
56 uint64_t _vproc_transaction_enabled
;
57 dispatch_queue_t _vproc_transaction_queue
;
58 int64_t _vproc_transaction_cnt
;
60 typedef struct launch_globals_s
*launch_globals_t
;
62 void _launch_init_globals(launch_globals_t globals
);
64 #if !_LIBLAUNCH_HAS_ALLOC_ONCE
65 launch_globals_t
_launch_globals_impl(void);
68 __attribute__((__pure__
))
69 static inline launch_globals_t
70 _launch_globals(void) {
71 #if _LIBLAUNCH_HAS_ALLOC_ONCE
72 return (launch_globals_t
)os_alloc_once(OS_ALLOC_ONCE_KEY_LIBLAUNCH
,
73 sizeof(struct launch_globals_s
),
74 (void*)&_launch_init_globals
);
76 return _launch_globals_impl();
80 #pragma GCC visibility push(default)
82 #define LAUNCHD_DB_PREFIX "/private/var/db/launchd.db"
83 #define LAUNCHD_LOG_PREFIX "/private/var/log"
85 #define LAUNCHD_JOB_DEFAULTS "Defaults"
86 #define LAUNCHD_JOB_DEFAULTS_CACHED "CachedDefaults"
88 launch_t
launchd_fdopen(int, int);
89 int launchd_getfd(launch_t
);
90 void launchd_close(launch_t
, __typeof__(close
) closefunc
);
92 launch_data_t
launch_data_new_errno(int);
93 bool launch_data_set_errno(launch_data_t
, int);
95 int launchd_msg_send(launch_t
, launch_data_t
);
96 int launchd_msg_recv(launch_t
, void (*)(launch_data_t
, void *), void *);
98 size_t launch_data_pack(launch_data_t d
, void *where
, size_t len
, int *fd_where
, size_t *fdslotsleft
);
99 launch_data_t
launch_data_unpack(void *data
, size_t data_size
, int *fds
, size_t fd_cnt
, size_t *data_offset
, size_t *fdoffset
);
101 #pragma GCC visibility pop
103 #endif /* __LAUNCH_INTERNAL_H__*/