| 1 | /* dl_next.xs
|
|---|
| 2 | *
|
|---|
| 3 | * Platform: NeXT NS 3.2
|
|---|
| 4 | * Author: Anno Siegel ([email protected])
|
|---|
| 5 | * Based on: dl_dlopen.xs by Paul Marquess
|
|---|
| 6 | * Created: Aug 15th, 1994
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | /*
|
|---|
| 11 | And Gandalf said: 'Many folk like to know beforehand what is to
|
|---|
| 12 | be set on the table; but those who have laboured to prepare the
|
|---|
| 13 | feast like to keep their secret; for wonder makes the words of
|
|---|
| 14 | praise louder.'
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | /* Porting notes:
|
|---|
| 18 |
|
|---|
| 19 | dl_next.xs is itself a port from dl_dlopen.xs by Paul Marquess. It
|
|---|
| 20 | should not be used as a base for further ports though it may be used
|
|---|
| 21 | as an example for how dl_dlopen.xs can be ported to other platforms.
|
|---|
| 22 |
|
|---|
| 23 | The method used here is just to supply the sun style dlopen etc.
|
|---|
| 24 | functions in terms of NeXTs rld_*. The xs code proper is unchanged
|
|---|
| 25 | from Paul's original.
|
|---|
| 26 |
|
|---|
| 27 | The port could use some streamlining. For one, error handling could
|
|---|
| 28 | be simplified.
|
|---|
| 29 |
|
|---|
| 30 | Anno Siegel
|
|---|
| 31 |
|
|---|
| 32 | */
|
|---|
| 33 |
|
|---|
| 34 | #if NS_TARGET_MAJOR >= 4
|
|---|
| 35 | #else
|
|---|
| 36 | /* include these before perl headers */
|
|---|
| 37 | #include <mach-o/rld.h>
|
|---|
| 38 | #include <streams/streams.h>
|
|---|
| 39 | #endif
|
|---|
| 40 |
|
|---|
| 41 | #include "EXTERN.h"
|
|---|
| 42 | #include "perl.h"
|
|---|
| 43 | #include "XSUB.h"
|
|---|
| 44 |
|
|---|
| 45 | #define DL_LOADONCEONLY
|
|---|
| 46 |
|
|---|
| 47 | typedef struct {
|
|---|
| 48 | AV * x_resolve_using;
|
|---|
| 49 | } my_cxtx_t; /* this *must* be named my_cxtx_t */
|
|---|
| 50 |
|
|---|
| 51 | #define DL_CXT_EXTRA /* ask for dl_cxtx to be defined in dlutils.c */
|
|---|
| 52 | #include "dlutils.c" /* SaveError() etc */
|
|---|
| 53 |
|
|---|
| 54 | #define dl_resolve_using (dl_cxtx.x_resolve_using)
|
|---|
| 55 |
|
|---|
| 56 | static char *dlerror()
|
|---|
| 57 | {
|
|---|
| 58 | dTHX;
|
|---|
| 59 | dMY_CXT;
|
|---|
| 60 | return dl_last_error;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | int dlclose(handle) /* stub only */
|
|---|
| 64 | void *handle;
|
|---|
| 65 | {
|
|---|
| 66 | return 0;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | #if NS_TARGET_MAJOR >= 4
|
|---|
| 70 | #import <mach-o/dyld.h>
|
|---|
| 71 |
|
|---|
| 72 | enum dyldErrorSource
|
|---|
| 73 | {
|
|---|
| 74 | OFImage,
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | static void TranslateError
|
|---|
| 78 | (const char *path, enum dyldErrorSource type, int number)
|
|---|
| 79 | {
|
|---|
| 80 | dTHX;
|
|---|
| 81 | dMY_CXT;
|
|---|
| 82 | char *error;
|
|---|
| 83 | unsigned int index;
|
|---|
| 84 | static char *OFIErrorStrings[] =
|
|---|
| 85 | {
|
|---|
| 86 | "%s(%d): Object Image Load Failure\n",
|
|---|
| 87 | "%s(%d): Object Image Load Success\n",
|
|---|
| 88 | "%s(%d): Not a recognisable object file\n",
|
|---|
| 89 | "%s(%d): No valid architecture\n",
|
|---|
| 90 | "%s(%d): Object image has an invalid format\n",
|
|---|
| 91 | "%s(%d): Invalid access (permissions?)\n",
|
|---|
| 92 | "%s(%d): Unknown error code from NSCreateObjectFileImageFromFile\n",
|
|---|
| 93 | };
|
|---|
| 94 | #define NUM_OFI_ERRORS (sizeof(OFIErrorStrings) / sizeof(OFIErrorStrings[0]))
|
|---|
| 95 |
|
|---|
| 96 | switch (type)
|
|---|
| 97 | {
|
|---|
| 98 | case OFImage:
|
|---|
| 99 | index = number;
|
|---|
| 100 | if (index > NUM_OFI_ERRORS - 1)
|
|---|
| 101 | index = NUM_OFI_ERRORS - 1;
|
|---|
| 102 | error = Perl_form_nocontext(OFIErrorStrings[index], path, number);
|
|---|
| 103 | break;
|
|---|
| 104 |
|
|---|
| 105 | default:
|
|---|
| 106 | error = Perl_form_nocontext("%s(%d): Totally unknown error type %d\n",
|
|---|
| 107 | path, number, type);
|
|---|
| 108 | break;
|
|---|
| 109 | }
|
|---|
| 110 | Safefree(dl_last_error);
|
|---|
| 111 | dl_last_error = savepv(error);
|
|---|
|
|---|