Changeset 14180


Ignore:
Timestamp:
Aug 13, 2010, 10:15:10 AM (9 years ago)
Author:
gb
Message:

Darwin/ARM doesn't support the legacy foreign symbol stuff. We should
drop support for that, but there's no public way to map from a handle
(as returned by dlopen()) to a Mach image header (as returned by
dlsym()).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-0/l0-cfm-support.lisp

    r14155 r14180  
    716716
    717717(defun legacy-shlib-containing-address (addr name)
    718   (dotimes (i (ff-call *dyld-image-count* :unsigned-fullword))
    719     (let ((header (ff-call *dyld-get-image-header* :unsigned-fullword i :address)))
    720       (when (and (not (%null-ptr-p header))
    721                  (or (eql (pref header :mach_header.filetype) #$MH_DYLIB)
    722                      (eql (pref header :mach_header.filetype) #$MH_BUNDLE)))
    723         ;; make sure the image is either a bundle or a dylib
    724         ;; (otherwise we will crash, likely OS bug, tested OS X 10.1.5)
    725         (with-cstrs ((cname name))
    726           ;; also we must check is symbol name is defined in the
    727           ;; image otherwise in certain cases there is a crash,
    728           ;; another likely OS bug happens in the case where a
    729           ;; bundle imports a dylib and then we call
    730           ;; nslookupsymbolinimage on the bundle image
    731           (when (/= 0
    732                     (ff-call *ns-is-symbol-name-defined-in-image* :address header
    733                              :address cname :unsigned))
    734             (let ((symbol (ff-call *nslookup-symbol-in-image* :address header :address cname
    735                                    :unsigned-fullword #$NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
    736                                    :address)))
    737               (unless (%null-ptr-p symbol)
    738                 ;; compare the found address to the address we are looking for
    739                 (let ((foundaddr (ff-call *nsaddress-of-symbol* :address symbol :address)))
    740                   ;; (format t "Foundaddr ~s~%" foundaddr)
    741                   ;; (format t "Compare to addr ~s~%" addr)
    742                   (when (eql foundaddr addr)
    743                     (let* ((imgname (ff-call *dyld-get-image-name* :unsigned-fullword i :address))
    744                            (libname (unless (%null-ptr-p imgname) (%get-cstring imgname)))
    745                            (libmodule (%int-to-ptr 0))
    746                            (libheader (%int-to-ptr 0)))
    747                       (if (eql (pref header :mach_header.filetype) #$MH_BUNDLE)
    748                         (setf libmodule (ff-call *nsmodule-for-symbol* :address symbol :address))
    749                         (setf libheader header))
    750                       ;; make sure that this shared library is on *shared-libraries*
    751                       (return (shared-library-from-header-module-or-name libheader libmodule libname)))))))))))))
     718  (when *ns-is-symbol-name-defined-in-image*
     719    (dotimes (i (ff-call *dyld-image-count* :unsigned-fullword))
     720      (let ((header (ff-call *dyld-get-image-header* :unsigned-fullword i :address)))
     721        (when (and (not (%null-ptr-p header))
     722                   (or (eql (pref header :mach_header.filetype) #$MH_DYLIB)
     723                       (eql (pref header :mach_header.filetype) #$MH_BUNDLE)))
     724          ;; make sure the image is either a bundle or a dylib
     725          ;; (otherwise we will crash, likely OS bug, tested OS X 10.1.5)
     726          (with-cstrs ((cname name))
     727            ;; also we must check is symbol name is defined in the
     728            ;; image otherwise in certain cases there is a crash,
     729            ;; another likely OS bug happens in the case where a
     730            ;; bundle imports a dylib and then we call
     731            ;; nslookupsymbolinimage on the bundle image
     732            (when (/= 0
     733                      (ff-call *ns-is-symbol-name-defined-in-image* :address header
     734                               :address cname :unsigned))
     735              (let ((symbol (ff-call *nslookup-symbol-in-image* :address header :address cname
     736                                     :unsigned-fullword #$NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
     737                                     :address)))
     738                (unless (%null-ptr-p symbol)
     739                  ;; compare the found address to the address we are looking for
     740                  (let ((foundaddr (ff-call *nsaddress-of-symbol* :address symbol :address)))
     741                    ;; (format t "Foundaddr ~s~%" foundaddr)
     742                    ;; (format t "Compare to addr ~s~%" addr)
     743                    (when (eql foundaddr addr)
     744                      (let* ((imgname (ff-call *dyld-get-image-name* :unsigned-fullword i :address))
     745                             (libname (unless (%null-ptr-p imgname) (%get-cstring imgname)))
     746                             (libmodule (%int-to-ptr 0))
     747                             (libheader (%int-to-ptr 0)))
     748                        (if (eql (pref header :mach_header.filetype) #$MH_BUNDLE)
     749                          (setf libmodule (ff-call *nsmodule-for-symbol* :address symbol :address))
     750                          (setf libheader header))
     751                        ;; make sure that this shared library is on *shared-libraries*
     752                        (return (shared-library-from-header-module-or-name libheader libmodule libname))))))))))))))
    752753
    753754(defun shlib-containing-address (address name)
Note: See TracChangeset for help on using the changeset viewer.