diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/mdso_unit_ctx.c | 24 | ||||
-rw-r--r-- | src/internal/mdso_driver_impl.h | 1 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/driver/mdso_unit_ctx.c b/src/driver/mdso_unit_ctx.c index 4d068bf..01ef303 100644 --- a/src/driver/mdso_unit_ctx.c +++ b/src/driver/mdso_unit_ctx.c @@ -22,6 +22,9 @@ static int mdso_free_unit_ctx_impl(struct mdso_unit_ctx_impl * ctx, int status) if (ctx->expsyms && ctx->expsyms->buffer) free(ctx->expsyms->buffer); + if (ctx->expsyms && ctx->expsyms->stype) + free(ctx->expsyms->stype); + if (ctx->expsyms) free(ctx->expsyms); @@ -90,8 +93,10 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) size_t nbytes; size_t size; char * dst; + const char * base; const char * ch; const char ** sym; + int stype; const char exphdr[] = "EXPORTS\n"; const char imphdr[] = "IMPORTS\n"; @@ -103,7 +108,7 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) nsyms += (*ch == '\n'); size = offsetof(struct mdso_unit_ctx_impl,expsyms); - size += (nsyms+1)*sizeof(const char *); + size += (++nsyms)*sizeof(const char *); if (!(ctx->expsyms = calloc(1,size))) return -1; @@ -111,6 +116,10 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) if (!(ctx->expsyms->buffer = calloc(1,ctx->map.size))) return -1; + if (!(ctx->expsyms->stype = calloc(nsyms,sizeof(int)))) + return -1; + + base = ctx->map.addr; ch = ctx->map.addr; nbytes = ctx->map.size; sym = ctx->expsyms->syms; @@ -135,7 +144,7 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) while (nbytes && ((nbytes < size) || (strncmp(ch,imphdr,size)))) { /* vector */ - *sym++ = dst; + *sym = dst; /* symbol */ for (; nbytes && ((*ch!=' ') @@ -150,6 +159,16 @@ static int mdso_create_symbol_vector(struct mdso_unit_ctx_impl * ctx) for (; nbytes && (*ch!='\n'); nbytes--) ch++; + /* stype */ + stype = ((*ch=='\n') + && ((ch-base) >= 6) + && !strncmp(&ch[-5]," DATA\n",6)) + ? MDSO_SYMBOL_TYPE_DATA + : MDSO_SYMBOL_TYPE_CODE; + + ctx->expsyms->stype[sym - ctx->expsyms->syms] = stype; + sym++; + /* advance to next symbol */ for (; nbytes && ((*ch==' ') || (*ch=='\t') @@ -213,6 +232,7 @@ int mdso_get_unit_ctx( ctx->uctx.map = &ctx->map; ctx->uctx.cctx = &ctx->cctx; ctx->uctx.syms = ctx->expsyms->syms; + ctx->uctx.stype = ctx->expsyms->stype; *pctx = &ctx->uctx; return 0; diff --git a/src/internal/mdso_driver_impl.h b/src/internal/mdso_driver_impl.h index 6b092dc..dc658af 100644 --- a/src/internal/mdso_driver_impl.h +++ b/src/internal/mdso_driver_impl.h @@ -28,6 +28,7 @@ enum app_tags { struct mdso_expsyms { char * buffer; + int * stype; const char * syms[]; }; |