]> git.saurik.com Git - apple/launchd.git/blob - src/runtime.h
launchd-842.90.1.tar.gz
[apple/launchd.git] / src / runtime.h
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 #include <xpc/xpc.h>
25 #include <mach/mach.h>
26 #include <sys/types.h>
27 #include <bsm/libbsm.h>
28 #include <stdbool.h>
29 #include <stdint.h>
30 #include <float.h>
31 #include <syslog.h>
32
33 #include "kill2.h"
34 #include "ktrace.h"
35 #include "log.h"
36
37 #define likely(x) __builtin_expect((bool)(x), true)
38 #define unlikely(x) __builtin_expect((bool)(x), false)
39
40 struct ldcred {
41 uid_t euid;
42 uid_t uid;
43 gid_t egid;
44 gid_t gid;
45 pid_t pid;
46 au_asid_t asid;
47 mach_port_t asport;
48 };
49
50 typedef void (*kq_callback)(void *, struct kevent *);
51 typedef boolean_t (*mig_callback)(mach_msg_header_t *, mach_msg_header_t *);
52 typedef void (*timeout_callback)(void);
53
54 extern bool launchd_verbose_boot;
55 /* Configuration knobs set in do_file_init(). */
56 extern bool launchd_shutdown_debugging;
57 extern bool launchd_use_gmalloc;
58 extern bool launchd_malloc_log_stacks;
59 extern bool launchd_log_shutdown;
60 extern bool launchd_log_debug;
61 extern bool launchd_log_perf;
62 extern bool launchd_trap_sigkill_bugs;
63 extern bool launchd_no_jetsam_perm_check;
64 extern bool launchd_osinstaller;
65 extern bool launchd_allow_global_dyld_envvars;
66 #if TARGET_OS_EMBEDDED
67 extern bool launchd_appletv;
68 #endif
69
70 extern bool launchd_runtime_busy_time;
71 extern mach_port_t inherited_bootstrap_port;
72 extern size_t runtime_busy_cnt;
73 extern int32_t launchd_sync_frequency;
74 extern pid_t launchd_wsp;
75
76 mach_port_t runtime_get_kernel_port(void);
77 extern boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply);
78
79 void runtime_add_ref(void);
80 void runtime_del_ref(void);
81 void runtime_add_weak_ref(void);
82 void runtime_del_weak_ref(void);
83 void runtime_install_timer(void);
84 void runtime_remove_timer(void);
85
86 void launchd_runtime_init(void);
87 void launchd_runtime_init2(void);
88 void launchd_runtime(void) __attribute__((noreturn));
89
90 void launchd_log_vm_stats(void);
91
92 int runtime_close(int fd);
93 int runtime_fsync(int fd);
94
95 #define RUNTIME_ADVISABLE_IDLE_TIMEOUT 30
96
97 void runtime_set_timeout(timeout_callback to_cb, unsigned int sec);
98 kern_return_t runtime_add_mport(mach_port_t name, mig_callback demux);
99 kern_return_t runtime_remove_mport(mach_port_t name);
100 void runtime_record_caller_creds(audit_token_t *token);
101 struct ldcred *runtime_get_caller_creds(void);
102 audit_token_t *runtime_get_caller_token(void);
103
104 const char *signal_to_C_name(unsigned int sig);
105 const char *reboot_flags_to_C_names(unsigned int flags);
106
107 int kevent_bulk_mod(struct kevent *kev, size_t kev_cnt);
108 int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata);
109 void log_kevent_struct(int level, struct kevent *kev_base, int indx);
110
111 pid_t runtime_fork(mach_port_t bsport);
112
113 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);
114
115 int64_t runtime_get_wall_time(void) __attribute__((warn_unused_result));
116 uint64_t runtime_get_opaque_time(void) __attribute__((warn_unused_result));
117 uint64_t runtime_get_opaque_time_of_event(void) __attribute__((pure, warn_unused_result));
118 uint64_t runtime_opaque_time_to_nano(uint64_t o) __attribute__((const, warn_unused_result));
119 uint64_t runtime_get_nanoseconds_since(uint64_t o) __attribute__((pure, warn_unused_result));
120
121 kern_return_t launchd_set_bport(mach_port_t name);
122 kern_return_t launchd_get_bport(mach_port_t *name);
123 kern_return_t launchd_mport_notify_req(mach_port_t name, mach_msg_id_t which);
124 kern_return_t launchd_mport_create_recv(mach_port_t *name);
125 kern_return_t launchd_mport_deallocate(mach_port_t name);
126 kern_return_t launchd_mport_make_send(mach_port_t name);
127 kern_return_t launchd_mport_copy_send(mach_port_t name);
128 kern_return_t launchd_mport_make_send_once(mach_port_t name, mach_port_t *so);
129 kern_return_t launchd_mport_close_recv(mach_port_t name);
130
131 uint64_t runtime_get_uniqueid(void);
132
133 #endif /* __LAUNCHD_RUNTIME_H__ */