Projects
Browse Source     Search     Timeline     Wiki

Changeset 23032

Show
Ignore:
Timestamp:
02/06/07 11:16:25 (22 months ago)
Author:
zarzycki@…
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/launchd/src/launchd_runtime.c

    r23031 r23032  
    3535#include <mach/mach_host.h> 
    3636#include <mach/exception.h> 
    37 #include <mach-o/dyld.h> 
    3837#include <sys/types.h> 
    3938#include <sys/time.h> 
     
    5251#include <stdbool.h> 
    5352#include <syslog.h> 
     53#include <dlfcn.h> 
    5454 
    5555#include "launchd_internalServer.h" 
     
    193193} 
    194194 
    195 static bool 
    196 ptr_is_in_exe(void *ptr) 
    197 { 
    198         uint32_t i, count = _dyld_image_count(); 
    199  
    200         for (i = 0; i < count; i++) { 
    201                 const struct mach_header *header = _dyld_get_image_header(i); 
    202                 uint32_t j, offset = _dyld_get_image_vmaddr_slide(i); 
    203                 struct segment_command *seg; 
    204                 struct load_command *cmd; 
    205  
    206                 j = 0; 
    207                 cmd = (struct load_command*)((char *)header + sizeof(struct mach_header)); 
    208  
    209                 while (j < header->ncmds) { 
    210                         if (cmd->cmd == LC_SEGMENT) { 
    211                                 seg = (struct segment_command*)cmd; 
    212                                 if (((uint32_t)ptr >= (seg->vmaddr + offset)) && ((uint32_t)ptr < (seg->vmaddr + offset + seg->vmsize))) { 
    213                                         return true; 
    214                                 } 
    215                         } 
    216  
    217                         j++; 
    218                         cmd = (struct load_command*)((char*)cmd + cmd->cmdsize); 
    219                 } 
    220         } 
    221          
    222         return false; 
    223 } 
    224  
    225195kern_return_t 
    226196x_handle_kqueue(mach_port_t junk __attribute__((unused)), integer_t fd) 
     
    228198        struct timespec ts = { 0, 0 }; 
    229199        struct kevent kev; 
     200        Dl_info dli; 
    230201        int kevr; 
    231202 
     
    233204 
    234205        if (kevr == 1) { 
    235                 if (launchd_assumes(malloc_size(kev.udata) || ptr_is_in_exe(kev.udata))) { 
     206                if (launchd_assumes(malloc_size(kev.udata) || dladdr(kev.udata, &dli))) { 
    236207                        (*((kq_callback *)kev.udata))(kev.udata, &kev); 
    237208                } else {