added a library table for module autoloading
updated VM plugin loader to read in this new section --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40149
This commit is contained in:
parent
5c6f81cb25
commit
13775b11b6
@ -16,6 +16,7 @@ enum FileSections
|
|||||||
FS_Publics,
|
FS_Publics,
|
||||||
FS_Pubvars,
|
FS_Pubvars,
|
||||||
FS_Natives,
|
FS_Natives,
|
||||||
|
FS_Libraries,
|
||||||
FS_Nametable, /* required */
|
FS_Nametable, /* required */
|
||||||
FS_DbgFile,
|
FS_DbgFile,
|
||||||
FS_DbgSymbol,
|
FS_DbgSymbol,
|
||||||
@ -47,7 +48,7 @@ int main(int argc, char *argv[])
|
|||||||
sp_file_t *spf;
|
sp_file_t *spf;
|
||||||
memfile_t *dbgtab = NULL; //dbgcrab
|
memfile_t *dbgtab = NULL; //dbgcrab
|
||||||
unsigned char *dbgptr = NULL;
|
unsigned char *dbgptr = NULL;
|
||||||
uint32_t sections[FS_Number] = {1,1,0,0,0,1,0,0,0,0,0,0};
|
uint32_t sections[FS_Number] = {1,1,0,0,0,0,1,0,0,0,0,0,0};
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (bin_file == NULL)
|
if (bin_file == NULL)
|
||||||
@ -87,6 +88,11 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
spfw_add_section(spf, ".natives");
|
spfw_add_section(spf, ".natives");
|
||||||
}
|
}
|
||||||
|
sections[FS_Libraries] = (hdr->pubvars - hdr->libraries) / hdr->defsize;
|
||||||
|
if (sections[FS_Libraries])
|
||||||
|
{
|
||||||
|
spfw_add_section(spf, ".libraries");
|
||||||
|
}
|
||||||
|
|
||||||
spfw_add_section(spf, ".names");
|
spfw_add_section(spf, ".names");
|
||||||
|
|
||||||
@ -251,6 +257,31 @@ int main(int argc, char *argv[])
|
|||||||
spfw_next_section(spf);
|
spfw_next_section(spf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sections[FS_Libraries])
|
||||||
|
{
|
||||||
|
sp_file_libraries_t *libtbl;
|
||||||
|
AMX_FUNCSTUBNT *stub;
|
||||||
|
unsigned char *stubptr;
|
||||||
|
uint32_t libraries = sections[FS_Libraries];
|
||||||
|
|
||||||
|
libtbl = (sp_file_libraries_t *)malloc(sizeof(sp_file_libraries_t) * libraries);
|
||||||
|
stubptr = (unsigned char *)hdr + hdr->libraries;
|
||||||
|
|
||||||
|
for (i=0; i<libraries; i++)
|
||||||
|
{
|
||||||
|
stub = (AMX_FUNCSTUBNT *)stubptr;
|
||||||
|
libtbl[i].name = stub->nameofs - (hdr->nametable + sizeof(uint16_t));
|
||||||
|
|
||||||
|
stubptr += hdr->defsize;
|
||||||
|
}
|
||||||
|
if (libraries)
|
||||||
|
{
|
||||||
|
sfwrite(libtbl, sizeof(sp_file_libraries_t), libraries, spf);
|
||||||
|
}
|
||||||
|
free(libtbl);
|
||||||
|
spfw_next_section(spf);
|
||||||
|
}
|
||||||
|
|
||||||
if (sections[FS_Nametable])
|
if (sections[FS_Nametable])
|
||||||
{
|
{
|
||||||
unsigned char *base;
|
unsigned char *base;
|
||||||
|
@ -1071,8 +1071,28 @@ static int command(void)
|
|||||||
lptr=(unsigned char*)strchr((char*)lptr,'\0'); /* skip to end (ignore "extra characters on line") */
|
lptr=(unsigned char*)strchr((char*)lptr,'\0'); /* skip to end (ignore "extra characters on line") */
|
||||||
} else if (strcmp(str,"dynamic")==0) {
|
} else if (strcmp(str,"dynamic")==0) {
|
||||||
preproc_expr(&pc_stksize,NULL);
|
preproc_expr(&pc_stksize,NULL);
|
||||||
} else if (strcmp(str,"library")==0) {
|
} else if (!strcmp(str,"library")
|
||||||
char name[sNAMEMAX+1];
|
||!strcmp(str,"reqclass")
|
||||||
|
||!strcmp(str,"loadlib")
|
||||||
|
||!strcmp(str,"explib")
|
||||||
|
||!strcmp(str,"expclass")
|
||||||
|
||!strcmp(str,"defclasslib")) {
|
||||||
|
char name[sNAMEMAX+1],sname[sNAMEMAX+1];
|
||||||
|
const char *prefix="";
|
||||||
|
sname[0]='\0';
|
||||||
|
sname[1]='\0';
|
||||||
|
if (!strcmp(str,"library"))
|
||||||
|
prefix="??li_";
|
||||||
|
else if (!strcmp(str,"reqclass"))
|
||||||
|
prefix="??rc_";
|
||||||
|
else if (!strcmp(str,"loadlib"))
|
||||||
|
prefix="??f_";
|
||||||
|
else if (!strcmp(str,"explib"))
|
||||||
|
prefix="??el_";
|
||||||
|
else if (!strcmp(str,"expclass"))
|
||||||
|
prefix="??ec_";
|
||||||
|
else if (!strcmp(str,"defclasslib"))
|
||||||
|
prefix="??d_";
|
||||||
while (*lptr<=' ' && *lptr!='\0')
|
while (*lptr<=' ' && *lptr!='\0')
|
||||||
lptr++;
|
lptr++;
|
||||||
if (*lptr=='"') {
|
if (*lptr=='"') {
|
||||||
@ -1082,6 +1102,18 @@ static int command(void)
|
|||||||
for (i=0; i<sizeof name && (alphanum(*lptr) || *lptr=='-'); i++,lptr++)
|
for (i=0; i<sizeof name && (alphanum(*lptr) || *lptr=='-'); i++,lptr++)
|
||||||
name[i]=*lptr;
|
name[i]=*lptr;
|
||||||
name[i]='\0';
|
name[i]='\0';
|
||||||
|
if (!strncmp(str,"exp",3) || !strncmp(str,"def",3)) {
|
||||||
|
while (*lptr && isspace(*lptr))
|
||||||
|
lptr++;
|
||||||
|
for (i=1; i<sizeof sname && alphanum(*lptr); i++,lptr++)
|
||||||
|
sname[i]=*lptr;
|
||||||
|
sname[i]='\0';
|
||||||
|
if (!sname[1]) {
|
||||||
|
error(45);
|
||||||
|
} else {
|
||||||
|
sname[0]='_';
|
||||||
|
}
|
||||||
|
}
|
||||||
} /* if */
|
} /* if */
|
||||||
if (strlen(name)==0) {
|
if (strlen(name)==0) {
|
||||||
curlibrary=NULL;
|
curlibrary=NULL;
|
||||||
@ -1089,8 +1121,19 @@ static int command(void)
|
|||||||
pc_addlibtable=FALSE;
|
pc_addlibtable=FALSE;
|
||||||
} else {
|
} else {
|
||||||
/* add the name if it does not yet exist in the table */
|
/* add the name if it does not yet exist in the table */
|
||||||
if (find_constval(&libname_tab,name,0)==NULL)
|
char newname[sNAMEMAX+1];
|
||||||
curlibrary=append_constval(&libname_tab,name,0,0);
|
if (strlen(name)+strlen(prefix)+strlen(sname)<=sNAMEMAX) {
|
||||||
|
strcpy(newname,prefix);
|
||||||
|
strcat(newname,name);
|
||||||
|
strcat(newname,sname);
|
||||||
|
if (find_constval(&libname_tab,newname,0)==NULL) {
|
||||||
|
if (!strcmp(str,"library") || !strcmp(str,"reqclass")) {
|
||||||
|
curlibrary=append_constval(&libname_tab,newname,1,0);
|
||||||
|
} else {
|
||||||
|
append_constval(&libname_tab,newname,1,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} /* if */
|
} /* if */
|
||||||
#if 0 /* more unused */
|
#if 0 /* more unused */
|
||||||
} else if (strcmp(str,"pack")==0) {
|
} else if (strcmp(str,"pack")==0) {
|
||||||
|
@ -91,6 +91,12 @@ typedef struct sp_file_natives_s
|
|||||||
uint32_t name; /* name of native at index */
|
uint32_t name; /* name of native at index */
|
||||||
} sp_file_natives_t;
|
} sp_file_natives_t;
|
||||||
|
|
||||||
|
/* section is .libraries */
|
||||||
|
typedef struct sp_file_libraries_s
|
||||||
|
{
|
||||||
|
uint32_t name; /* index into nametable */
|
||||||
|
} sp_file_libraries_t;
|
||||||
|
|
||||||
/* section is .pubvars */
|
/* section is .pubvars */
|
||||||
typedef struct sp_file_pubvars_s
|
typedef struct sp_file_pubvars_s
|
||||||
{
|
{
|
||||||
|
@ -52,6 +52,8 @@ typedef struct sp_plugin_infotab_s
|
|||||||
sp_file_natives_t *natives; /* native table */
|
sp_file_natives_t *natives; /* native table */
|
||||||
uint32_t pubvars_num; /* number of pubvars */
|
uint32_t pubvars_num; /* number of pubvars */
|
||||||
sp_file_pubvars_t *pubvars; /* pubvars table */
|
sp_file_pubvars_t *pubvars; /* pubvars table */
|
||||||
|
uint32_t libraries_num; /* number of libraries */
|
||||||
|
sp_file_libraries_t *lib; /* library table */
|
||||||
} sp_plugin_infotab_t;
|
} sp_plugin_infotab_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,6 +107,11 @@ sp_plugin_t *_ReadPlugin(sp_file_hdr_t *hdr, uint8_t *base, sp_plugin_t *plugin,
|
|||||||
plugin->info.natives_num = secptr->size / sizeof(sp_file_natives_t);
|
plugin->info.natives_num = secptr->size / sizeof(sp_file_natives_t);
|
||||||
plugin->info.natives = (sp_file_natives_t *)(base + secptr->dataoffs);
|
plugin->info.natives = (sp_file_natives_t *)(base + secptr->dataoffs);
|
||||||
}
|
}
|
||||||
|
else if (!(plugin->info.lib) && !strcmp(nameptr, ".libraries"))
|
||||||
|
{
|
||||||
|
plugin->info.libraries_num = secptr->size / sizeof(sp_file_libraries_t);
|
||||||
|
plugin->info.lib = (sp_file_libraries_t *)(base + secptr->dataoffs);
|
||||||
|
}
|
||||||
else if (!(plugin->info.stringbase) && !strcmp(nameptr, ".names"))
|
else if (!(plugin->info.stringbase) && !strcmp(nameptr, ".names"))
|
||||||
{
|
{
|
||||||
plugin->info.stringbase = (const char *)(base + secptr->dataoffs);
|
plugin->info.stringbase = (const char *)(base + secptr->dataoffs);
|
||||||
|
Loading…
Reference in New Issue
Block a user