From b183d1ada2b4db899179e1865d4248f8e950a1ca Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 24 Oct 2016 16:41:54 -0400 Subject: helper api: renamed mdso_create_output() --> mdso_create_asm_source(). --- include/mdso/mdso.h | 4 ++- project/common.mk | 2 +- project/tree.mk | 1 + src/helper/mdso_create_asm_source.c | 47 ++++++++++++++++++++++++++++++++++ src/logic/mdso_create_implib_sources.c | 6 ++--- src/output/mdso_create_output.c | 47 ---------------------------------- 6 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 src/helper/mdso_create_asm_source.c delete mode 100644 src/output/mdso_create_output.c diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h index eba41ad..9efda11 100644 --- a/include/mdso/mdso.h +++ b/include/mdso/mdso.h @@ -107,6 +107,9 @@ mdso_api void mdso_free_unit_ctx (struct mdso_unit_ctx *); mdso_api int mdso_map_input (const struct mdso_driver_ctx *, int fd, const char * path, int prot, struct mdso_input *); mdso_api int mdso_unmap_input (struct mdso_input *); +/* helper api */ +mdso_api FILE*mdso_create_asm_source (const struct mdso_driver_ctx *, const char * asmname); + /* utility api */ mdso_api int mdso_main (int, char **, char **); mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx *); @@ -117,7 +120,6 @@ mdso_api int mdso_output_error_vector (const struct mdso_driver_ctx *); /* low-level api */ mdso_api uint32_t mdso_crc32_mbstr (const unsigned char * str, size_t * symlen); mdso_api uint64_t mdso_crc64_mbstr (const unsigned char * str, size_t * symlen); -mdso_api FILE * mdso_create_output (const struct mdso_driver_ctx *, const char * asmname); mdso_api int mdso_generate_dsometa (const struct mdso_driver_ctx *, FILE * fout); mdso_api int mdso_generate_symentry(const struct mdso_driver_ctx *, const char * sym, FILE * fout); mdso_api int mdso_generate_symfn (const struct mdso_driver_ctx *, const char * sym, FILE * fout); diff --git a/project/common.mk b/project/common.mk index 260e1a6..f482923 100644 --- a/project/common.mk +++ b/project/common.mk @@ -4,13 +4,13 @@ COMMON_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/internal/mdso_errinfo_impl.c \ src/logic/mdso_create_implib_sources.c \ src/logic/mdso_generate_dsometa.c \ src/logic/mdso_generate_symentry.c \ src/logic/mdso_generate_symfn.c \ src/logic/mdso_map_input.c \ - src/output/mdso_create_output.c \ src/output/mdso_output_error.c \ src/output/mdso_output_export_symbols.c \ src/skin/mdso_skin_default.c \ diff --git a/project/tree.mk b/project/tree.mk index 4133dd5..94db455 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -2,6 +2,7 @@ tree.tag: mkdir -p src mkdir -p src/crc mkdir -p src/driver + mkdir -p src/helper mkdir -p src/internal mkdir -p src/logic mkdir -p src/output diff --git a/src/helper/mdso_create_asm_source.c b/src/helper/mdso_create_asm_source.c new file mode 100644 index 0000000..0d02c12 --- /dev/null +++ b/src/helper/mdso_create_asm_source.c @@ -0,0 +1,47 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2016 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" + +FILE * mdso_create_asm_source( + const struct mdso_driver_ctx * dctx, + const char * asmname) +{ + struct mdso_driver_ctx_impl * ictx; + uintptr_t addr; + int fdout; + FILE * fout; + + if (!dctx->cctx->dstdir) + return stdout; + + addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx); + ictx = (struct mdso_driver_ctx_impl *)addr; + + if ((fdout = openat(ictx->fddst,asmname, + 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; +} diff --git a/src/logic/mdso_create_implib_sources.c b/src/logic/mdso_create_implib_sources.c index fb12e97..4bc8796 100644 --- a/src/logic/mdso_create_implib_sources.c +++ b/src/logic/mdso_create_implib_sources.c @@ -35,7 +35,7 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) mdso_init_asmname(asmname,"__%s_dso_meta.s",dctx->cctx->libname); - if (!(fout = mdso_create_output(dctx,asmname))) + if (!(fout = mdso_create_asm_source(dctx,asmname))) return MDSO_NESTED_ERROR(dctx); ret = mdso_generate_dsometa(dctx,fout); @@ -53,7 +53,7 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) for (sym=uctx->syms; *sym; sym++) { mdso_init_asmname(asmname,"__%s_sym_entry.s",*sym); - if (!(fout = mdso_create_output(dctx,asmname))) + if (!(fout = mdso_create_asm_source(dctx,asmname))) return MDSO_NESTED_ERROR(dctx); ret = mdso_generate_symentry(dctx,*sym,fout); @@ -66,7 +66,7 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) mdso_init_asmname(asmname,"__%s_sym_fn.s",*sym); - if (!(fout = mdso_create_output(dctx,asmname))) + if (!(fout = mdso_create_asm_source(dctx,asmname))) return MDSO_NESTED_ERROR(dctx); ret = mdso_generate_symfn(dctx,*sym,fout); diff --git a/src/output/mdso_create_output.c b/src/output/mdso_create_output.c deleted file mode 100644 index 14321b7..0000000 --- a/src/output/mdso_create_output.c +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2016 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" - -FILE * mdso_create_output( - const struct mdso_driver_ctx * dctx, - const char * asmname) -{ - struct mdso_driver_ctx_impl * ictx; - uintptr_t addr; - int fdout; - FILE * fout; - - if (!dctx->cctx->dstdir) - return stdout; - - addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx); - ictx = (struct mdso_driver_ctx_impl *)addr; - - if ((fdout = openat(ictx->fddst,asmname, - 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; -} -- cgit v1.2.3