summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-04 22:56:15 -0500
committermidipix <writeonce@midipix.org>2016-11-10 23:35:30 -0500
commitd7ed3e2faf8e3bc1aeb1e7fed27cd8a1ff4b2290 (patch)
tree0fa55ad7eccd35b3f7cbb3194045d5bcc9f83032 /src/driver
parentc61328dfece5c7346aabd4bc0027a9eb8126dd08 (diff)
downloadperk-d7ed3e2faf8e3bc1aeb1e7fed27cd8a1ff4b2290.tar.bz2
perk-d7ed3e2faf8e3bc1aeb1e7fed27cd8a1ff4b2290.tar.xz
API redesign 5/10: pe_unit_ctx: protect members against direct modification.
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/pe_unit_ctx.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/driver/pe_unit_ctx.c b/src/driver/pe_unit_ctx.c
index b86719c..df5409b 100644
--- a/src/driver/pe_unit_ctx.c
+++ b/src/driver/pe_unit_ctx.c
@@ -1,10 +1,13 @@
#include <stdint.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
+
#include <perk/perk.h>
+#include "perk_impl.h"
-static int pe_free_unit_ctx_impl(struct pe_unit_ctx * ctx, int status)
+static int pe_free_unit_ctx_impl(struct pe_unit_ctx_impl * ctx, int status)
{
if (ctx) {
pe_free_image_meta(ctx->meta);
@@ -20,7 +23,7 @@ int pe_get_unit_ctx(
const char * path,
struct pe_unit_ctx ** pctx)
{
- struct pe_unit_ctx * ctx;
+ struct pe_unit_ctx_impl * ctx;
int prot;
if (!dctx || !(ctx = calloc(sizeof(*ctx),1)))
@@ -39,14 +42,26 @@ int pe_get_unit_ctx(
memcpy(&ctx->cctx,dctx->cctx,
sizeof(ctx->cctx));
- ctx->path = path;
+ ctx->path = ctx->path;
ctx->cctx.prot = prot;
- *pctx = ctx;
+ ctx->uctx.path = &ctx->path;
+ ctx->uctx.map = &ctx->map;
+ ctx->uctx.meta = ctx->meta;
+ ctx->uctx.cctx = &ctx->cctx;
+
+ *pctx = &ctx->uctx;
return 0;
}
void pe_free_unit_ctx(struct pe_unit_ctx * ctx)
{
- pe_free_unit_ctx_impl(ctx,0);
+ struct pe_unit_ctx_impl * ictx;
+ uintptr_t addr;
+
+ if (ctx) {
+ addr = (uintptr_t)ctx - offsetof(struct pe_unit_ctx_impl,uctx);
+ ictx = (struct pe_unit_ctx_impl *)addr;
+ pe_free_unit_ctx_impl(ictx,0);
+ }
}