[launchd-changes] [23032] trunk/launchd/src/launchd_runtime.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 6 11:16:25 PST 2007


Revision: 23032
          http://trac.macosforge.org/projects/launchd/changeset/23032
Author:   zarzycki at apple.com
Date:     2007-02-06 11:16:25 -0800 (Tue, 06 Feb 2007)

Log Message:
-----------
I just got off the phone with our dynamic linker engineer. This should work just as well, but with less code.

Modified Paths:
--------------
    trunk/launchd/src/launchd_runtime.c

Modified: trunk/launchd/src/launchd_runtime.c
===================================================================
--- trunk/launchd/src/launchd_runtime.c	2007-02-06 17:50:05 UTC (rev 23031)
+++ trunk/launchd/src/launchd_runtime.c	2007-02-06 19:16:25 UTC (rev 23032)
@@ -34,7 +34,6 @@
 #include <mach/host_info.h>
 #include <mach/mach_host.h>
 #include <mach/exception.h>
-#include <mach-o/dyld.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/event.h>
@@ -51,6 +50,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <syslog.h>
+#include <dlfcn.h>
 
 #include "launchd_internalServer.h"
 #include "launchd_internal.h"
@@ -192,47 +192,18 @@
 	return NULL;
 }
 
-static bool
-ptr_is_in_exe(void *ptr)
-{
-	uint32_t i, count = _dyld_image_count();
-
-	for (i = 0; i < count; i++) {
-		const struct mach_header *header = _dyld_get_image_header(i);
-		uint32_t j, offset = _dyld_get_image_vmaddr_slide(i);
-		struct segment_command *seg;
-		struct load_command *cmd;
-
-		j = 0;
-		cmd = (struct load_command*)((char *)header + sizeof(struct mach_header));
-
-		while (j < header->ncmds) {
-			if (cmd->cmd == LC_SEGMENT) {
-				seg = (struct segment_command*)cmd;
-				if (((uint32_t)ptr >= (seg->vmaddr + offset)) && ((uint32_t)ptr < (seg->vmaddr + offset + seg->vmsize))) {
-					return true;
-				}
-			}
-
-			j++;
-			cmd = (struct load_command*)((char*)cmd + cmd->cmdsize);
-		}
-	}
-	
-	return false;
-}
-
 kern_return_t
 x_handle_kqueue(mach_port_t junk __attribute__((unused)), integer_t fd)
 {
 	struct timespec ts = { 0, 0 };
 	struct kevent kev;
+	Dl_info dli;
 	int kevr;
 
 	launchd_assumes((kevr = kevent(fd, NULL, 0, &kev, 1, &ts)) != -1);
 
 	if (kevr == 1) {
-		if (launchd_assumes(malloc_size(kev.udata) || ptr_is_in_exe(kev.udata))) {
+		if (launchd_assumes(malloc_size(kev.udata) || dladdr(kev.udata, &dli))) {
 			(*((kq_callback *)kev.udata))(kev.udata, &kev);
 		} else {
 			syslog(LOG_ERR, "kev.ident == 0x%x kev.filter == 0x%x kev.fflags = 0x%x kev.udata = 0x%x",

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070206/52182454/attachment.html


More information about the launchd-changes mailing list