diff options
author | midipix <writeonce@midipix.org> | 2015-12-17 04:11:07 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-11 00:22:28 -0500 |
commit | cde03b7121400bd61167e8db5303b3cd0ff03a0c (patch) | |
tree | 58a4ff993fefddf8d963f6a3dd5d1ae6760e2df9 /src/driver/mdso_unit_ctx.c | |
parent | 08279ea75fe76bdccb9809030ed3e5b261c9d557 (diff) | |
download | mdso-cde03b7121400bd61167e8db5303b3cd0ff03a0c.tar.bz2 mdso-cde03b7121400bd61167e8db5303b3cd0ff03a0c.tar.xz |
created skeleton.
Diffstat (limited to 'src/driver/mdso_unit_ctx.c')
-rw-r--r-- | src/driver/mdso_unit_ctx.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/driver/mdso_unit_ctx.c b/src/driver/mdso_unit_ctx.c new file mode 100644 index 0000000..870e060 --- /dev/null +++ b/src/driver/mdso_unit_ctx.c @@ -0,0 +1,62 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include <stdint.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> + +#include <mdso/mdso.h> +#include "mdso_driver_impl.h" + +static int mdso_free_unit_ctx_impl(struct mdso_unit_ctx_impl * ctx, int status) +{ + if (ctx) { + mdso_unmap_input(&ctx->map); + free(ctx); + } + + return status; +} + +int mdso_get_unit_ctx( + const struct mdso_driver_ctx * dctx, + const char * path, + struct mdso_unit_ctx ** pctx) +{ + struct mdso_unit_ctx_impl * ctx; + + if (!dctx || !(ctx = calloc(sizeof(*ctx),1))) + return -1; + + if (mdso_map_input(-1,path,PROT_READ,&ctx->map)) + return mdso_free_unit_ctx_impl(ctx,-1); + + memcpy(&ctx->cctx,dctx->cctx, + sizeof(ctx->cctx)); + + ctx->path = path; + + ctx->uctx.path = &ctx->path; + ctx->uctx.map = &ctx->map; + ctx->uctx.cctx = &ctx->cctx; + + *pctx = &ctx->uctx; + return 0; +} + +void mdso_free_unit_ctx(struct mdso_unit_ctx * ctx) +{ + struct mdso_unit_ctx_impl * ictx; + uintptr_t addr; + + if (ctx) { + addr = (uintptr_t)ctx - offsetof(struct mdso_unit_ctx_impl,uctx); + ictx = (struct mdso_unit_ctx_impl *)addr; + mdso_free_unit_ctx_impl(ictx,0); + } +} |