Closed Bug 191270 Opened 22 years ago Closed 22 years ago

Enhance PR_LoadLibrary to load a dynamic shared library (.dylib)

Categories

(NSPR :: NSPR, enhancement, P1)

4.2.1
PowerPC
macOS
enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wtc, Assigned: wtc)

Details

Attachments

(1 file, 1 obsolete file)

In Mac OS X 10.1, the function NSAddImage was added,
which can be used to load a dynamic shared library
(.dylib).  An image loaded this way can't be unloaded
though.

Unfortunately, NSAddImage does not use DYLD_LIBRARY_PATH
to search for the specified dynamic shared library.
Attached patch Proposed patch (obsolete) — Splinter Review
Looks good.

> +    /* No way to unload an image (lib->image) */

Do we ever attempt to unload modules (other than when we shut down)? Assuming
not, maybe there should be an assertion here in case somebody tries to?
NSPR's assertion macro (PR_ASSERT) is intended for
detecting fatal internal errors, so an assertion
would not be appropriate here.  Also, the user still
needs to free the memory associated with the
PRLibrary structure even though the image cannot be
unloaded.

I agree it is important that we communicate to the
caller that an image loaded this way cannot be
unloaded, but I don't know how.  One idea is to
make PR_UnloadLibrary fail with
PR_OPERATION_NOT_SUPPORTED_ERROR, without freeing any
memory, if it is invoked on an image loaded with
NSAddImage, and add a new function PR_ReleaseLibrary
that merely frees the memory associated with the
PRLibrary structure without unloading the underlying
library/module/image.  (Note I use PR_"Release"Library
instead of PR_"Destroy"Library because PRLibrary
structures are reference counted.)  But this seems
like an overkill for an corner case that only exists
on Mac OS X.  Maybe we just document this issue?
Severity: normal → enhancement
Status: NEW → ASSIGNED
Priority: -- → P1
Target Milestone: --- → 4.3
NSS may unload a library in the middle if you delete a PKCS #11 module on the
fly. In this case it's probably a bundle, though, on the mac.

We should make sure the unload 'works most of the way' that is the library is
still removed from NSS's call table, and data is freed. If we call
PR_LoadLibrary again on the module it should succeed.

bob
Do you think the ability for PR_LoadLibrary to load
a dynamic shared library (.dylib) is useful?  Do you
need it?
I think so.

Doug - wouldn't this solve the problem of loading libxpcom.bundle for the GRE?
(It doesn't work and that's why GRE is disabled for Mach-O)
yes.  wtc - with this support, I can enable the GRE on OSX without any extra
work on my part.
Doug, I'd like you to give this patch a test drive.
It is already checked into the tip of NSPR.  You
can do
    cvs -q co -A mozilla/nsprpub
to test this patch.  Thanks.
wtc: to fix the problem that tinderbox showed with this patch, I'd suggest
passing NSADDIMAGE_OPTION_RETURN_ON_ERROR as an option to NSAddImage().  The
problem is that there's a 0-length file that we try to load as a dylib, and the
default behavior without that flag is to abort execution if there is an error
loading the dylib.
Brian: thank you very much for tracking this down.  I've backed
out my checkin and will take a closer look at the error handling
in my patch.
1. Pass the XXX_RETURN_ON_ERROR options to the Mac OS X
linker functions.

2. Pass the NSADDIMAGE_OPTION_WITH_SEARCHING option to
NSAddImage so that it uses DYLD_LIBRARY_PATH to search for
.dylib files.

I would appreciate it if someone can test this patch with plugins.  Thanks.
Attachment #113081 - Attachment is obsolete: true
Patch checked into the NSPR TIP (NSPR 4.3 Beta 2) and
NSPRPUB_PRE_4_2_CLIENT_BRANCH (mozilla 1.4alpha).

Doug, I'd appreciate it if you could test it.
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: