Skip to content

Commit

Permalink
Add J9HookInterface.J9HookUnreserve() to clear flag J9HOOK_FLAG_RESERVED
Browse files Browse the repository at this point in the history
J9HookRegister() sets flags J9HOOK_FLAG_HOOKED | J9HOOK_FLAG_RESERVED,
J9HookUnregister() only clears J9HOOK_FLAG_HOOKED, add J9HookUnreserve()
to clear J9HOOK_FLAG_RESERVED.
This supports an event to be registered, unregistered/unreserved, and
disabled. Otherwise, an unregistered event can't be disabled by
J9HookDisable() because of the presence of J9HOOK_FLAG_RESERVED.

Signed-off-by: Jason Feng <[email protected]>
  • Loading branch information
JasonFengJ9 committed Jul 23, 2024
1 parent 56cb81f commit 8159d04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions include_core/omrhookable.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct J9HookInterface {
void (*J9HookDispatch)(struct J9HookInterface **hookInterface, uintptr_t eventNum, void *eventData);
intptr_t (*J9HookDisable)(struct J9HookInterface **hookInterface, uintptr_t eventNum);
intptr_t (*J9HookReserve)(struct J9HookInterface **hookInterface, uintptr_t eventNum);
void (*J9HookUnreserve)(struct J9HookInterface **hookInterface, uintptr_t eventNum);
intptr_t (*J9HookRegister)(struct J9HookInterface **hookInterface, uintptr_t eventNum, J9HookFunction function, void *userData, ...);
intptr_t (*J9HookRegisterWithCallSite)(struct J9HookInterface **hookInterface, uintptr_t eventNum, J9HookFunction function, const char *callsite, void *userData, ...);
void (*J9HookUnregister)(struct J9HookInterface **hookInterface, uintptr_t eventNum, J9HookFunction function, void *userData);
Expand Down
22 changes: 22 additions & 0 deletions util/hookable/hookable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ static intptr_t J9HookDisable(struct J9HookInterface **hookInterface, uintptr_t
static intptr_t J9HookIsEnabled(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum);
static void J9HookDispatch(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum, void *eventData);
static intptr_t J9HookReserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum);
static void J9HookUnreserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum);
static uintptr_t J9HookAllocateAgentID(struct J9HookInterface **hookInterface);
static void J9HookDeallocateAgentID(struct J9HookInterface **hookInterface, uintptr_t agentID);

static const J9HookInterface hookFunctionTable = {
J9HookDispatch,
J9HookDisable,
J9HookReserve,
J9HookUnreserve,
J9HookRegister,
J9HookRegisterWithCallSite,
J9HookUnregister,
Expand Down Expand Up @@ -345,6 +347,26 @@ J9HookReserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum)
return rc;
}

/*
* Clear the J9HOOK_FLAG_RESERVED flag from an event.
* This flag can be removed regardless of current flag(s) of the event,
* J9HOOK_FLAG_RESERVED, J9HOOK_FLAG_HOOKED or J9HOOK_FLAG_DISABLED.
*
* This function should not be called directly. It should be called through the hook interface.
*/
static void
J9HookUnreserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum)
{
J9CommonHookInterface *commonInterface = (J9CommonHookInterface *)hookInterface;
uintptr_t eventNum = taggedEventNum & J9HOOK_EVENT_NUM_MASK;

omrthread_monitor_enter(commonInterface->lock);

HOOK_FLAGS(commonInterface, eventNum) &= ~J9HOOK_FLAG_RESERVED;

omrthread_monitor_exit(commonInterface->lock);
}

static intptr_t
J9HookRegisterWithCallSitePrivate(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum, J9HookFunction function, const char *callsite, void *userData, uintptr_t agentID)
{
Expand Down

0 comments on commit 8159d04

Please sign in to comment.