From: Arran Cudbard-Bell Date: Wed, 10 Nov 2021 17:41:26 +0000 (-0600) Subject: Pass the private version of dl_inst down in the mctx X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d335da8c01c92c3360ae4cb5001933193923104a;p=thirdparty%2Ffreeradius-server.git Pass the private version of dl_inst down in the mctx --- diff --git a/src/lib/server/dl_module.c b/src/lib/server/dl_module.c index 517d348226..7a86cae8f4 100644 --- a/src/lib/server/dl_module.c +++ b/src/lib/server/dl_module.c @@ -24,8 +24,6 @@ * @copyright 2016-2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org) */ RCSID("$Id$") - -#include #include #include @@ -35,6 +33,9 @@ RCSID("$Id$") #include #include +#define _DL_MODULE_PRIVATE 1 +#include + #define DL_INIT_CHECK fr_assert(dl_module_loader) /** Wrapper struct around dl_loader_t @@ -276,7 +277,7 @@ static void dl_module_instance_data_alloc(dl_module_inst_t *dl_inst, dl_module_t * succeed, and will create a talloc chunk header. * * This is needed so we can resolve instance data back to - * dl_module_instance_t/dl_module_t/dl_t. + * dl_module_inst_t/dl_module_t/dl_t. */ MEM(data = talloc_zero_array(dl_inst, uint8_t, module->common->inst_size)); diff --git a/src/lib/server/dl_module.h b/src/lib/server/dl_module.h index dc33e0e08a..bc98572c8b 100644 --- a/src/lib/server/dl_module.h +++ b/src/lib/server/dl_module.h @@ -40,6 +40,15 @@ RCSIDH(dl_module_h, "$Id$") extern "C" { #endif +#ifdef _CONST +# error _CONST can only be defined in the local header +#endif +#ifndef _DL_MODULE_PRIVATE +# define _CONST const +#else +# define _CONST +#endif + #ifdef __APPLE__ # define DL_EXTENSION ".dylib" #elif defined (WIN32) @@ -124,19 +133,19 @@ typedef struct { */ typedef struct dl_module_s dl_module_t; struct dl_module_s { - dl_t *dl; //!< Dynamic loader handle. + dl_t * _CONST dl; //!< Dynamic loader handle. - dl_module_t const *parent; //!< of this module. + dl_module_t const * _CONST parent; //!< of this module. - dl_module_type_t type; //!< of this module. + dl_module_type_t _CONST type; //!< of this module. - dl_module_common_t const *common; //!< Symbol exported by the module, containing its public - //!< functions, name and behaviour control flags. + dl_module_common_t const * _CONST common; //!< Symbol exported by the module, containing its public + //!< functions, name and behaviour control flags. - CONF_SECTION *conf; //!< The module's global configuration - ///< (as opposed to the instance, configuration). - ///< May be NULL. - bool in_tree; + CONF_SECTION * _CONST conf; //!< The module's global configuration + ///< (as opposed to the instance, configuration). + ///< May be NULL. + bool _CONST in_tree; }; /** A module/inst tuple @@ -145,11 +154,11 @@ struct dl_module_s { */ typedef struct dl_module_instance_s dl_module_inst_t; struct dl_module_instance_s { - char const *name; //!< Instance name. - dl_module_t const *module; //!< Module - void *data; //!< Module instance's parsed configuration. - CONF_SECTION *conf; //!< Module's instance configuration. - dl_module_inst_t const *parent; //!< Parent module's instance (if any). + char const * _CONST name; //!< Instance name. + dl_module_t const * _CONST module; //!< Module + void * _CONST data; //!< Module instance's parsed configuration. + CONF_SECTION * _CONST conf; //!< Module's instance configuration. + dl_module_inst_t const * _CONST parent; //!< Parent module's instance (if any). }; extern fr_table_num_sorted_t const dl_module_type_prefix[]; @@ -176,6 +185,8 @@ dl_loader_t *dl_loader_from_module_loader(dl_module_loader_t *dl_module_loader) dl_module_loader_t *dl_module_loader_init(char const *lib_dir); +#undef _CONST + #ifdef __cplusplus } #endif diff --git a/src/lib/server/module.h b/src/lib/server/module.h index dacc599087..f66b962f23 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -265,6 +265,7 @@ typedef struct { * */ struct module_ctx_s { + dl_module_inst_t *dl_inst; //!< dl API handle for the module. void *instance; //!< Global instance data for the module. void *thread; //!< Thread specific instance data. void *rctx; //!< Resume ctx that a module previously set. diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index f133d62861..0b6ce0efbc 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -45,7 +45,8 @@ typedef struct { unlang_module_fd_event_t fd_read; //!< Function to call when FD is readable. unlang_module_fd_event_t fd_write; //!< Function to call when FD is writable. unlang_module_fd_event_t fd_error; //!< Function to call when FD has errored. - void const *inst; //!< Module instance to pass to callbacks. + dl_module_inst_t *dl_inst; //!< Module instance to pass to callbacks. + ///< Use dl_inst->data to get instance data. void *thread; //!< Thread specific module instance. void const *ctx; //!< ctx data to pass to callbacks. fr_event_timer_t const *ev; //!< Event in this worker's event heap. @@ -63,18 +64,14 @@ static unlang_action_t unlang_module_resume(rlm_rcode_t *p_result, request_t *re static void unlang_event_fd_read_handler(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx) { unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t); - void *mutable_ctx; - void *mutable_inst; fr_assert(ev->fd == fd); - memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx)); - memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst)); - ev->fd_read(&(module_ctx_t){ - .instance = mutable_inst, + .dl_inst = ev->dl_inst, + .instance = ev->dl_inst->data, .thread = ev->thread, - .rctx = mutable_ctx }, + .rctx = UNCONST(void *, ev->ctx) }, ev->request, fd); } @@ -111,16 +108,12 @@ static int _unlang_event_free(unlang_module_event_t *ev) static void unlang_module_event_timeout_handler(UNUSED fr_event_list_t *el, fr_time_t now, void *ctx) { unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t); - void *mutable_ctx; - void *mutable_inst; - - memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx)); - memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst)); ev->timeout(&(module_ctx_t){ - .instance = mutable_inst, + .dl_inst = ev->dl_inst, + .instance = ev->dl_inst->data, .thread = ev->thread, - .rctx = mutable_ctx + .rctx = UNCONST(void *, ev->ctx) }, ev->request, now); talloc_free(ev); } @@ -161,7 +154,7 @@ int unlang_module_timeout_add(request_t *request, unlang_module_timeout_t callba .request = request, .fd = -1, .timeout = callback, - .inst = mc->instance->dl_inst->data, + .dl_inst = mc->instance->dl_inst, .thread = state->thread, .ctx = ctx }; @@ -209,18 +202,13 @@ int unlang_module_timeout_delete(request_t *request, void const *ctx) static void unlang_event_fd_write_handler(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx) { unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t); - void *mutable_ctx; - void *mutable_inst; - fr_assert(ev->fd == fd); - memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx)); - memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst)); - ev->fd_write(&(module_ctx_t){ - .instance = mutable_inst, + .dl_inst = ev->dl_inst, + .instance = ev->dl_inst->data, .thread = ev->thread, - .rctx = mutable_ctx }, + .rctx = UNCONST(void *, ev->ctx) }, ev->request, fd); } @@ -236,18 +224,14 @@ static void unlang_event_fd_error_handler(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, UNUSED int fd_errno, void *ctx) { unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t); - void *mutable_ctx; - void *mutable_inst; fr_assert(ev->fd == fd); - memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx)); - memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst)); - ev->fd_error(&(module_ctx_t){ - .instance = mutable_inst, + .dl_inst = ev->dl_inst, + .instance = ev->dl_inst->data, .thread = ev->thread, - .rctx = mutable_ctx + .rctx = UNCONST(void *, ev->ctx) }, ev->request, fd); } @@ -302,7 +286,7 @@ int unlang_module_fd_add(request_t *request, ev->fd_read = read; ev->fd_write = write; ev->fd_error = error; - ev->inst = mc->instance->dl_inst->data; + ev->dl_inst = mc->instance->dl_inst; ev->thread = state->thread; ev->ctx = ctx; @@ -665,6 +649,7 @@ static void unlang_module_signal(request_t *request, unlang_stack_frame_t *frame request->module = mc->instance->name; safe_lock(mc->instance); state->signal(&(module_ctx_t){ + .dl_inst = mc->instance->dl_inst, .instance = mc->instance->dl_inst->data, .thread = state->thread->data, .rctx = state->rctx @@ -763,6 +748,7 @@ static unlang_action_t unlang_module_resume(rlm_rcode_t *p_result, request_t *re safe_lock(mc->instance); ua = resume(&state->rcode, &(module_ctx_t){ + .dl_inst = mc->instance->dl_inst, .instance = mc->instance->dl_inst->data, .thread = state->thread->data, .rctx = state->rctx, @@ -972,6 +958,7 @@ static unlang_action_t unlang_module(rlm_rcode_t *p_result, request_t *request, safe_lock(mc->instance); /* Noop unless instance->mutex set */ ua = mc->method(&state->rcode, &(module_ctx_t){ + .dl_inst = mc->instance->dl_inst, .instance = mc->instance->dl_inst->data, .thread = state->thread->data },