/ duct-tape / src / stubs.c
stubs.c
  1  #include <darlingserver/duct-tape/stubs.h>
  2  #include <darlingserver/duct-tape/log.h>
  3  
  4  #include <kern/thread.h>
  5  #include <kern/policy_internal.h>
  6  
  7  #include <sys/file_internal.h>
  8  #include <pthread/workqueue_internal.h>
  9  
 10  #include <kern/host.h>
 11  #include <mach_debug/lockgroup_info.h>
 12  
 13  unsigned int kdebug_enable = 0;
 14  uint32_t avenrun[3] = {0};
 15  uint32_t mach_factor[3] = {0};
 16  vm_object_t compressor_object;
 17  uint32_t c_segment_pages_compressed;
 18  expired_task_statistics_t dead_task_statistics;
 19  struct machine_info machine_info;
 20  int sched_allow_NO_SMT_threads;
 21  
 22  #undef panic
 23  
 24  __attribute__((noreturn))
 25  void abort(void);
 26  
 27  typedef struct FILE FILE;
 28  extern FILE* stdout;
 29  
 30  int fflush(FILE* stream);
 31  
 32  #ifndef DTAPE_FATAL_STUBS
 33  	#define DTAPE_FATAL_STUBS 0
 34  #endif
 35  
 36  extern char* getenv(const char* name);
 37  
 38  static bool log_safe_stubs = false;
 39  
 40  __attribute__((constructor))
 41  static void init_stubs() {
 42  	log_safe_stubs = getenv("DTAPE_LOG_SAFE_STUBS") != NULL;
 43  };
 44  
 45  void dtape_stub_log(const char* function_name, int safety, const char* subsection) {
 46  	dtape_log_level_t log_level;
 47  	bool do_abort;
 48  	const char* kind_info;
 49  
 50  	if (safety == 0) {
 51  		log_level = dtape_log_level_warning;
 52  #if DTAPE_FATAL_STUBS
 53  		do_abort = true;
 54  #else
 55  		do_abort = false;
 56  #endif
 57  		kind_info = "";
 58  	} else if (safety < 0) {
 59  		log_level = dtape_log_level_error;
 60  		do_abort = true;
 61  		kind_info = " (unsafe)";
 62  	} else {
 63  		if (!log_safe_stubs) {
 64  			return;
 65  		}
 66  
 67  		log_level = dtape_log_level_debug;
 68  		do_abort = false;
 69  		kind_info = " (safe)";
 70  	}
 71  
 72  	dtape_log(log_level, "stub%s: %s%s%s", kind_info, function_name, subsection[0] == '\0' ? "" : ":", subsection);
 73  
 74  	if (do_abort) {
 75  		abort();
 76  	}
 77  };
 78  
 79  void panic(const char* message, ...) {
 80  	va_list args;
 81  	va_start(args, message);
 82  	printf("darlingserver duct-tape panic: ");
 83  	vprintf(message, args);
 84  	va_end(args);
 85  	printf("\n");
 86  	fflush(stdout);
 87  	abort();
 88  };
 89  
 90  kern_return_t bank_get_bank_ledger_thread_group_and_persona(ipc_voucher_t voucher, ledger_t* bankledger, struct thread_group** banktg, uint32_t* persona_id) {
 91  	dtape_stub();
 92  	return KERN_FAILURE;
 93  };
 94  
 95  int cpu_number(void) {
 96  	dtape_stub_safe();
 97  	return 0;
 98  };
 99  
