summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
Diffstat (limited to 'unix')
-rw-r--r--unix/tclLoadDyld.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c
index 67a797d..3c1fc82 100644
--- a/unix/tclLoadDyld.c
+++ b/unix/tclLoadDyld.c
@@ -2,15 +2,17 @@
* tclLoadDyld.c --
*
* This procedure provides a version of the TclLoadFile that works with
- * Apple's dyld dynamic loading. This file provided by Wilfredo Sanchez
- * (wsanchez@apple.com). This works on Mac OS X.
+ * Apple's dyld dynamic loading.
+ * Original version of his file (now superseded long ago) provided by
+ * Wilfredo Sanchez (wsanchez@apple.com).
*
* Copyright (c) 1995 Apple Computer, Inc.
+ * Copyright (c) 2005 Daniel A. Steffen <das@users.sourceforge.net>
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLoadDyld.c,v 1.18 2005/07/19 08:51:29 dkf Exp $
+ * RCS: @(#) $Id: tclLoadDyld.c,v 1.19 2005/07/30 07:57:48 das Exp $
*/
#include "tclInt.h"
@@ -121,9 +123,10 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
if (!dyldLibHeader) {
NSLinkEditErrors editError;
+ int errorNumber;
CONST char *name, *msg, *objFileImageErrMsg = NULL;
- NSLinkEditError(&editError, &errno, &name, &msg);
+ NSLinkEditError(&editError, &errorNumber, &name, &msg);
if (editError == NSLinkEditFileAccessError) {
/*
@@ -141,9 +144,10 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
| NSADDIMAGE_OPTION_RETURN_ON_ERROR);
Tcl_DStringFree(&ds);
if (!dyldLibHeader) {
- NSLinkEditError(&editError, &errno, &name, &msg);
+ NSLinkEditError(&editError, &errorNumber, &name, &msg);
}
- } else if (editError==NSLinkEditFileFormatError && errno==EBADMACHO) {
+ } else if ((editError==NSLinkEditFileFormatError && errorNumber==EBADMACHO)
+ || editError == NSLinkEditOtherError){
/*
* The requested file was found but was not of type MH_DYLIB,
* attempt to load it as a MH_BUNDLE.
@@ -156,6 +160,9 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
if (!dyldLibHeader && !dyldObjFileImage) {
Tcl_AppendResult(interp, msg, (char *) NULL);
+ if (msg && *msg) {
+ Tcl_AppendResult(interp, "\n", (char *) NULL);
+ }
if (objFileImageErrMsg) {
Tcl_AppendResult(interp,
"NSCreateObjectFileImageFromFile() error: ",
@@ -175,9 +182,10 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
if (!module) {
NSLinkEditErrors editError;
+ int errorNumber;
CONST char *name, *msg;
- NSLinkEditError(&editError, &errno, &name, &msg);
+ NSLinkEditError(&editError, &errorNumber, &name, &msg);
Tcl_AppendResult(interp, msg, (char *) NULL);
return TCL_ERROR;
}
@@ -265,9 +273,10 @@ TclpFindSymbol(interp, loadHandle, symbol)
} else {
NSLinkEditErrors editError;
+ int errorNumber;
CONST char *name, *msg;
- NSLinkEditError(&editError, &errno, &name, &msg);
+ NSLinkEditError(&editError, &errorNumber, &name, &msg);
Tcl_AppendResult(interp, msg, (char *) NULL);
}
} else {
@@ -452,10 +461,22 @@ TclpLoadMemory(interp, buffer, size, codeSize, loadHandle, unloadProcPtr)
*/
if (codeSize >= 0) {
- NSObjectFileImageReturnCode err;
-
- err = NSCreateObjectFileImageFromMemory(buffer, codeSize,
- &dyldObjFileImage);
+ NSObjectFileImageReturnCode err = NSObjectFileImageSuccess;
+
+#ifndef __LP64__
+ struct mach_header *mh = buffer;
+ if (codeSize < sizeof(struct mach_header) || mh->magic != MH_MAGIC
+#else
+ struct mach_header_64 *mh = buffer;
+ if (codeSize < sizeof(struct mach_header_64) || mh->magic != MH_MAGIC_64
+#endif
+ || mh->filetype != MH_BUNDLE) {
+ err = NSObjectFileImageInappropriateFile;
+ }
+ if (err == NSObjectFileImageSuccess) {
+ err = NSCreateObjectFileImageFromMemory(buffer, codeSize,
+ &dyldObjFileImage);
+ }
objFileImageErrMsg = DyldOFIErrorMsg(err);
}
@@ -484,9 +505,10 @@ TclpLoadMemory(interp, buffer, size, codeSize, loadHandle, unloadProcPtr)
if (!module) {
NSLinkEditErrors editError;
+ int errorNumber;
CONST char *name, *msg;
- NSLinkEditError(&editError, &errno, &name, &msg);
+ NSLinkEditError(&editError, &errorNumber, &name, &msg);
Tcl_AppendResult(interp, msg, (char *) NULL);
return TCL_ERROR;
}