From 00a88c01dc20c33da1936600d46974d460a23cc4 Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 8 Feb 2017 01:08:41 -0500 Subject: project: source tree: tidy up. --- project/common.mk | 8 ++-- project/tree.mk | 1 + src/helper/mdso_create_asm_source.c | 66 ------------------------- src/helper/mdso_create_output.c | 66 +++++++++++++++++++++++++ src/helper/mdso_map_input.c | 62 ++++++++++++++++++++++++ src/logic/mdso_create_implib_sources.c | 85 --------------------------------- src/logic/mdso_map_input.c | 62 ------------------------ src/object/mdso_create_implib_objects.c | 79 ------------------------------ src/util/mdso_create_implib_objects.c | 79 ++++++++++++++++++++++++++++++ src/util/mdso_create_implib_sources.c | 85 +++++++++++++++++++++++++++++++++ 10 files changed, 297 insertions(+), 296 deletions(-) delete mode 100644 src/helper/mdso_create_asm_source.c create mode 100644 src/helper/mdso_create_output.c create mode 100644 src/helper/mdso_map_input.c delete mode 100644 src/logic/mdso_create_implib_sources.c delete mode 100644 src/logic/mdso_map_input.c delete mode 100644 src/object/mdso_create_implib_objects.c create mode 100644 src/util/mdso_create_implib_objects.c create mode 100644 src/util/mdso_create_implib_sources.c diff --git a/project/common.mk b/project/common.mk index 65bcd2e..8823bcc 100644 --- a/project/common.mk +++ b/project/common.mk @@ -4,19 +4,19 @@ API_SRCS = \ src/driver/mdso_amain.c \ src/driver/mdso_driver_ctx.c \ src/driver/mdso_unit_ctx.c \ - src/helper/mdso_create_asm_source.c \ - src/logic/mdso_create_implib_sources.c \ + src/helper/mdso_create_output.c \ + src/helper/mdso_map_input.c \ src/logic/mdso_asmgen_dsometa.c \ src/logic/mdso_asmgen_symentry.c \ src/logic/mdso_asmgen_symfn.c \ - src/logic/mdso_map_input.c \ - src/object/mdso_create_implib_objects.c \ src/object/mdso_objgen_dsometa.c \ src/object/mdso_objgen_symentry.c \ src/object/mdso_objgen_symfn.c \ src/output/mdso_output_error.c \ src/output/mdso_output_export_symbols.c \ src/skin/mdso_skin_default.c \ + src/util/mdso_create_implib_objects.c \ + src/util/mdso_create_implib_sources.c \ INTERNAL_SRCS = \ src/internal/$(PACKAGE)_errinfo_impl.c \ diff --git a/project/tree.mk b/project/tree.mk index 063788c..ce61482 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -8,4 +8,5 @@ tree.tag: mkdir -p src/object mkdir -p src/output mkdir -p src/skin + mkdir -p src/util touch tree.tag diff --git a/src/helper/mdso_create_asm_source.c b/src/helper/mdso_create_asm_source.c deleted file mode 100644 index b152697..0000000 --- a/src/helper/mdso_create_asm_source.c +++ /dev/null @@ -1,66 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ -/****************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include -#include "mdso_driver_impl.h" -#include "mdso_errinfo_impl.h" - -static FILE * mdso_create_output( - const struct mdso_driver_ctx * dctx, - const char * name) -{ - struct mdso_driver_ctx_impl * ictx; - uintptr_t addr; - int fdout; - FILE * fout; - - addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx); - ictx = (struct mdso_driver_ctx_impl *)addr; - - if ((fdout = openat(ictx->fddst,name, - O_CREAT|O_TRUNC|O_WRONLY|O_NOCTTY|O_NOFOLLOW, - S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) { - MDSO_SYSTEM_ERROR(dctx); - return 0; - } - - if (!(fout = fdopen(fdout,"w"))) { - close(fdout); - MDSO_SYSTEM_ERROR(dctx); - return 0; - } - - return fout; -} - -FILE * mdso_create_asm_source( - const struct mdso_driver_ctx * dctx, - const char * asmname) -{ - if (!dctx->cctx->dstdir) - return stdout; - - return mdso_create_output(dctx,asmname); -} - -FILE * mdso_create_object( - const struct mdso_driver_ctx * dctx, - const char * objname) -{ - if (!dctx->cctx->dstdir) { - MDSO_CUSTOM_ERROR(dctx,MDSO_ERR_INVALID_DSTDIR); - return 0; - } - - return mdso_create_output(dctx,objname); -} diff --git a/src/helper/mdso_create_output.c b/src/helper/mdso_create_output.c new file mode 100644 index 0000000..b152697 --- /dev/null +++ b/src/helper/mdso_create_output.c @@ -0,0 +1,66 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include +#include "mdso_driver_impl.h" +#include "mdso_errinfo_impl.h" + +static FILE * mdso_create_output( + const struct mdso_driver_ctx * dctx, + const char * name) +{ + struct mdso_driver_ctx_impl * ictx; + uintptr_t addr; + int fdout; + FILE * fout; + + addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx); + ictx = (struct mdso_driver_ctx_impl *)addr; + + if ((fdout = openat(ictx->fddst,name, + O_CREAT|O_TRUNC|O_WRONLY|O_NOCTTY|O_NOFOLLOW, + S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) { + MDSO_SYSTEM_ERROR(dctx); + return 0; + } + + if (!(fout = fdopen(fdout,"w"))) { + close(fdout); + MDSO_SYSTEM_ERROR(dctx); + return 0; + } + + return fout; +} + +FILE * mdso_create_asm_source( + const struct mdso_driver_ctx * dctx, + const char * asmname) +{ + if (!dctx->cctx->dstdir) + return stdout; + + return mdso_create_output(dctx,asmname); +} + +FILE * mdso_create_object( + const struct mdso_driver_ctx * dctx, + const char * objname) +{ + if (!dctx->cctx->dstdir) { + MDSO_CUSTOM_ERROR(dctx,MDSO_ERR_INVALID_DSTDIR); + return 0; + } + + return mdso_create_output(dctx,objname); +} diff --git a/src/helper/mdso_map_input.c b/src/helper/mdso_map_input.c new file mode 100644 index 0000000..77401f3 --- /dev/null +++ b/src/helper/mdso_map_input.c @@ -0,0 +1,62 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include "mdso_errinfo_impl.h" + +int mdso_map_input( + const struct mdso_driver_ctx * dctx, + int fd, + const char * path, + int prot, + struct mdso_input * map) +{ + struct stat st; + bool fnew; + int ret; + + if ((fnew = (fd < 0))) + fd = open(path,O_RDONLY | O_CLOEXEC); + + if (fd < 0) + return MDSO_SYSTEM_ERROR(dctx); + + if ((ret = fstat(fd,&st) < 0) && fnew) + close(fd); + + else if ((st.st_size == 0) && fnew) + close(fd); + + if (ret < 0) + return MDSO_SYSTEM_ERROR(dctx); + + else if (st.st_size == 0) + return MDSO_CUSTOM_ERROR( + dctx,MDSO_ERR_SOURCE_SIZE_ZERO); + + map->size = st.st_size; + map->addr = mmap(0,map->size,prot,MAP_PRIVATE,fd,0); + + if (fnew) + close(fd); + + return (map->addr == MAP_FAILED) + ? MDSO_SYSTEM_ERROR(dctx) + : 0; +} + +int mdso_unmap_input(struct mdso_input * map) +{ + return munmap(map->addr,map->size); +} diff --git a/src/logic/mdso_create_implib_sources.c b/src/logic/mdso_create_implib_sources.c deleted file mode 100644 index 1031920..0000000 --- a/src/logic/mdso_create_implib_sources.c +++ /dev/null @@ -1,85 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ -/****************************************************************/ - -#include -#include -#include - -#include -#include "mdso_errinfo_impl.h" - -static void mdso_init_asmname(char * buf, const char * fmt, const char * str) -{ - char hexstr[24]; - long long unsigned int crc64; - - if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) { - crc64 = mdso_crc64_mbstr((const unsigned char *)str,0); - sprintf(hexstr,"%llx",crc64); - sprintf(buf,fmt,hexstr); - } else - sprintf(buf,fmt,str); -} - -mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) -{ - struct mdso_unit_ctx * uctx; - const char ** unit; - FILE * fout; - char asmname[PATH_MAX]; - const char * const * sym; - int ret; - - mdso_init_asmname(asmname,".dsometa_%s.s",dctx->cctx->libname); - - if (!(fout = mdso_create_asm_source(dctx,asmname))) - return MDSO_NESTED_ERROR(dctx); - - ret = mdso_asmgen_dsometa(dctx,fout); - - if (fout != stdout) - fclose(fout); - - if (ret < 0) - return MDSO_NESTED_ERROR(dctx); - - for (unit=dctx->units; *unit; unit++) { - if (mdso_get_unit_ctx(dctx,*unit,&uctx)) - return MDSO_NESTED_ERROR(dctx); - - for (sym=uctx->syms; *sym; sym++) { - mdso_init_asmname(asmname,".%s_symentry.s",*sym); - - if (!(fout = mdso_create_asm_source(dctx,asmname))) - return MDSO_NESTED_ERROR(dctx); - - ret = mdso_asmgen_symentry(dctx,*sym,fout); - - if (fout != stdout) - fclose(fout); - - if (ret < 0) - return MDSO_NESTED_ERROR(dctx); - - mdso_init_asmname(asmname,".%s_symfn.s",*sym); - - if (!(fout = mdso_create_asm_source(dctx,asmname))) - return MDSO_NESTED_ERROR(dctx); - - ret = mdso_asmgen_symfn(dctx,*sym,fout); - - if (fout != stdout) - fclose(fout); - - if (ret < 0) - return MDSO_NESTED_ERROR(dctx); - } - - mdso_free_unit_ctx(uctx); - } - - return 0; -} diff --git a/src/logic/mdso_map_input.c b/src/logic/mdso_map_input.c deleted file mode 100644 index 77401f3..0000000 --- a/src/logic/mdso_map_input.c +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ -/****************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include "mdso_errinfo_impl.h" - -int mdso_map_input( - const struct mdso_driver_ctx * dctx, - int fd, - const char * path, - int prot, - struct mdso_input * map) -{ - struct stat st; - bool fnew; - int ret; - - if ((fnew = (fd < 0))) - fd = open(path,O_RDONLY | O_CLOEXEC); - - if (fd < 0) - return MDSO_SYSTEM_ERROR(dctx); - - if ((ret = fstat(fd,&st) < 0) && fnew) - close(fd); - - else if ((st.st_size == 0) && fnew) - close(fd); - - if (ret < 0) - return MDSO_SYSTEM_ERROR(dctx); - - else if (st.st_size == 0) - return MDSO_CUSTOM_ERROR( - dctx,MDSO_ERR_SOURCE_SIZE_ZERO); - - map->size = st.st_size; - map->addr = mmap(0,map->size,prot,MAP_PRIVATE,fd,0); - - if (fnew) - close(fd); - - return (map->addr == MAP_FAILED) - ? MDSO_SYSTEM_ERROR(dctx) - : 0; -} - -int mdso_unmap_input(struct mdso_input * map) -{ - return munmap(map->addr,map->size); -} diff --git a/src/object/mdso_create_implib_objects.c b/src/object/mdso_create_implib_objects.c deleted file mode 100644 index dd681e0..0000000 --- a/src/object/mdso_create_implib_objects.c +++ /dev/null @@ -1,79 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ -/****************************************************************/ - -#include -#include -#include - -#include -#include "mdso_errinfo_impl.h" - -static void mdso_init_objname(char * buf, const char * fmt, const char * str) -{ - char hexstr[24]; - long long unsigned int crc64; - - if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) { - crc64 = mdso_crc64_mbstr((const unsigned char *)str,0); - sprintf(hexstr,"%llx",crc64); - sprintf(buf,fmt,hexstr); - } else - sprintf(buf,fmt,str); -} - -mdso_api int mdso_create_implib_objects(const struct mdso_driver_ctx * dctx) -{ - struct mdso_unit_ctx * uctx; - const char ** unit; - FILE * fout; - char objname[PATH_MAX]; - const char * const * sym; - int ret; - - mdso_init_objname(objname,".dsometa_%s.o",dctx->cctx->libname); - - if (!(fout = mdso_create_object(dctx,objname))) - return MDSO_NESTED_ERROR(dctx); - - ret = mdso_objgen_dsometa(dctx,fout,0); - fclose(fout); - - if (ret < 0) - return MDSO_NESTED_ERROR(dctx); - - for (unit=dctx->units; *unit; unit++) { - if (mdso_get_unit_ctx(dctx,*unit,&uctx)) - return MDSO_NESTED_ERROR(dctx); - - for (sym=uctx->syms; *sym; sym++) { - mdso_init_objname(objname,".%s_symentry.o",*sym); - - if (!(fout = mdso_create_object(dctx,objname))) - return MDSO_NESTED_ERROR(dctx); - - ret = mdso_objgen_symentry(dctx,*sym,fout,0); - fclose(fout); - - if (ret < 0) - return MDSO_NESTED_ERROR(dctx); - - mdso_init_objname(objname,".%s_symfn.o",*sym); - - if (!(fout = mdso_create_object(dctx,objname))) - return MDSO_NESTED_ERROR(dctx); - - ret = mdso_objgen_symfn(dctx,*sym,fout,0); - fclose(fout); - - if (ret < 0) - return MDSO_NESTED_ERROR(dctx); - } - - mdso_free_unit_ctx(uctx); - } - - return 0; -} diff --git a/src/util/mdso_create_implib_objects.c b/src/util/mdso_create_implib_objects.c new file mode 100644 index 0000000..dd681e0 --- /dev/null +++ b/src/util/mdso_create_implib_objects.c @@ -0,0 +1,79 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include +#include + +#include +#include "mdso_errinfo_impl.h" + +static void mdso_init_objname(char * buf, const char * fmt, const char * str) +{ + char hexstr[24]; + long long unsigned int crc64; + + if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) { + crc64 = mdso_crc64_mbstr((const unsigned char *)str,0); + sprintf(hexstr,"%llx",crc64); + sprintf(buf,fmt,hexstr); + } else + sprintf(buf,fmt,str); +} + +mdso_api int mdso_create_implib_objects(const struct mdso_driver_ctx * dctx) +{ + struct mdso_unit_ctx * uctx; + const char ** unit; + FILE * fout; + char objname[PATH_MAX]; + const char * const * sym; + int ret; + + mdso_init_objname(objname,".dsometa_%s.o",dctx->cctx->libname); + + if (!(fout = mdso_create_object(dctx,objname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_objgen_dsometa(dctx,fout,0); + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + + for (unit=dctx->units; *unit; unit++) { + if (mdso_get_unit_ctx(dctx,*unit,&uctx)) + return MDSO_NESTED_ERROR(dctx); + + for (sym=uctx->syms; *sym; sym++) { + mdso_init_objname(objname,".%s_symentry.o",*sym); + + if (!(fout = mdso_create_object(dctx,objname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_objgen_symentry(dctx,*sym,fout,0); + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + + mdso_init_objname(objname,".%s_symfn.o",*sym); + + if (!(fout = mdso_create_object(dctx,objname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_objgen_symfn(dctx,*sym,fout,0); + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + } + + mdso_free_unit_ctx(uctx); + } + + return 0; +} diff --git a/src/util/mdso_create_implib_sources.c b/src/util/mdso_create_implib_sources.c new file mode 100644 index 0000000..1031920 --- /dev/null +++ b/src/util/mdso_create_implib_sources.c @@ -0,0 +1,85 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include +#include + +#include +#include "mdso_errinfo_impl.h" + +static void mdso_init_asmname(char * buf, const char * fmt, const char * str) +{ + char hexstr[24]; + long long unsigned int crc64; + + if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) { + crc64 = mdso_crc64_mbstr((const unsigned char *)str,0); + sprintf(hexstr,"%llx",crc64); + sprintf(buf,fmt,hexstr); + } else + sprintf(buf,fmt,str); +} + +mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) +{ + struct mdso_unit_ctx * uctx; + const char ** unit; + FILE * fout; + char asmname[PATH_MAX]; + const char * const * sym; + int ret; + + mdso_init_asmname(asmname,".dsometa_%s.s",dctx->cctx->libname); + + if (!(fout = mdso_create_asm_source(dctx,asmname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_asmgen_dsometa(dctx,fout); + + if (fout != stdout) + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + + for (unit=dctx->units; *unit; unit++) { + if (mdso_get_unit_ctx(dctx,*unit,&uctx)) + return MDSO_NESTED_ERROR(dctx); + + for (sym=uctx->syms; *sym; sym++) { + mdso_init_asmname(asmname,".%s_symentry.s",*sym); + + if (!(fout = mdso_create_asm_source(dctx,asmname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_asmgen_symentry(dctx,*sym,fout); + + if (fout != stdout) + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + + mdso_init_asmname(asmname,".%s_symfn.s",*sym); + + if (!(fout = mdso_create_asm_source(dctx,asmname))) + return MDSO_NESTED_ERROR(dctx); + + ret = mdso_asmgen_symfn(dctx,*sym,fout); + + if (fout != stdout) + fclose(fout); + + if (ret < 0) + return MDSO_NESTED_ERROR(dctx); + } + + mdso_free_unit_ctx(uctx); + } + + return 0; +} -- cgit v1.2.3