14 #define dln_notimplement rb_notimplement 15 #define dln_memerror rb_memerror 16 #define dln_exit rb_exit 17 #define dln_loaderror rb_loaderror 19 #define dln_notimplement --->>> dln not implemented <<<--- 20 #define dln_memerror abort 22 static void dln_loaderror(
const char *format, ...);
34 #if defined(HAVE_ALLOCA_H) 51 #define free(x) xfree(x) 57 #include <sys/types.h> 61 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 64 #ifdef HAVE_SYS_PARAM_H 65 # include <sys/param.h> 68 # define MAXPATHLEN 1024 80 # if defined(HAVE_DLOPEN) 82 # define MACOSX_DLOPEN 90 dln_loaderror(
const char *format, ...)
94 vfprintf(stderr, format, ap);
100 #if defined(HAVE_DLOPEN) && !defined(USE_DLN_A_OUT) && !defined(_AIX) && !defined(MACOSX_DYLD) && !defined(_UNICOSMP) 102 # define USE_DLN_DLOPEN 105 #if defined(__hp9000s300) || ((defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)) && !defined(__ELF__)) || defined(NeXT) || defined(MACOSX_DYLD) 106 # define EXTERNAL_PREFIX "_" 108 # define EXTERNAL_PREFIX "" 110 #define FUNCNAME_PREFIX EXTERNAL_PREFIX"Init_" 112 #if defined __CYGWIN__ || defined DOSISH 113 #define isdirsep(x) ((x) == '/' || (x) == '\\') 115 #define isdirsep(x) ((x) == '/') 119 init_funcname_len(
const char **file)
121 const char *p = *file, *base, *dot =
NULL;
124 for (base = p; *p; p++) {
125 if (*p ==
'.' && !dot) dot = p;
130 return (dot ? dot : p) - base;
135 #define init_funcname(buf, file) do {\ 136 const char *base = (file);\ 137 const size_t flen = init_funcname_len(&base);\ 138 const size_t plen = sizeof(funcname_prefix);\ 139 char *const tmp = ALLOCA_N(char, plen+flen+1);\ 143 memcpy(tmp, funcname_prefix, plen);\ 144 memcpy(tmp+plen, base, flen);\ 145 tmp[plen+flen] = '\0';\ 152 # define LIBC_NAME "libc.a" 155 #ifndef DLN_DEFAULT_LIB_PATH 156 # define DLN_DEFAULT_LIB_PATH "/lib:/usr/lib:/usr/local/lib:." 161 static int dln_errno;
163 #define DLN_ENOEXEC ENOEXEC 164 #define DLN_ECONFL 1201 165 #define DLN_ENOINIT 1202 166 #define DLN_EUNDEF 1203 167 #define DLN_ENOTLIB 1204 168 #define DLN_EBADLIB 1205 169 #define DLN_EINIT 1206 171 static int dln_init_p = 0;
179 # define N_MAGIC(x) (x).a_magic 182 #define INVALID_OBJECT(h) (N_MAGIC(h) != OMAGIC) 190 static int load_lib();
193 load_header(
int fd,
struct exec *hdrp,
long disp)
198 size = read(fd, hdrp,
sizeof(
struct exec));
203 if (size !=
sizeof(
struct exec) || N_BADMAG(*hdrp)) {
204 dln_errno = DLN_ENOEXEC;
211 #define RELOC_SYMBOL(r) ((r)->r_symbolnum) 212 #define RELOC_MEMORY_SUB_P(r) ((r)->r_bsr) 213 #define RELOC_PCREL_P(r) ((r)->r_pcrel || (r)->r_bsr) 214 #define RELOC_TARGET_SIZE(r) ((r)->r_length) 218 #ifndef RELOC_ADDRESS 219 #define RELOC_ADDRESS(r) ((r)->r_address) 220 #define RELOC_EXTERN_P(r) ((r)->r_extern) 221 #define RELOC_SYMBOL(r) ((r)->r_symbolnum) 222 #define RELOC_MEMORY_SUB_P(r) 0 223 #define RELOC_PCREL_P(r) ((r)->r_pcrel) 224 #define RELOC_TARGET_SIZE(r) ((r)->r_length) 227 #if defined(__sun) && defined(__sparc) 229 # undef relocation_info 230 # define relocation_info reloc_info_sparc 231 # define R_RIGHTSHIFT(r) (reloc_r_rightshift[(r)->r_type]) 232 # define R_BITSIZE(r) (reloc_r_bitsize[(r)->r_type]) 233 # define R_LENGTH(r) (reloc_r_length[(r)->r_type]) 234 static int reloc_r_rightshift[] = {
235 0, 0, 0, 0, 0, 0, 2, 2, 10, 0, 0, 0, 0, 0, 0,
237 static int reloc_r_bitsize[] = {
238 8, 16, 32, 8, 16, 32, 30, 22, 22, 22, 13, 10, 32, 32, 16,
240 static int reloc_r_length[] = {
241 0, 1, 2, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
243 # define R_PCREL(r) \ 244 ((r)->r_type >= RELOC_DISP8 && (r)->r_type <= RELOC_WDISP22) 245 # define R_SYMBOL(r) ((r)->r_index) 249 #define R_SYMBOL(r) ((r)->r_symbolnum) 250 #define R_MEMORY_SUB(r) ((r)->r_bsr) 251 #define R_PCREL(r) ((r)->r_pcrel || (r)->r_bsr) 252 #define R_LENGTH(r) ((r)->r_length) 256 # define R_SYMBOL(r) ((r)->r_symbolnum) 257 # define R_MEMORY_SUB(r) 0 258 # define R_PCREL(r) ((r)->r_pcrel) 259 # define R_LENGTH(r) ((r)->r_length) 262 static struct relocation_info *
263 load_reloc(
int fd,
struct exec *hdrp,
long disp)
265 struct relocation_info *reloc;
268 lseek(fd, disp + N_TXTOFF(*hdrp) + hdrp->a_text + hdrp->a_data, 0);
269 size = hdrp->a_trsize + hdrp->a_drsize;
270 reloc = (
struct relocation_info*)
xmalloc(size);
276 if (read(fd, reloc, size) !=
size) {
285 static struct nlist *
286 load_sym(
int fd,
struct exec *hdrp,
long disp)
288 struct nlist * buffer;
294 lseek(fd, N_SYMOFF(*hdrp) + hdrp->a_syms + disp, 0);
295 if (read(fd, &size,
sizeof(
int)) !=
sizeof(
int)) {
299 buffer = (
struct nlist*)
xmalloc(hdrp->a_syms + size);
300 if (buffer ==
NULL) {
305 lseek(fd, disp + N_SYMOFF(*hdrp), 0);
306 if (read(fd, buffer, hdrp->a_syms + size) != hdrp->a_syms + size) {
312 end = sym + hdrp->a_syms /
sizeof(
struct nlist);
313 displ = (long)buffer + (
long)(hdrp->a_syms);
316 sym->n_un.n_name = (
char*)sym->n_un.n_strx + displ;
322 dln_errno = DLN_ENOEXEC;
327 sym_hash(
struct exec *hdrp,
struct nlist *syms)
330 struct nlist *sym = syms;
331 struct nlist *end = syms + (hdrp->a_syms /
sizeof(
struct nlist));
347 dln_init(
const char *prog)
354 if (dln_init_p == 1)
return 0;
357 if (file ==
NULL || (fd = open(file, O_RDONLY)) < 0) {
362 if (load_header(fd, &hdr, 0) == -1)
return -1;
363 syms = load_sym(fd, &hdr, 0);
368 sym_tbl = sym_hash(&hdr, syms);
369 if (sym_tbl ==
NULL) {
376 if (read(fd, &c, 1) == -1) {
380 if (c !=
'#')
goto err_noexec;
381 if (read(fd, &c, 1) == -1) {
385 if (c !=
'!')
goto err_noexec;
389 while (read(fd, &c, 1) == 1) {
390 if (c ==
'\n')
goto err_noexec;
391 if (c !=
'\t' && c !=
' ') {
397 while (read(fd, p, 1) == 1) {
398 if (*p ==
'\n' || *p ==
'\t' || *p ==
' ')
break;
401 dln_errno = ENAMETOOLONG;
407 return dln_init(buf);
416 dln_errno = DLN_ENOEXEC;
421 load_text_data(
int fd,
struct exec *hdrp,
int bss,
long disp)
426 lseek(fd, disp + N_TXTOFF(*hdrp), 0);
427 size = hdrp->a_text + hdrp->a_data;
429 if (bss == -1) size += hdrp->a_bss;
430 else if (bss > 1) size += bss;
432 addr = (
unsigned char*)
xmalloc(size);
438 if (read(fd, addr, size) !=
size) {
445 memset(addr + hdrp->a_text + hdrp->a_data, 0, hdrp->a_bss);
448 memset(addr + hdrp->a_text + hdrp->a_data, 0, bss);
455 undef_print(
char *
key,
char *value)
457 fprintf(stderr,
" %s\n", key);
462 dln_print_undef(
void)
464 fprintf(stderr,
" Undefined symbols:\n");
472 fprintf(stderr,
"dln: Calling undefined function\n");
480 struct relocation_info reloc;
492 link_undef(
const char *
name,
long base,
struct relocation_info *reloc)
496 char *addr = (
char*)(reloc->r_address + base);
498 obj = (
struct undef*)
xmalloc(
sizeof(
struct undef));
502 switch (R_LENGTH(reloc)) {
507 obj->u.s = *(
short*)addr;
510 obj->u.l = *(
long*)addr;
513 if (reloc_tbl ==
NULL) {
525 reloc_undef(
int no,
struct undef *undef,
struct reloc_arg *arg)
529 #if defined(__sun) && defined(__sparc) 530 unsigned int mask = 0;
533 if (strcmp(arg->name, undef->name) != 0)
return ST_CONTINUE;
534 address = (
char*)(undef->base + undef->reloc.r_address);
537 if (R_PCREL(&(undef->reloc))) datum -= undef->base;
538 #
if defined(__sun) && defined(__sparc)
539 datum += undef->reloc.r_addend;
540 datum >>= R_RIGHTSHIFT(&(undef->reloc));
541 mask = (1 << R_BITSIZE(&(undef->reloc))) - 1;
544 switch (R_LENGTH(&(undef->reloc))) {
546 *address = undef->u.c;
551 *(
short *)address = undef->u.s;
552 *(
short *)address &= ~mask;
553 *(
short *)address |= datum;
556 *(
long *)address = undef->u.l;
557 *(
long *)address &= ~mask;
558 *(
long *)address |= datum;
562 switch (R_LENGTH(&(undef->reloc))) {
564 if (R_MEMORY_SUB(&(undef->reloc)))
565 *address = datum - *address;
566 else *address = undef->u.c + datum;
569 if (R_MEMORY_SUB(&(undef->reloc)))
570 *(
short*)address = datum - *(
short*)address;
571 else *(
short*)address = undef->u.s + datum;
574 if (R_MEMORY_SUB(&(undef->reloc)))
575 *(
long*)address = datum - *(
long*)address;
576 else *(
long*)address = undef->u.l + datum;
586 unlink_undef(
const char *name,
long value)
588 struct reloc_arg arg;
601 reloc_repl(
int no,
struct undef *undef,
struct indr_data *data)
603 if (strcmp(data->name0, undef->name) == 0) {
605 undef->name =
strdup(data->name1);
612 load_1(
int fd,
long disp,
const char *need_init)
614 static const char *libc = LIBC_NAME;
616 struct relocation_info *reloc =
NULL;
619 struct nlist *syms =
NULL;
624 if (load_header(fd, &hdr, disp) == -1)
return -1;
625 if (INVALID_OBJECT(hdr)) {
626 dln_errno = DLN_ENOEXEC;
629 reloc = load_reloc(fd, &hdr, disp);
630 if (reloc ==
NULL)
return -1;
632 syms = load_sym(fd, &hdr, disp);
639 end = syms + (hdr.a_syms /
sizeof(
struct nlist));
641 struct nlist *old_sym;
642 int value = sym->n_value;
645 if (sym->n_type == (N_INDR | N_EXT)) {
646 char *
key = sym->n_un.n_name;
648 if (
st_lookup(sym_tbl, sym[1].n_un.n_name, &old_sym)) {
650 unlink_undef(key, old_sym->n_value);
655 struct indr_data data;
657 data.name0 = sym->n_un.n_name;
658 data.name1 = sym[1].n_un.n_name;
670 if (sym->n_type == (N_UNDF | N_EXT)) {
671 if (
st_lookup(sym_tbl, sym->n_un.n_name, &old_sym) == 0) {
677 sym->n_type = N_EXT | N_COMM;
678 sym->n_value = old_sym->n_value;
682 value >=
sizeof(double) ?
sizeof(
double) - 1
683 : value >=
sizeof(long) ?
sizeof(
long) - 1
686 sym->n_type = N_COMM;
688 new_common &= ~(long)rnd;
689 sym->n_value = new_common;
695 sym->n_type = N_EXT | N_COMM;
696 sym->n_value = old_sym->n_value;
699 sym->n_value = (long)dln_undefined;
707 block = load_text_data(fd, &hdr, hdr.a_bss + new_common, disp);
708 if (block == 0)
goto err_exit;
712 struct nlist *new_sym;
715 switch (sym->n_type) {
717 sym->n_value += hdr.a_text + hdr.a_data;
721 sym->n_value += block;
723 if (
st_lookup(sym_tbl, sym->n_un.n_name, &new_sym) != 0
724 && new_sym->n_value != (
long)dln_undefined) {
725 dln_errno = DLN_ECONFL;
729 key = sym->n_un.n_name;
731 unlink_undef(key, sym->n_value);
735 new_sym = (
struct nlist*)
xmalloc(
sizeof(
struct nlist));
737 new_sym->n_un.n_name =
strdup(sym->n_un.n_name);
738 st_insert(sym_tbl, new_sym->n_un.n_name, new_sym);
743 sym->n_value += block;
753 struct relocation_info * rel = reloc;
754 struct relocation_info * rel_beg = reloc +
755 (hdr.a_trsize/
sizeof(
struct relocation_info));
756 struct relocation_info * rel_end = reloc +
757 (hdr.a_trsize+hdr.a_drsize)/
sizeof(
struct relocation_info);
759 while (rel < rel_end) {
760 char *address = (
char*)(rel->r_address + block);
762 #if defined(__sun) && defined(__sparc) 763 unsigned int mask = 0;
767 address += hdr.a_text;
770 sym = &(syms[R_SYMBOL(rel)]);
771 switch (sym->n_type) {
773 link_undef(sym->n_un.n_name, block, rel);
776 datum = sym->n_value;
783 switch (R_SYMBOL(rel)) {
789 datum = block + new_common;
795 if (R_PCREL(rel)) datum -= block;
797 #if defined(__sun) && defined(__sparc) 798 datum += rel->r_addend;
799 datum >>= R_RIGHTSHIFT(rel);
800 mask = (1 << R_BITSIZE(rel)) - 1;
804 switch (R_LENGTH(rel)) {
810 *(
short *)address &= ~mask;
811 *(
short *)address |= datum;
814 *(
long *)address &= ~mask;
815 *(
long *)address |= datum;
819 switch (R_LENGTH(rel)) {
825 *(
short *)address += datum;
828 *(
long *)address += datum;
838 char **libs_to_be_linked = 0;
842 if (load_lib(libc) == -1)
goto err_exit;
848 for (sym = syms; sym<end; sym++) {
849 char *name = sym->n_un.n_name;
850 if (name[0] ==
'_' && sym->n_value >= block) {
851 if (strcmp(name+1,
"dln_libs_to_be_linked") == 0) {
852 libs_to_be_linked = (
char**)sym->n_value;
854 else if (strcmp(name+1, buf) == 0) {
856 ((int (*)())sym->n_value)();
860 if (libs_to_be_linked && undef_tbl->
num_entries > 0) {
861 while (*libs_to_be_linked) {
862 load_lib(*libs_to_be_linked);
871 dln_errno = DLN_ENOINIT;
875 if (load_lib(libc) == -1)
goto err_exit;
877 dln_errno = DLN_EUNDEF;
885 if (syms)
free(syms);
886 if (reloc)
free(reloc);
887 if (block)
free((
char*)block);
891 static int target_offset;
893 search_undef(
const char *key,
int value,
st_table *lib_tbl)
898 target_offset = offset;
907 const char *dln_librrb_ary_path = DLN_DEFAULT_LIB_PATH;
910 load_lib(
const char *lib)
914 char armagic[SARMAG];
922 if (dln_init_p == 0) {
923 dln_errno = DLN_ENOINIT;
928 dln_errno = DLN_EBADLIB;
930 if (lib[0] ==
'-' && lib[1] ==
'l') {
931 long len =
strlen(lib) + 4;
941 path =
getenv(
"DLN_LIBRARY_PATH");
942 if (path ==
NULL) path = dln_librrb_ary_path;
943 else path = envpath =
strdup(path);
946 if (envpath)
free(envpath);
947 fd = open(file, O_RDONLY);
948 if (fd == -1)
goto syserr;
949 size = read(fd, armagic, SARMAG);
950 if (size == -1)
goto syserr;
952 if (size != SARMAG) {
953 dln_errno = DLN_ENOTLIB;
956 size = read(fd, &ahdr,
sizeof(ahdr));
957 if (size == -1)
goto syserr;
958 if (size !=
sizeof(ahdr) || sscanf(ahdr.ar_size,
"%d", &size) != 1) {
962 if (strncmp(ahdr.ar_name,
"__.SYMDEF", 9) == 0) {
967 if (data ==
NULL)
goto syserr;
968 size = read(fd, data, size);
969 nsym = *data /
sizeof(
struct symdef);
970 base = (
struct symdef*)(data + 1);
971 name_base = (
char*)(base + nsym) +
sizeof(int);
973 char *name = name_base + base->rb_str_index;
975 st_insert(lib_tbl, name, base->lib_offset +
sizeof(ahdr));
982 if (target_offset == -1)
break;
983 if (load_1(fd, target_offset, 0) == -1) {
1000 struct nlist *syms, *
sym, *end;
1004 lseek(fd, offset, 0);
1005 size = read(fd, &ahdr,
sizeof(ahdr));
1006 if (size == -1)
goto syserr;
1007 if (size == 0)
break;
1008 if (size !=
sizeof(ahdr)
1009 || sscanf(ahdr.ar_size,
"%d", &size) != 1) {
1012 offset +=
sizeof(ahdr);
1013 if (load_header(fd, &hdr, offset) == -1)
1015 syms = load_sym(fd, &hdr, offset);
1016 if (syms ==
NULL)
goto badlib;
1018 end = syms + (hdr.a_syms /
sizeof(
struct nlist));
1020 if (sym->n_type == N_EXT|N_TEXT
1029 if (load_1(fd, offset, 0) == -1) {
1034 if (offset & 1) offset++;
1045 if (fd >= 0) close(fd);
1050 load(
const char *file)
1055 if (dln_init_p == 0) {
1056 if (dln_init(dln_argv0) == -1)
return -1;
1059 if (file[result-1] ==
'a') {
1060 return load_lib(file);
1063 fd = open(file, O_RDONLY);
1068 result = load_1(fd, 0, file);
1075 dln_sym(
const char *name)
1080 return (
void*)sym->n_value;
1086 #ifdef USE_DLN_DLOPEN 1098 #include <sys/ldr.h> 1102 #if NS_TARGET_MAJOR < 4 1103 #include <mach-o/rld.h> 1105 #include <mach-o/dyld.h> 1106 #ifndef NSLINKMODULE_OPTION_BINDNOW 1107 #define NSLINKMODULE_OPTION_BINDNOW 1 1112 #include <mach-o/dyld.h> 1117 #include <windows.h> 1118 #include <imagehlp.h> 1123 dln_strerror(
char *message,
size_t size)
1125 int error = GetLastError();
1127 size_t len =
snprintf(message, size,
"%d: ", error);
1129 #define format_message(sublang) FormatMessage(\ 1130 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \ 1131 NULL, error, MAKELANGID(LANG_NEUTRAL, (sublang)), \ 1132 message + len, size - len, NULL) 1133 if (format_message(SUBLANG_ENGLISH_US) == 0)
1134 format_message(SUBLANG_DEFAULT);
1135 for (p = message + len; *p; p++) {
1136 if (*p ==
'\n' || *p ==
'\r')
1141 #define dln_strerror() dln_strerror(message, sizeof message) 1142 #elif ! defined _AIX 1146 #ifdef USE_DLN_A_OUT 1149 switch (dln_errno) {
1151 return "Symbol name conflict";
1153 return "No initializer given";
1155 return "Unresolved symbols";
1157 return "Not a library file";
1159 return "Malformed library file";
1161 return "Not initialized";
1167 #ifdef USE_DLN_DLOPEN 1168 return (
char*)dlerror();
1173 #if defined(_AIX) && ! defined(_IA64) 1175 aix_loaderror(
const char *pathname)
1177 char *message[1024], errbuf[1024];
1179 #define ERRBUF_APPEND(s) strlcat(errbuf, (s), sizeof(errbuf)) 1180 snprintf(errbuf,
sizeof(errbuf),
"load failed - %s. ", pathname);
1182 if (loadquery(L_GETMESSAGES, &message[0],
sizeof(message)) != -1) {
1183 ERRBUF_APPEND(
"Please issue below command for detailed reasons:\n\t");
1184 ERRBUF_APPEND(
"/usr/sbin/execerror ruby ");
1185 for (i=0; message[i]; i++) {
1186 ERRBUF_APPEND(
"\"");
1187 ERRBUF_APPEND(message[i]);
1188 ERRBUF_APPEND(
"\" ");
1190 ERRBUF_APPEND(
"\n");
1194 ERRBUF_APPEND(
"[loadquery failed]");
1196 dln_loaderror(
"%s", errbuf);
1200 #if defined _WIN32 && defined RUBY_EXPORT 1201 HANDLE rb_libruby_handle(
void);
1204 rb_w32_check_imported(HMODULE ext, HMODULE mine)
1207 const IMAGE_IMPORT_DESCRIPTOR *desc;
1209 desc = ImageDirectoryEntryToData(ext,
TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size);
1210 if (!desc)
return 0;
1211 while (desc->Name) {
1212 PIMAGE_THUNK_DATA pint = (PIMAGE_THUNK_DATA)((
char *)ext + desc->Characteristics);
1213 PIMAGE_THUNK_DATA piat = (PIMAGE_THUNK_DATA)((
char *)ext + desc->FirstThunk);
1214 for (; piat->u1.Function; piat++, pint++) {
1215 static const char prefix[] =
"rb_";
1216 PIMAGE_IMPORT_BY_NAME pii;
1219 if (IMAGE_SNAP_BY_ORDINAL(pint->u1.Ordinal))
continue;
1220 pii = (PIMAGE_IMPORT_BY_NAME)((
char *)ext + (size_t)pint->u1.AddressOfData);
1221 name = (
const char *)pii->Name;
1222 if (strncmp(name, prefix,
sizeof(prefix) - 1) == 0) {
1223 FARPROC addr = GetProcAddress(mine, name);
1224 if (addr)
return (FARPROC)piat->u1.Function == addr;
1233 #if defined(DLN_NEEDS_ALT_SEPARATOR) && DLN_NEEDS_ALT_SEPARATOR 1234 #define translit_separator(src) do { \ 1235 char *tmp = ALLOCA_N(char, strlen(src) + 1), *p = tmp, c; \ 1237 *p++ = ((c = *file++) == '/') ? DLN_NEEDS_ALT_SEPARATOR : c; \ 1242 #define translit_separator(str) (void)(str) 1248 #if (defined _WIN32 || defined USE_DLN_DLOPEN) && defined RUBY_EXPORT 1249 static const char incompatible[] =
"incompatible library version";
1251 #if !defined(_AIX) && !defined(NeXT) 1252 const char *error = 0;
1272 handle = LoadLibraryW(winfile);
1276 error = dln_strerror();
1280 #if defined _WIN32 && defined RUBY_EXPORT 1281 if (!rb_w32_check_imported(handle, rb_libruby_handle())) {
1282 FreeLibrary(handle);
1283 error = incompatible;
1288 if ((init_fct = (
void(*)())GetProcAddress(handle, buf)) ==
NULL) {
1289 dln_loaderror(
"%s - %s\n%s", dln_strerror(), buf, file);
1296 #ifdef USE_DLN_A_OUT 1297 if (load(file) == -1) {
1298 error = dln_strerror();
1309 #ifdef USE_DLN_DLOPEN 1316 # define RTLD_LAZY 1 1322 # define RTLD_GLOBAL 0 1326 if ((handle = (
void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) ==
NULL) {
1327 error = dln_strerror();
1330 # if defined RUBY_EXPORT 1335 # if defined __APPLE__ && \ 1336 defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \ 1337 (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11) 1339 rb_fatal(
"%s - %s", incompatible, file);
1342 error = incompatible;
1349 init_fct = (void(*)())(
VALUE)dlsym(handle, buf);
1350 if (init_fct ==
NULL) {
1351 const size_t errlen =
strlen(error = dln_strerror()) + 1;
1352 error = memcpy(
ALLOCA_N(
char, errlen), error, errlen);
1370 flags = BIND_DEFERRED;
1371 lib = shl_load(file, flags, 0);
1374 dln_loaderror(
"%s - %s",
strerror(errno), file);
1376 shl_findsym(&lib, buf, TYPE_PROCEDURE, (
void*)&init_fct);
1377 if (init_fct ==
NULL) {
1378 shl_findsym(&lib, buf, TYPE_UNDEFINED, (
void*)&init_fct);
1379 if (init_fct ==
NULL) {
1381 dln_loaderror(
"%s - %s",
strerror(ENOSYM), file);
1389 #if defined(_AIX) && ! defined(_IA64) 1394 init_fct = (void(*)())load((
char*)file, 1, 0);
1395 if (init_fct ==
NULL) {
1396 aix_loaderror(file);
1398 if (loadbind(0, (
void*)
dln_load, (
void*)init_fct) == -1) {
1399 aix_loaderror(file);
1402 return (
void*)init_fct;
1406 #if defined(MACOSX_DYLD) 1419 NSObjectFileImage obj_file;
1426 dyld_result = NSCreateObjectFileImageFromFile(file, &obj_file);
1428 if (dyld_result != NSObjectFileImageSuccess) {
1429 dln_loaderror(
"Failed to load %.200s", file);
1432 NSLinkModule(obj_file, file, NSLINKMODULE_OPTION_BINDNOW);
1435 if (!NSIsSymbolNameDefined(buf)) {
1436 dln_loaderror(
"Failed to lookup Init function %.200s",file);
1438 init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
1441 return (
void*)init_fct;
1451 #if !defined(_AIX) && !defined(NeXT) 1453 dln_loaderror(
"%s - %s", error, file);
void rb_fatal(const char *fmt,...)
size_t strlen(const char *)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
#define ALLOCA_N(type, n)
#define rb_str_index(str, sub, offset)
#define init_funcname(buf, file)
unsigned char buf[MIME_BUF_SIZE]
void * dln_load(const char *file)
register unsigned int len
void * ruby_xmalloc(size_t size)
RUBY_EXTERN char * strerror(int)
WCHAR * rb_w32_mbstr_to_wstr(UINT, const char *, int, long *)
#define translit_separator(str)
RUBY_SYMBOL_EXPORT_BEGIN void * alloca()