Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/openlaunchd
Path: blob/master/launchd/runtime.h
374 views
1
/*
2
* Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3
*
4
* @APPLE_APACHE_LICENSE_HEADER_START@
5
*
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
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
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.
17
*
18
* @APPLE_APACHE_LICENSE_HEADER_END@
19
*/
20
21
#ifndef __LAUNCHD_RUNTIME_H__
22
#define __LAUNCHD_RUNTIME_H__
23
24
#ifdef __APPLE__
25
/* XPC is an IPC mechanism for Apple OSes that works with Grand Central
26
* Dispatch. See here for more details:
27
* <https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpsystemstartup/chapters/CreatingXPCServices.html>
28
*/
29
#include <xpc/xpc.h>
30
#endif
31
32
#if HAS_MACH
33
#include <mach/mach.h>
34
#endif
35
#include <sys/types.h>
36
#include <bsm/libbsm.h>
37
#include <stdbool.h>
38
#include <stdint.h>
39
#include <float.h>
40
#include <syslog.h>
41
42
#include "kill2.h"
43
#ifdef __APPLE__
44
#include "ktrace.h"
45
#endif
46
#include "log.h"
47
48
#define likely(x) __builtin_expect((bool)(x), true)
49
#define unlikely(x) __builtin_expect((bool)(x), false)
50
51
struct ldcred {
52
uid_t euid;
53
uid_t uid;
54
gid_t egid;
55
gid_t gid;
56
pid_t pid;
57
au_asid_t asid;
58
mach_port_t asport;
59
};
60
61
typedef void (*kq_callback)(void *, struct kevent *);
62
typedef boolean_t (*mig_callback)(mach_msg_header_t *, mach_msg_header_t *);
63
typedef void (*timeout_callback)(void);
64
65
extern bool launchd_verbose_boot;
66
/* Configuration knobs set in do_file_init(). */
67
extern bool launchd_shutdown_debugging;
68
extern bool launchd_use_gmalloc;
69
extern bool launchd_malloc_log_stacks;
70
extern bool launchd_log_shutdown;
71
extern bool launchd_log_debug;
72
extern bool launchd_log_perf;
73
extern bool launchd_trap_sigkill_bugs;
74
extern bool launchd_no_jetsam_perm_check;
75
extern bool launchd_osinstaller;
76
extern bool launchd_allow_global_dyld_envvars;
77
#if TARGET_OS_EMBEDDED
78
extern bool launchd_appletv;
79
#endif
80
81
extern bool launchd_runtime_busy_time;
82
extern mach_port_t inherited_bootstrap_port;
83
extern size_t runtime_busy_cnt;
84
extern int32_t launchd_sync_frequency;
85
extern pid_t launchd_wsp;
86
87
mach_port_t runtime_get_kernel_port(void);
88
extern boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply);
89
90
void runtime_add_ref(void);
91
void runtime_del_ref(void);
92
void runtime_add_weak_ref(void);
93
void runtime_del_weak_ref(void);
94
void runtime_install_timer(void);
95
void runtime_remove_timer(void);
96
97
void launchd_runtime_init(void);
98
void launchd_runtime_init2(void);
99
void launchd_runtime(void) __attribute__((noreturn));
100
101
void launchd_log_vm_stats(void);
102
103
int runtime_close(int fd);
104
int runtime_fsync(int fd);
105
106
#define RUNTIME_ADVISABLE_IDLE_TIMEOUT 30
107
108
void runtime_set_timeout(timeout_callback to_cb, unsigned int sec);
109
kern_return_t runtime_add_mport(mach_port_t name, mig_callback demux);
110
kern_return_t runtime_remove_mport(mach_port_t name);
111
void runtime_record_caller_creds(audit_token_t *token);
112
struct ldcred *runtime_get_caller_creds(void);
113
audit_token_t *runtime_get_caller_token(void);
114
115
const char *signal_to_C_name(unsigned int sig);
116
const char *reboot_flags_to_C_names(unsigned int flags);
117
118
int kevent_bulk_mod(struct kevent *kev, size_t kev_cnt);
119
int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata);
120
void log_kevent_struct(int level, struct kevent *kev_base, int indx);
121
122
pid_t runtime_fork(mach_port_t bsport);
123
124
mach_msg_return_t launchd_exc_runtime_once(mach_port_t port, mach_msg_size_t rcv_msg_size, mach_msg_size_t send_msg_size, mig_reply_error_t *bufRequest, mig_reply_error_t *bufReply, mach_msg_timeout_t to);
125
126
int64_t runtime_get_wall_time(void) __attribute__((warn_unused_result));
127
uint64_t runtime_get_opaque_time(void) __attribute__((warn_unused_result));
128
uint64_t runtime_get_opaque_time_of_event(void) __attribute__((pure, warn_unused_result));
129
uint64_t runtime_opaque_time_to_nano(uint64_t o) __attribute__((const, warn_unused_result));
130
uint64_t runtime_get_nanoseconds_since(uint64_t o) __attribute__((pure, warn_unused_result));
131
132
kern_return_t launchd_set_bport(mach_port_t name);
133
kern_return_t launchd_get_bport(mach_port_t *name);
134
kern_return_t launchd_mport_notify_req(mach_port_t name, mach_msg_id_t which);
135
kern_return_t launchd_mport_create_recv(mach_port_t *name);
136
kern_return_t launchd_mport_deallocate(mach_port_t name);
137
kern_return_t launchd_mport_make_send(mach_port_t name);
138
kern_return_t launchd_mport_copy_send(mach_port_t name);
139
kern_return_t launchd_mport_make_send_once(mach_port_t name, mach_port_t *so);
140
kern_return_t launchd_mport_close_recv(mach_port_t name);
141
142
uint64_t runtime_get_uniqueid(void);
143
144
#endif /* __LAUNCHD_RUNTIME_H__ */
145
146