diff options
author | midipix <writeonce@midipix.org> | 2018-08-03 20:56:45 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-08-03 21:13:30 -0400 |
commit | a3e2cfa926e49bb4f63557bd990f83b8f4685734 (patch) | |
tree | 3edaf363a11a1fe1050780de272309ca0ac40db8 /src/object | |
parent | 18a091990a2de49fb0c9d85b0ae8e86825f2104f (diff) | |
download | mdso-a3e2cfa926e49bb4f63557bd990f83b8f4685734.tar.bz2 mdso-a3e2cfa926e49bb4f63557bd990f83b8f4685734.tar.xz |
library interfaces: object file generation: simplify, re-implement with mmap.
Diffstat (limited to 'src/object')
-rw-r--r-- | src/object/mdso_objgen_dsometa.c | 38 | ||||
-rw-r--r-- | src/object/mdso_objgen_symentry.c | 38 | ||||
-rw-r--r-- | src/object/mdso_objgen_symfn.c | 38 |
3 files changed, 60 insertions, 54 deletions
diff --git a/src/object/mdso_objgen_dsometa.c b/src/object/mdso_objgen_dsometa.c index dfe8a33..388e296 100644 --- a/src/object/mdso_objgen_dsometa.c +++ b/src/object/mdso_objgen_dsometa.c @@ -9,6 +9,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <sys/mman.h> #include <mdso/mdso.h> #include <mdso/mdso_specs.h> @@ -32,11 +33,11 @@ struct mdso_dsometa_object { int mdso_objgen_dsometa( const struct mdso_driver_ctx * dctx, - FILE * fout, struct mdso_object * vobj) { struct mdso_dsometa_object * dsometa; struct pe_raw_coff_symbol * symrec; + void * addr; unsigned char * mark; struct pe_raw_aux_rec_section * aux; size_t buflen; @@ -65,21 +66,25 @@ int mdso_objgen_dsometa( cstlen = (3 * liblen) + 48; objlen = sizeof(*dsometa) + cstlen; - if (vobj && vobj->addr && (vobj->size < objlen)) + if (vobj->addr && (vobj->size < objlen)) return MDSO_BUFFER_ERROR(dctx); - if (vobj && !vobj->addr) { - vobj->size = objlen; + if ((addr = vobj->addr)) { + (void)0; + + } else { + vobj->size = objlen; vobj->mapstrsnum = 1; vobj->mapstrslen = 10 + liblen; - return 0; - } - if (vobj) - dsometa = (struct mdso_dsometa_object *)vobj->addr; + if (!vobj->name) + return 0; + + else if (mdso_create_object(dctx,vobj) < 0) + return MDSO_NESTED_ERROR(dctx); + } - else if (!(dsometa = calloc(1,objlen))) - return MDSO_SYSTEM_ERROR(dctx); + dsometa = (struct mdso_dsometa_object *)vobj->addr; if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) { reclen = sizeof(struct mdso_meta_record_m64); @@ -220,20 +225,17 @@ int mdso_objgen_dsometa( memcpy(&mark[9],dctx->cctx->libname,liblen); /* archive symbol map */ - if (vobj && vobj->mapstrs) + if (vobj->mapstrs) memcpy(vobj->mapstrs,mark,9+liblen); /* .libname */ mark = dsometa->hdr.cfh_machine; memcpy(&mark[stroff],dctx->cctx->libname,liblen); - /* tada */ - if (fout) - if (fwrite(dsometa,objlen,1,fout) == 0) - return MDSO_FILE_ERROR(dctx); - - if (!vobj) - free(dsometa); + /* fs object unmap */ + if (!addr) + munmap(vobj->addr,vobj->size); + /* tada */ return 0; } diff --git a/src/object/mdso_objgen_symentry.c b/src/object/mdso_objgen_symentry.c index 47167c7..7ddc14c 100644 --- a/src/object/mdso_objgen_symentry.c +++ b/src/object/mdso_objgen_symentry.c @@ -9,6 +9,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <sys/mman.h> #include <mdso/mdso.h> #include "mdso_object_impl.h" @@ -32,11 +33,11 @@ struct mdso_symentry_object { int mdso_objgen_symentry( const struct mdso_driver_ctx * dctx, const char * sym, - FILE * fout, struct mdso_object * vobj) { struct mdso_symentry_object * syment; struct pe_raw_coff_symbol * symrec; + void * addr; unsigned char * mark; unsigned char * mapsym; struct pe_raw_aux_rec_section * aux; @@ -71,21 +72,25 @@ int mdso_objgen_symentry( objlen = sizeof(*syment) + cstlen; uscore = !(dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR); - if (vobj && vobj->addr && (vobj->size < objlen)) + if (vobj->addr && (vobj->size < objlen)) return MDSO_BUFFER_ERROR(dctx); - if (vobj && !vobj->addr) { - vobj->size = objlen; + if ((addr = vobj->addr)) { + (void)0; + + } else { + vobj->size = objlen; vobj->mapstrsnum = 1; vobj->mapstrslen = 7 + uscore + symlen; - return 0; - } - if (vobj) - syment = (struct mdso_symentry_object *)vobj->addr; + if (!vobj->name) + return 0; + + else if (mdso_create_object(dctx,vobj) < 0) + return MDSO_NESTED_ERROR(dctx); + } - else if (!(syment = calloc(1,objlen))) - return MDSO_SYSTEM_ERROR(dctx); + syment = (struct mdso_symentry_object *)vobj->addr; if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) { aattr = PE_IMAGE_SCN_ALIGN_16BYTES; @@ -238,7 +243,7 @@ int mdso_objgen_symentry( symrec += 1; /* archive symbol map */ - if (vobj && vobj->mapstrs) + if (vobj->mapstrs) memcpy(vobj->mapstrs,mapsym,mark-mapsym); /* coff symbol: .dsometa_libname */ @@ -255,13 +260,10 @@ int mdso_objgen_symentry( mark = syment->hdr.cfh_machine; memcpy(&mark[stroff],sym,symlen); - /* tada */ - if (fout) - if (fwrite(syment,objlen,1,fout) == 0) - return MDSO_FILE_ERROR(dctx); - - if (!vobj) - free(syment); + /* fs object unmap */ + if (!addr) + munmap(vobj->addr,vobj->size); + /* tada */ return 0; } diff --git a/src/object/mdso_objgen_symfn.c b/src/object/mdso_objgen_symfn.c index 47f9280..6f4ac68 100644 --- a/src/object/mdso_objgen_symfn.c +++ b/src/object/mdso_objgen_symfn.c @@ -9,6 +9,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <sys/mman.h> #include <mdso/mdso.h> #include "mdso_object_impl.h" @@ -46,12 +47,12 @@ struct mdso_symfn_object { int mdso_objgen_symfn( const struct mdso_driver_ctx * dctx, const char * sym, - FILE * fout, struct mdso_object * vobj) { struct mdso_symfn_object * symfn; struct pe_raw_coff_symbol * symrec; const unsigned char * code; + void * addr; unsigned char * mark; unsigned char * mapsym; struct pe_raw_aux_rec_section * aux; @@ -80,21 +81,25 @@ int mdso_objgen_symfn( objlen = sizeof(*symfn) + cstlen; uscore = !(dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR); - if (vobj && vobj->addr && (vobj->size < objlen)) + if (vobj->addr && (vobj->size < objlen)) return MDSO_BUFFER_ERROR(dctx); - if (vobj && !vobj->addr) { - vobj->size = objlen; + if ((addr = vobj->addr)) { + (void)0; + + } else { + vobj->size = objlen; vobj->mapstrsnum = 1; vobj->mapstrslen = 1 + uscore + symlen; - return 0; - } - if (vobj) - symfn = (struct mdso_symfn_object *)vobj->addr; + if (!vobj->name) + return 0; + + else if (mdso_create_object(dctx,vobj) < 0) + return MDSO_NESTED_ERROR(dctx); + } - else if (!(symfn = calloc(1,objlen))) - return MDSO_SYSTEM_ERROR(dctx); + symfn = (struct mdso_symfn_object *)vobj->addr; if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) { code = jmp_code_amd64; @@ -206,7 +211,7 @@ int mdso_objgen_symfn( symrec += 2; /* archive symbol map */ - if (vobj && vobj->mapstrs) + if (vobj->mapstrs) memcpy(vobj->mapstrs,mapsym,mark-mapsym); /* coff symbol: __imp_sym */ @@ -227,13 +232,10 @@ int mdso_objgen_symfn( mark++; } - /* tada */ - if (fout) - if (fwrite(symfn,objlen,1,fout) == 0) - return MDSO_FILE_ERROR(dctx); - - if (!vobj) - free(symfn); + /* fs object unmap */ + if (!addr) + munmap(vobj->addr,vobj->size); + /* tada */ return 0; } |