/************************************************************************* * * (c) Copyright 1992 - 1995 by G & A Technical Software, Inc., * 28 Research Drive, Hampton, Virginia, 23666. * * All Rights Reserved. No part of this software or publication may be * reproduced, stored in a retrieval system, or transmitted, in any form * or by any means, electronic, mechanical, photocopying, recording, or * otherwise without the prior written permission of G & A Technical * Software, Inc. * ************************************************************************* * * Filename: s3_dynamic_module_load.c * * Purpose: Provides the ability to dynamically load modules where * O/S provides necessary support. Currently supports two * methods of dynamic loading, GNU dld and dlopen/dlclose/etc * for ELF based systems. * * Author: John Burton * * Date: 5/31/94 * ************************************************************************* * * Modification History: * * $Log$ * ************************************************************************* * * Revision Control Information: */ static char rcsid[] = "$Id$"; static char rcsrev[] = "$Revision$"; #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_externals.h" #include "s3_globals.h" #include typedef struct mlstruct { char *name; char *file; struct mlstruct *next; } Mod_list; static Mod_list *Modules = NULL; int s3_dml_init (char *path) { } extern File_list *lib_list; void s3_load_dynamic_modules(EMT_struct *emt_info) { int i,result; ST_entry *entry; char *tmp; void *handle; File_list *curr; curr = lib_list; fprintf(fperr,"Loading Dynamic Modules "); for(i=0;inexe;i++) { fprintf(fperr,"."); entry = emt_info->exe_list[i]; if((handle = dlopen(entry->en.filename,RTLD_LAZY)) == NULL) s3_error(SYS,"s3_load_dynamic_modules: %s",dlerror()); if(((entry->en.function = (int (*)()) dlsym(handle,entry->en.name)) == NULL) && ((tmp = dlerror()) != NULL)) s3_error(SYS,"s3_load_dynamic_modules: %s",tmp); } fprintf(fperr," done\n"); } void s3_dml_unload_symbol(char *symbol) { } void s3_compile_dynamic_modules(EMT_struct *emt_info) { int len, ulen, result, i; ST_entry *entry; char *tmp; extern char *uliblist; extern char *applib; uliblist = (uliblist == NULL) ? strdup(" ") : uliblist; ulen = (uliblist != NULL) ? strlen(uliblist) : 0; len = strlen(Compile_Flags) + strlen(applib) + ulen + strlen(D_LOADFLAGS) + 80; tmp = (char *)xmalloc(len*sizeof(char)); fprintf(fperr,"Compiling Dynamic Modules "); for(i=0;inexe;i++) { fprintf(fperr,"."); entry = emt_info->exe_list[i]; sprintf(tmp,"cc %s -o %s -bM:SRE -e %s %s %s %s", Compile_Flags,entry->en.filename,entry->en.name,applib,uliblist,D_LOADFLAGS); result = system(tmp); if(result < 0) s3_error(SYS,"s3_compile_dynamic_modules: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"s3_compile_dynamic_modules: system call returned %d for command %s",result,tmp); } fprintf(fperr," done\n"); xfree(tmp); } void s3_put_file_module(char * name) { char nm_command[80]; char dummy[80]; char symbol[80]; FILE* pipe; int result; Mod_list *tmp; strcpy(nm_command,"/usr/ucb/nm -p "); strcat(nm_command,name); pipe = popen(nm_command,"r"); while (!feof(pipe)) { fgets(dummy,80,pipe); strcpy(symbol,&dummy[8]); if (!strncmp(symbol," T ",3)) { symbol[strlen(symbol) - 1] = '\0'; tmp = (Mod_list *)xmalloc(sizeof(Mod_list)); tmp->name = strsave(&symbol[4]); tmp->file = strsave(name); tmp->next = Modules; Modules = tmp; } } result = pclose(pipe); } char *s3_get_module_file(char *name) { Mod_list *tmp; char *filename; int result; tmp = Modules; while((tmp != NULL)&&((result = strcmp(name,tmp->name)) != 0)) { tmp = tmp->next; } if(tmp != NULL) return tmp->file; else return NULL; }