]>
Commit | Line | Data |
---|---|---|
5b0a4722 A |
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 | #ifndef __LAUNCHD_RUNTIME_H__ | |
21 | #define __LAUNCHD_RUNTIME_H__ | |
22 | ||
23 | #include <mach/mach.h> | |
24 | #include <sys/types.h> | |
25 | #include <bsm/libbsm.h> | |
26 | #include <stdbool.h> | |
27 | #include <syslog.h> | |
28 | ||
29 | #include "launchd_runtime_kill.h" | |
30 | ||
31 | struct ldcred { | |
32 | uid_t euid; | |
33 | uid_t uid; | |
34 | gid_t egid; | |
35 | gid_t gid; | |
36 | pid_t pid; | |
37 | au_asid_t asid; | |
38 | }; | |
39 | ||
40 | /* | |
41 | * Use launchd_assumes() when we can recover, even if it means we leak or limp along. | |
42 | * | |
43 | * Use launchd_assert() for core initialization routines. | |
44 | */ | |
45 | #define launchd_assumes(e) \ | |
46 | (__builtin_expect(!(e), 0) ? _log_launchd_bug(__rcs_file_version__, __FILE__, __LINE__, #e), false : true) | |
47 | ||
48 | #define launchd_blame(e, b) \ | |
49 | (__builtin_expect(!(e), 0) ? syslog(LOG_DEBUG, "Encountered bug: %d", b), false : true) | |
50 | ||
51 | #define launchd_assert(e) if (__builtin_constant_p(e)) { char __compile_time_assert__[e ? 1 : -1] __attribute__((unused)); } else if (!launchd_assumes(e)) { abort(); } | |
52 | ||
f36da725 A |
53 | #define likely(x) __builtin_expect((bool)(x), true) |
54 | #define unlikely(x) __builtin_expect((bool)(x), false) | |
55 | ||
5b0a4722 A |
56 | void _log_launchd_bug(const char *rcs_rev, const char *path, unsigned int line, const char *test); |
57 | ||
58 | typedef void (*kq_callback)(void *, struct kevent *); | |
59 | typedef boolean_t (*mig_callback)(mach_msg_header_t *, mach_msg_header_t *); | |
60 | typedef void (*timeout_callback)(void); | |
61 | ||
fe044cc9 | 62 | mach_port_t runtime_get_kernel_port(void); |
5b0a4722 A |
63 | |
64 | void runtime_add_ref(void); | |
65 | void runtime_del_ref(void); | |
66 | ||
67 | void launchd_runtime_init(void); | |
68 | void launchd_runtime_init2(void); | |
69 | void launchd_runtime(void) __attribute__((noreturn)); | |
70 | ||
71 | int runtime_close(int fd); | |
72 | int runtime_fsync(int fd); | |
73 | ||
74 | #define RUNTIME_ADVISABLE_IDLE_TIMEOUT 30 | |
75 | ||
76 | void runtime_set_timeout(timeout_callback to_cb, unsigned int sec); | |
77 | kern_return_t runtime_add_mport(mach_port_t name, mig_callback demux, mach_msg_size_t msg_size); | |
78 | kern_return_t runtime_remove_mport(mach_port_t name); | |
79 | bool runtime_get_caller_creds(struct ldcred *ldc); | |
80 | ||
81 | const char *signal_to_C_name(unsigned int sig); | |
82 | const char *reboot_flags_to_C_names(unsigned int flags); | |
83 | const char *proc_flags_to_C_names(unsigned int flags); | |
84 | ||
85 | ||
86 | int kevent_bulk_mod(struct kevent *kev, size_t kev_cnt); | |
87 | int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata); | |
88 | ||
89 | pid_t runtime_fork(mach_port_t bsport); | |
90 | ||
91 | kern_return_t runtime_log_forward(uid_t forward_uid, gid_t forward_gid, vm_offset_t inval, mach_msg_type_number_t invalCnt); | |
92 | kern_return_t runtime_log_drain(mach_port_t srp, vm_offset_t *outval, mach_msg_type_number_t *outvalCnt); | |
93 | ||
94 | #define LOG_APPLEONLY 0x4141504c /* AAPL in hex */ | |
95 | ||
96 | struct runtime_syslog_attr { | |
97 | const char *from_name; | |
98 | const char *about_name; | |
99 | const char *session_name; | |
100 | int priority; | |
101 | uid_t from_uid; | |
102 | pid_t from_pid; | |
103 | pid_t about_pid; | |
104 | }; | |
105 | ||
106 | int runtime_setlogmask(int maskpri); | |
107 | void runtime_closelog(void); | |
108 | void runtime_syslog(int pri, const char *message, ...) __attribute__((format(printf, 2, 3))); | |
109 | void runtime_vsyslog(struct runtime_syslog_attr *attr, const char *message, va_list args) __attribute__((format(printf, 2, 0))); | |
110 | ||
111 | ||
112 | kern_return_t launchd_set_bport(mach_port_t name); | |
113 | kern_return_t launchd_get_bport(mach_port_t *name); | |
114 | kern_return_t launchd_mport_notify_req(mach_port_t name, mach_msg_id_t which); | |
115 | kern_return_t launchd_mport_notify_cancel(mach_port_t name, mach_msg_id_t which); | |
116 | kern_return_t launchd_mport_create_recv(mach_port_t *name); | |
117 | kern_return_t launchd_mport_deallocate(mach_port_t name); | |
118 | kern_return_t launchd_mport_make_send(mach_port_t name); | |
119 | kern_return_t launchd_mport_close_recv(mach_port_t name); | |
120 | ||
121 | #endif |