Changeset 8587


Ignore:
Timestamp:
Feb 25, 2008, 11:40:45 AM (12 years ago)
Author:
gb
Message:

On ELF platforms, distinguish between link-map and handle returned
by #_dlopen. (They're EQL on Linux but differ on FreeBSD.) Note
that we only set the handle for libraries opened explicitly by
user code, which allows us to usurp the old opened-by-lisp-kernel
slot.

Ensure that CLOSE-SHARED-LIBRARY is defined on FreeBSD; make the ELF
version call #_dlclose on the handle if it exists, not the link map.

Location:
trunk/source
Files:
2 edited

Legend:

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

    r7591 r8587  
    6767  shlib.soname
    6868  shlib.pathname
    69   shlib.opened-by-lisp-kernel
     69  shlib.handle                          ; if explicitly opened
    7070  shlib.map
    7171  shlib.base
     
    263263  (when (null *shared-libraries*)
    264264    (%walk-shared-libraries #'shlib-from-map-entry)
    265     (dolist (l *shared-libraries*)
    266265      ;;; On Linux, it seems to be necessary to open each of these
    267266      ;;; libraries yet again, specifying the RTLD_GLOBAL flag.
    268267      ;;; On FreeBSD, it seems desirable -not- to do that.
    269       #+linux-target
    270       (%dlopen-shlib l)
    271       (setf (shlib.opened-by-lisp-kernel l) t))))
     268    #+linux-target
     269    (dolist (l *shared-libraries*)
     270      (%dlopen-shlib l))))
    272271
    273272(init-shared-libraries)
     
    297296loaded, signal a SIMPLE-ERROR which contains an often-cryptic message from
    298297the operating system."
    299   (let* ((link-map
    300           (let* ((lib (with-cstrs ((name name))
     298  (let* ((handle (with-cstrs ((name name))
    301299                        (ff-call
    302300                         (%kernel-import target::kernel-import-GetSharedLibrary)
    303301                         :address name
    304302                         :unsigned-fullword *dlopen-flags*
    305                          :address))))
    306             #+linux-target lib
    307             #+freebsd-target (if (%null-ptr-p lib)
    308                                lib
    309                                (rlet ((p :address))
    310                                  (if (eql 0 (ff-call
    311                                              (foreign-symbol-entry "dlinfo")
    312                                              :address lib
    313                                              :int #$RTLD_DI_LINKMAP
    314                                              :address p
    315                                              :int))
    316                                    (pref p :address)
    317                                    (%null-ptr)))))))
     303                         :address)))
     304         (link-map #-freebsd-target handle
     305                   #+freebsd-target (if (%null-ptr-p handle)
     306                                      handle
     307                                      (rlet ((p :address))
     308                                        (if (eql 0 (ff-call
     309                                                    (foreign-symbol-entry "dlinfo")
     310                                                    :address handle
     311                                                    :int #$RTLD_DI_LINKMAP
     312                                                    :address p
     313                                                    :int))
     314                                          (pref p :address)
     315                                          (%null-ptr))))))
    318316    (if (%null-ptr-p link-map)
    319317      (error "Error opening shared library ~s: ~a" name (dlerror))
    320318      (prog1 (let* ((lib (shlib-from-map-entry link-map)))
    321319               (incf (shlib.opencount lib))
     320               (setf (shlib.handle lib) handle)
    322321               lib)
    323322        (%walk-shared-libraries
  • trunk/source/level-1/linux-files.lisp

    r8487 r8587  
    596596
    597597;;; Kind of has something to do with files, and doesn't work in level-0.
    598 #+linux-target
     598#+(or linux-target freebsd-target)
    599599(defun close-shared-library (lib &key (completely t))
    600600  "If completely is T, set the reference count of library to 0. Otherwise,
     
    606606                    (error "Shared library ~s not found." lib))
    607607                (require-type lib 'shlib)))
    608          (map (shlib.map lib)))
    609     (unless (shlib.opened-by-lisp-kernel lib)
    610       (when map
     608         (handle (shlib.handle lib)))
     609      (when handle
    611610        (let* ((found nil)
    612611               (base (shlib.base lib)))
    613612          (do* ()
    614613               ((progn           
    615                   (#_dlclose map)
     614                  (#_dlclose handle)
    616615                  (or (not (setq found (shlib-containing-address base)))
    617616                      (not completely)))))
     
    619618            (setf (shlib.pathname lib) nil
    620619              (shlib.base lib) nil
     620              (shlib.handle lib) nil
    621621              (shlib.map lib) nil)
    622622            (unload-foreign-variables lib)
    623             (unload-library-entrypoints lib)))))))
     623            (unload-library-entrypoints lib))))))
    624624
    625625#+darwin-target
Note: See TracChangeset for help on using the changeset viewer.