Mallctl: Add experimental.hooks.[install|remove].
This commit is contained in:
committed by
David Goldblatt
parent
126e9a84a5
commit
bb071db92e
59
src/ctl.c
59
src/ctl.c
@@ -202,6 +202,8 @@ CTL_PROTO(stats_metadata_thp)
|
||||
CTL_PROTO(stats_resident)
|
||||
CTL_PROTO(stats_mapped)
|
||||
CTL_PROTO(stats_retained)
|
||||
CTL_PROTO(experimental_hooks_install)
|
||||
CTL_PROTO(experimental_hooks_remove)
|
||||
|
||||
#define MUTEX_STATS_CTL_PROTO_GEN(n) \
|
||||
CTL_PROTO(stats_##n##_num_ops) \
|
||||
@@ -536,6 +538,15 @@ static const ctl_named_node_t stats_node[] = {
|
||||
{NAME("arenas"), CHILD(indexed, stats_arenas)}
|
||||
};
|
||||
|
||||
static const ctl_named_node_t hooks_node[] = {
|
||||
{NAME("install"), CTL(experimental_hooks_install)},
|
||||
{NAME("remove"), CTL(experimental_hooks_remove)},
|
||||
};
|
||||
|
||||
static const ctl_named_node_t experimental_node[] = {
|
||||
{NAME("hooks"), CHILD(named, hooks)}
|
||||
};
|
||||
|
||||
static const ctl_named_node_t root_node[] = {
|
||||
{NAME("version"), CTL(version)},
|
||||
{NAME("epoch"), CTL(epoch)},
|
||||
@@ -548,7 +559,8 @@ static const ctl_named_node_t root_node[] = {
|
||||
{NAME("arena"), CHILD(indexed, arena)},
|
||||
{NAME("arenas"), CHILD(named, arenas)},
|
||||
{NAME("prof"), CHILD(named, prof)},
|
||||
{NAME("stats"), CHILD(named, stats)}
|
||||
{NAME("stats"), CHILD(named, stats)},
|
||||
{NAME("experimental"), CHILD(named, experimental)}
|
||||
};
|
||||
static const ctl_named_node_t super_root_node[] = {
|
||||
{NAME(""), CHILD(named, root)}
|
||||
@@ -2879,3 +2891,48 @@ label_return:
|
||||
malloc_mutex_unlock(tsdn, &ctl_mtx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
experimental_hooks_install_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
|
||||
void *oldp, size_t *oldlenp, void *newp, size_t newlen) {
|
||||
int ret;
|
||||
if (oldp == NULL || oldlenp == NULL|| newp == NULL) {
|
||||
ret = EINVAL;
|
||||
goto label_return;
|
||||
}
|
||||
/*
|
||||
* Note: this is a *private* struct. This is an experimental interface;
|
||||
* forcing the user to know the jemalloc internals well enough to
|
||||
* extract the ABI hopefully ensures nobody gets too comfortable with
|
||||
* this API, which can change at a moment's notice.
|
||||
*/
|
||||
hooks_t hooks;
|
||||
WRITE(hooks, hooks_t);
|
||||
void *handle = hook_install(tsd_tsdn(tsd), &hooks);
|
||||
if (handle == NULL) {
|
||||
ret = EAGAIN;
|
||||
goto label_return;
|
||||
}
|
||||
READ(handle, void *);
|
||||
|
||||
ret = 0;
|
||||
label_return:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
experimental_hooks_remove_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
|
||||
void *oldp, size_t *oldlenp, void *newp, size_t newlen) {
|
||||
int ret;
|
||||
WRITEONLY();
|
||||
void *handle = NULL;
|
||||
WRITE(handle, void *);
|
||||
if (handle == NULL) {
|
||||
ret = EINVAL;
|
||||
goto label_return;
|
||||
}
|
||||
hook_remove(tsd_tsdn(tsd), handle);
|
||||
ret = 0;
|
||||
label_return:
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user