From 3b42f99f60194a4afea5bf04b9f1439ffde4d666 Mon Sep 17 00:00:00 2001 From: midipix Date: Nov 11 2016 05:22:30 +0000 Subject: mdso_create_output(): initial implementation. --- diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h index 7f68021..f809813 100644 --- a/include/mdso/mdso.h +++ b/include/mdso/mdso.h @@ -89,6 +89,7 @@ mdso_api int mdso_output_export_symbols(const struct mdso_unit_ctx *, const str /* 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); #ifdef __cplusplus } diff --git a/project/common.mk b/project/common.mk index 12c02e4..2d7fad1 100644 --- a/project/common.mk +++ b/project/common.mk @@ -4,6 +4,7 @@ COMMON_SRCS = \ src/driver/mdso_driver_ctx.c \ src/driver/mdso_unit_ctx.c \ src/logic/mdso_map_input.c \ + src/output/mdso_create_output.c \ src/output/mdso_output_export_symbols.c \ src/skin/mdso_skin_default.c \ diff --git a/src/output/mdso_create_output.c b/src/output/mdso_create_output.c new file mode 100644 index 0000000..3ecde61 --- /dev/null +++ b/src/output/mdso_create_output.c @@ -0,0 +1,37 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include +#include "mdso_driver_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; + + 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) + return 0; + + return fdopen(fdout,"w"); +}