From 76f8c51055cb1b69d087b113453764227160bc05 Mon Sep 17 00:00:00 2001 From: midipix Date: May 23 2020 05:59:02 +0000 Subject: driver: write & copy modes: pre-allocate a robust-file-copy memory region. --- diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c index c27ce90..926eb07 100644 --- a/src/driver/tpax_driver_ctx.c +++ b/src/driver/tpax_driver_ctx.c @@ -4,12 +4,15 @@ /* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ /******************************************************/ +#define _DEFAULT_SOURCE 1 + #include #include #include #include #include #include +#include #define ARGV_DRIVER @@ -279,6 +282,16 @@ static struct tpax_driver_ctx_impl * tpax_driver_ctx_alloc( if (!entry->fopt) *units++ = entry->arg; + if (cctx->drvflags & TPAX_DRIVER_EXEC_MODE_WRITE_COPY) { + ictx->ctx.bufsize = 64 * 1024; + ictx->ctx.bufaddr = mmap(0,ictx->ctx.bufsize,PROT_READ|PROT_WRITE,MAP_ANONYMOUS,-1,0); + } + + if (ictx->ctx.bufaddr == MAP_FAILED) { + ictx->ctx.bufaddr = 0; + ictx->ctx.bufsize = 0; + } + ictx->ctx.ctx.units = ictx->units; ictx->ctx.ctx.errv = ictx->ctx.errinfp; return &ictx->ctx; @@ -539,6 +552,9 @@ int tpax_get_driver_ctx( static void tpax_free_driver_ctx_impl(struct tpax_driver_ctx_alloc * ictx) { + if (ictx->ctx.bufaddr) + munmap(ictx->ctx.bufaddr,ictx->ctx.bufsize); + argv_free(ictx->meta); free(ictx); } diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h index c99553a..56c40b2 100644 --- a/src/internal/tpax_driver_impl.h +++ b/src/internal/tpax_driver_impl.h @@ -50,6 +50,8 @@ struct tpax_driver_ctx_impl { struct tpax_error_info ** erricap; struct tpax_error_info * erriptr[64]; struct tpax_error_info erribuf[64]; + void * bufaddr; + size_t bufsize; }; struct tpax_unit_ctx_impl {