xref: /trueos/lib/liblaunch/launch_priv.h (revision a39535524a7b97f8cdb8ae7f21de83eccb0ed005)
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 __LAUNCH_PRIVATE_H__
22 #define __LAUNCH_PRIVATE_H__
23 
24 #include <mach/mach.h>
25 #include <sys/types.h>
26 #include <launch.h>
27 #include <unistd.h>
28 #include <paths.h>
29 #include <uuid/uuid.h>
30 
31 #pragma GCC visibility push(default)
32 
33 __BEGIN_DECLS
34 
35 #define LAUNCH_EXITSTATUS_FAIRPLAY_FAIL (INT64_MAX)
36 
37 #define LAUNCH_KEY_SETUSERENVIRONMENT "SetUserEnvironment"
38 #define LAUNCH_KEY_UNSETUSERENVIRONMENT "UnsetUserEnvironment"
39 #define LAUNCH_KEY_SHUTDOWN "Shutdown"
40 #define LAUNCH_KEY_SINGLEUSER "SingleUser"
41 #define LAUNCH_KEY_GETRESOURCELIMITS "GetResourceLimits"
42 #define LAUNCH_KEY_SETRESOURCELIMITS "SetResourceLimits"
43 #define LAUNCH_KEY_GETRUSAGESELF "GetResourceUsageSelf"
44 #define LAUNCH_KEY_GETRUSAGECHILDREN "GetResourceUsageChildren"
45 
46 #define LAUNCHD_SOCKET_ENV "LAUNCHD_SOCKET"
47 #define LAUNCHD_SOCK_PREFIX _PATH_VARTMP "launchd"
48 #define LAUNCHD_TRUSTED_FD_ENV "__LAUNCHD_FD"
49 #define LAUNCHD_ASYNC_MSG_KEY "_AsyncMessage"
50 #define LAUNCH_KEY_BATCHCONTROL "BatchControl"
51 #define LAUNCH_KEY_BATCHQUERY "BatchQuery"
52 
53 #define LAUNCH_JOBKEY_TRANSACTIONCOUNT "TransactionCount"
54 #define LAUNCH_JOBKEY_QUARANTINEDATA "QuarantineData"
55 #define LAUNCH_JOBKEY_SANDBOXPROFILE "SandboxProfile"
56 #define LAUNCH_JOBKEY_SANDBOXFLAGS "SandboxFlags"
57 #define LAUNCH_JOBKEY_SANDBOX_NAMED "Named"
58 #define	LAUNCH_JOBKEY_SANDBOXCONTAINER "SandboxContainer"
59 #define LAUNCH_JOBKEY_JETSAMPROPERTIES "JetsamProperties"
60 #define LAUNCH_JOBKEY_JETSAMPRIORITY "JetsamPriority"
61 #define LAUNCH_JOBKEY_JETSAMMEMORYLIMIT "JetsamMemoryLimit"
62 #define LAUNCH_JOBKEY_JETSAMMEMORYLIMITBACKGROUND "JetsamMemoryLimitBackground"
63 #define LAUNCH_JOBKEY_SECURITYSESSIONUUID "SecuritySessionUUID"
64 #define LAUNCH_JOBKEY_DISABLEASLR "DisableASLR"
65 #define LAUNCH_JOBKEY_XPCDOMAIN "XPCDomain"
66 #define LAUNCH_JOBKEY_POSIXSPAWNTYPE "POSIXSpawnType"
67 
68 #define LAUNCH_KEY_JETSAMLABEL "JetsamLabel"
69 #define LAUNCH_KEY_JETSAMFRONTMOST "JetsamFrontmost"
70 #define LAUNCH_KEY_JETSAMACTIVE "JetsamActive"
71 #define LAUNCH_KEY_JETSAMPRIORITY LAUNCH_JOBKEY_JETSAMPRIORITY
72 #define LAUNCH_KEY_JETSAMMEMORYLIMIT LAUNCH_JOBKEY_JETSAMMEMORYLIMIT
73 
74 #define LAUNCH_KEY_POSIXSPAWNTYPE_APP LAUNCH_KEY_PROCESSTYPE_APP
75 #define LAUNCH_KEY_POSIXSPAWNTYPE_SYSTEMAPP "SystemApp"
76 #define LAUNCH_KEY_POSIXSPAWNTYPE_STANDARD LAUNCH_KEY_PROCESSTYPE_STANDARD
77 #define LAUNCH_KEY_POSIXSPAWNTYPE_BACKGROUND LAUNCH_KEY_PROCESSTYPE_BACKGROUND
78 #define LAUNCH_KEY_POSIXSPAWNTYPE_INTERACTIVE LAUNCH_KEY_PROCESSTYPE_INTERACTIVE
79 #define LAUNCH_KEY_POSIXSPAWNTYPE_ADAPTIVE LAUNCH_KEY_PROCESSTYPE_ADAPTIVE
80 #define LAUNCH_KEY_POSIXSPAWNTYPE_TALAPP "TALApp"
81 
82 #define LAUNCH_JOBKEY_EMBEDDEDPRIVILEGEDISPENSATION "EmbeddedPrivilegeDispensation"
83 #define LAUNCH_JOBKEY_EMBEDDEDHOMESCREEN "EmbeddedHomeScreen"
84 #define LAUNCH_JOBKEY_EMBEDDEDMAINTHREADPRIORITY "EmbeddedMainThreadPriority"
85 
86 #define LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL "EnterKernelDebuggerBeforeKill"
87 #define LAUNCH_JOBKEY_PERJOBMACHSERVICES "PerJobMachServices"
88 #define LAUNCH_JOBKEY_SERVICEIPC "ServiceIPC"
89 #define LAUNCH_JOBKEY_BINARYORDERPREFERENCE "BinaryOrderPreference"
90 #define LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER "MachExceptionHandler"
91 #define LAUNCH_JOBKEY_MULTIPLEINSTANCES "MultipleInstances"
92 #define LAUNCH_JOBKEY_EVENTMONITOR "EventMonitor"
93 #define LAUNCH_JOBKEY_SHUTDOWNMONITOR "ShutdownMonitor"
94 #define LAUNCH_JOBKEY_BEGINTRANSACTIONATSHUTDOWN "BeginTransactionAtShutdown"
95 #define LAUNCH_JOBKEY_XPCDOMAINBOOTSTRAPPER "XPCDomainBootstrapper"
96 #define LAUNCH_JOBKEY_ASID "AuditSessionID"
97 #define LAUNCH_JOBKEY_JOINGUISESSION "JoinGUISession"
98 
99 #define LAUNCH_JOBKEY_MACH_KUNCSERVER "kUNCServer"
100 #define LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER "ExceptionServer"
101 #define LAUNCH_JOBKEY_MACH_TASKSPECIALPORT "TaskSpecialPort"
102 #define LAUNCH_JOBKEY_MACH_HOSTSPECIALPORT "HostSpecialPort"
103 #define LAUNCH_JOBKEY_MACH_ENTERKERNELDEBUGGERONCLOSE "EnterKernelDebuggerOnClose"
104 #define LAUNCH_JOBKEY_LOWPRIORITYBACKGROUNDIO "LowPriorityBackgroundIO"
105 #define LAUNCH_JOBKEY_LEGACYTIMERS "LegacyTimers"
106 
107 #define LAUNCH_ENV_INSTANCEID "LaunchInstanceID"
108 
109 #define JETSAM_PROPERTY_PRIORITY "Priority"
110 #define JETSAM_PROPERTY_MEMORYLIMIT "MemoryLimitMB"
111 
112 /* For LoginWindow.
113  *
114  * After this call, the task's bootstrap port is set to the per session launchd.
115  *
116  * This returns 1 on success (it used to return otherwise), and -1 on failure.
117  */
118 #define	LOAD_ONLY_SAFEMODE_LAUNCHAGENTS (1 << 0)
119 #define LAUNCH_GLOBAL_ON_DEMAND (1 << 1)
120 pid_t
121 create_and_switch_to_per_session_launchd(const char *, int flags, ...);
122 
123 /* Also for LoginWindow.
124  *
125  * This is will load jobs at the LoginWindow prompt.
126  */
127 void
128 load_launchd_jobs_at_loginwindow_prompt(int flags, ...);
129 
130 /* For CoreProcesses */
131 #define SPAWN_VIA_LAUNCHD_STOPPED 0x0001
132 #define SPAWN_VIA_LAUNCHD_TALAPP 0x0002
133 #define SPAWN_VIA_LAUNCHD_WIDGET 0x0004
134 #define SPAWN_VIA_LAUNCHD_DISABLE_ASLR 0x0008
135 
136 struct spawn_via_launchd_attr {
137 	uint64_t spawn_flags;
138 	const char *spawn_path;
139 	const char *spawn_chdir;
140  	const char * const * spawn_env;
141  	const mode_t *spawn_umask;
142  	mach_port_t *spawn_observer_port;
143  	const cpu_type_t *spawn_binpref;
144 	size_t spawn_binpref_cnt;
145 	void * spawn_quarantine;
146 	const char *spawn_seatbelt_profile;
147 	const uint64_t *spawn_seatbelt_flags;
148 };
149 
150 #define spawn_via_launchd(a, b, c) _spawn_via_launchd(a, b, c, 3)
151 pid_t
152 _spawn_via_launchd(const char *label, const char * const *argv,
153 	const struct spawn_via_launchd_attr *spawn_attrs, int struct_version);
154 
155 int
156 launch_wait(mach_port_t port);
157 
158 /* The mpm_*() APIs no longer do anything. */
159 kern_return_t
160 mpm_wait(mach_port_t ajob, int *wstatus);
161 
162 kern_return_t
163 mpm_uncork_fork(mach_port_t ajob);
164 
165 launch_data_t
166 launch_socket_service_check_in(void);
167 
168 __END_DECLS
169 
170 #pragma GCC visibility pop
171 
172 
173 #endif /* __LAUNCH_PRIVATE_H__ */
174