Loading...
os/debug_private.c Libc-1725.40.4 Libc-1044.1.2
--- Libc/Libc-1725.40.4/os/debug_private.c
+++ Libc/Libc-1044.1.2/os/debug_private.c
@@ -37,8 +37,6 @@
 #include <syslog.h>
 #include <sys/time.h>
 #include <unistd.h>
-#include <os/log_simple_private.h>
-#include <ptrauth.h>
 
 struct os_debug_log_globals_s {
 	uint64_t start;
@@ -92,30 +90,15 @@
 	return -1;
 }
 
-__attribute__((weak))
-bool
-_os_debug_log_redirect_func(const char *message)
-{
-	return false;
-}
-
-extern char __text_start __asm__("section$start$__TEXT$__text");
-extern char __text_end __asm__("section$end$__TEXT$__text");
-
 static
 void
 _os_debug_log_init(void *globals)
 {
 	struct os_debug_log_globals_s *g = globals;
-	os_redirect_t redirect = &_os_debug_log_redirect_func;
-	char *addr = (char *)ptrauth_strip(redirect, ptrauth_key_function_pointer);
 
 	g->errors_only = false;
 
-	/* check if our weak _os_debug_log_redirect_func was overriden */
-	if (addr < &__text_start || &__text_end <= addr) {
-		g->redirect = redirect;
-	}
+	g->redirect = dlsym(RTLD_MAIN_ONLY, "_os_debug_log_redirect_func");
 
 	// This is a bit of a hack. LIBDISPATCH_LOG is part of dispatch's API.
 	// But now all dispatch logging goes through os_debug_log. So we have to
@@ -247,7 +230,7 @@
 
 static inline
 void
-_os_debug_log_write(int level, char *str, uint64_t offset)
+_os_debug_log_write(int level, char *str)
 {
 	int fd = os_debug_log_globals()->logfd;
 	os_redirect_t rdr = os_debug_log_globals()->redirect;
@@ -264,21 +247,14 @@
 			// Don't return, fall out to syslog().
 		}
 	}
-#if TARGET_OS_SIMULATOR
-	// Old hosts don't have libplatform support for os_log_simple, so we need
-	// to use legacy shims on simulator
 	_simple_asl_log(level, "com.apple.os_debug_log", str);
-#else // TARGET_OS_SIMULATOR
-	_os_log_simple_offset(os_log_simple_type_from_asl(level),
-			"com.apple.os_debug_log", offset, str);
-#endif // TARGET_OS_SIMULATOR
 }
 
 static __attribute__((always_inline))
 void
 _os_debug_logv(int level, const char *msg, va_list ap)
 {
-	if (os_slowpath((bool)os_debug_log_globals()->errors_only) && level > LOG_ERR) {
+	if (os_slowpath(os_debug_log_globals()->errors_only) && level > LOG_ERR) {
 		// more important = lower integer
 		return;
 	}
@@ -298,7 +274,7 @@
 	__OS_COMPILETIME_ASSERT__(pfxlen >= timelen);
 
 	if (os_fastpath(len > pfxlen)) {
-		if (os_slowpath((bool)os_debug_log_globals()->prepend_timestamp)) {
+		if (os_slowpath(os_debug_log_globals()->prepend_timestamp)) {
 			char tmp = buf[timelen];
 			snprintf(buf, timelen + 1, "%16llu", _os_debug_log_ticks_since_start());
 			buf[timelen] = tmp; // snprintf's null
@@ -307,20 +283,14 @@
 		}
 	}
 
-	_os_debug_log_write(level, buf, (uint64_t)(uintptr_t)__builtin_return_address(0));
+	_os_debug_log_write(level, buf);
 	free(freebuf);
 }
 
 void
 _os_debug_log_error_str(char *msg)
 {
-	_os_debug_log_write(LOG_ERR, msg, (uint64_t)(uintptr_t)__builtin_return_address(0));
-}
-
-void
-_os_debug_log_error_offset(char *msg, uint64_t offset)
-{
-	_os_debug_log_write(LOG_ERR, msg, offset);
+	_os_debug_log_write(LOG_ERR, msg);
 }
 
 OS_FORMAT_PRINTF(1, 2)