100  void fileport_releasefg(struct fileglob* fg) {
101  	dtape_stub();
102  };
103  
104  void workq_deallocate_safe(struct workqueue* wq) {
105  	dtape_stub();
106  };
107  
108  bool workq_is_current_thread_updating_turnstile(struct workqueue* wq) {
109  	dtape_stub();
110  	return false;
111  };
112  
113  void workq_reference(struct workqueue* wq) {
114  	dtape_stub();
115  };
116  
117  void workq_schedule_creator_turnstile_redrive(struct workqueue* wq, bool locked) {
118  	dtape_stub();
119  };
120  
121  kern_return_t uext_server(ipc_kmsg_t request, ipc_kmsg_t* reply) {
122  	dtape_stub();
123  	return KERN_FAILURE;
124  };
125  
126  void upl_no_senders(ipc_port_t port, mach_port_mscount_t mscount) {
127  	dtape_stub_safe();
128  };
129  
130  void suid_cred_destroy(ipc_port_t port) {
131  	dtape_stub();
132  };
133  
134  void suid_cred_notify(mach_msg_header_t* msg) {
135  	dtape_stub();
136  };
137  
138  boolean_t ml_get_interrupts_enabled(void) {
139  	return TRUE;
140  };
141  
142  boolean_t ml_set_interrupts_enabled(boolean_t enable) {
143  	return TRUE;
144  };
145  
146  boolean_t ml_delay_should_spin(uint64_t interval) {
147  	return FALSE;
148  };
149  
150  unsigned int ml_wait_max_cpus(void) {
151  	return 0;
152  };
153  
154  struct turnstile* kqueue_turnstile(struct kqueue* kqu) {
155  	dtape_stub();
156  	return NULL;
157  };
158  
159  void waitq_set__CALLING_PREPOST_HOOK__(waitq_set_prepost_hook_t* kq_hook) {
160  	dtape_stub();
161  };
162  
163  void work_interval_port_notify(mach_msg_header_t* msg) {
164  	dtape_stub();
165  };
166  
167  int proc_get_effective_thread_policy(thread_t thread, int flavor) {
168  	switch (flavor) {
169  		case TASK_POLICY_LATENCY_QOS:
170  			return 0;
171  		default:
172  			dtape_stub("unimplemented flavor");
173  			return -1;
174  	}
175  };
176  
177  boolean_t PE_parse_boot_argn(const char* arg_string, void* arg_ptr, int max_len) {
178  	dtape_stub_safe();
179  	return FALSE;
180  };
181  
182  boolean_t machine_timeout_suspended(void) {
183  	dtape_stub_safe();
184  	return true;
185  };
186  
187  boolean_t IOTaskHasEntitlement(task_t task, const char* entitlement) {
188  	dtape_stub_safe();
189  	return TRUE;
190  };
191  
192  kern_return_t kmod_create(host_priv_t host_priv, vm_address_t addr, kmod_t* id) {
193  	dtape_stub_safe();
194  	return KERN_NOT_SUPPORTED;
195  };
196  
197  kern_return_t kmod_destroy(host_priv_t host_priv, kmod_t id) {
198  	dtape_stub_safe();
199  	return KERN_NOT_SUPPORTED;
200  };
201  
202  kern_return_t kmod_control(host_priv_t host_priv, kmod_t id, kmod_control_flavor_t flavor, kmod_args_t* data, mach_msg_type_number_t* dataCount) {
203  	dtape_stub_safe();
204  	return KERN_NOT_SUPPORTED;
205  };
206  
207  kern_return_t kmod_get_info(host_t host, kmod_info_array_t* kmod_list, mach_msg_type_number_t* kmodCount) {
208  	dtape_stub_safe();
209  	return KERN_NOT_SUPPORTED;
210  };
211  
212  kern_return_t kext_request(host_priv_t hostPriv, uint32_t clientLogSpec, vm_offset_t requestIn, mach_msg_type_number_t requestLengthIn, vm_offset_t* responseOut, mach_msg_type_number_t* responseLengthOut, vm_offset_t* logDataOut, mach_msg_type_number_t* logDataLengthOut, kern_return_t* op_result) {
213  	dtape_stub_unsafe();
214  };
215  
216  uint32_t PE_i_can_has_debugger(uint32_t* something) {
217  	dtape_stub_unsafe();
218  };
219  
220  bool work_interval_port_type_render_server(mach_port_name_t port_name) {
221  	dtape_stub_safe();
222  	return false;
223  };
224  
225  ipc_port_t convert_suid_cred_to_port(suid_cred_t sc) {
226  	dtape_stub_unsafe();
227  };