Module: wine Branch: master Commit: 4dadf7a0deffdacc82e056f93818b4bc31a17402 URL: https://gitlab.winehq.org/wine/wine/-/commit/4dadf7a0deffdacc82e056f93818b4b...
Author: Jinoh Kang jinoh.kang.kr@gmail.com Date: Sat Mar 18 18:48:14 2023 +0900
ntdll: Factor out reading current activation context into a helper function.
This refactoring makes it easier to change the algorithm of obtaining the current activation context stack.
Note that RtlAddRefActivationContext(NULL) is a no-op, and check_actctx(NULL) returns NULL without doing anything.
---
dlls/ntdll/actctx.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/dlls/ntdll/actctx.c b/dlls/ntdll/actctx.c index b275a7f5b49..ab4ef378330 100644 --- a/dlls/ntdll/actctx.c +++ b/dlls/ntdll/actctx.c @@ -3384,6 +3384,14 @@ static NTSTATUS parse_depend_manifests(struct actctx_loader* acl) return status; }
+static HANDLE get_current_actctx_no_addref(void) +{ + if (NtCurrentTeb()->ActivationContextStack.ActiveFrame) + return NtCurrentTeb()->ActivationContextStack.ActiveFrame->ActivationContext; + + return NULL; +} + /* find the appropriate activation context for RtlQueryInformationActivationContext */ static NTSTATUS find_query_actctx( HANDLE *handle, DWORD flags, ULONG class ) { @@ -3393,8 +3401,7 @@ static NTSTATUS find_query_actctx( HANDLE *handle, DWORD flags, ULONG class ) { if (*handle) return STATUS_INVALID_PARAMETER;
- if (NtCurrentTeb()->ActivationContextStack.ActiveFrame) - *handle = NtCurrentTeb()->ActivationContextStack.ActiveFrame->ActivationContext; + *handle = get_current_actctx_no_addref(); } else if (flags & (QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS|QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE)) { @@ -5462,14 +5469,7 @@ void WINAPI RtlFreeThreadActivationContextStack(void) */ NTSTATUS WINAPI RtlGetActiveActivationContext( HANDLE *handle ) { - if (NtCurrentTeb()->ActivationContextStack.ActiveFrame) - { - *handle = NtCurrentTeb()->ActivationContextStack.ActiveFrame->ActivationContext; - RtlAddRefActivationContext( *handle ); - } - else - *handle = 0; - + RtlAddRefActivationContext( *handle = get_current_actctx_no_addref() ); return STATUS_SUCCESS; }
@@ -5754,6 +5754,7 @@ NTSTATUS WINAPI RtlFindActivationContextSectionString( ULONG flags, const GUID * { PACTCTX_SECTION_KEYED_DATA data = ptr; NTSTATUS status = STATUS_SXS_KEY_NOT_FOUND; + ACTIVATION_CONTEXT *actctx;
TRACE("%08lx %s %lu %s %p\n", flags, debugstr_guid(guid), section_kind, debugstr_us(section_name), data); @@ -5775,11 +5776,8 @@ NTSTATUS WINAPI RtlFindActivationContextSectionString( ULONG flags, const GUID * return STATUS_INVALID_PARAMETER; }
- if (NtCurrentTeb()->ActivationContextStack.ActiveFrame) - { - ACTIVATION_CONTEXT *actctx = check_actctx(NtCurrentTeb()->ActivationContextStack.ActiveFrame->ActivationContext); - if (actctx) status = find_string( actctx, section_kind, section_name, flags, data ); - } + actctx = check_actctx( get_current_actctx_no_addref() ); + if (actctx) status = find_string( actctx, section_kind, section_name, flags, data );
if (status != STATUS_SUCCESS) status = find_string( process_actctx, section_kind, section_name, flags, data ); @@ -5798,6 +5796,7 @@ NTSTATUS WINAPI RtlFindActivationContextSectionGuid( ULONG flags, const GUID *ex { ACTCTX_SECTION_KEYED_DATA *data = ptr; NTSTATUS status = STATUS_SXS_KEY_NOT_FOUND; + ACTIVATION_CONTEXT *actctx;
TRACE("%08lx %s %lu %s %p\n", flags, debugstr_guid(extguid), section_kind, debugstr_guid(guid), data);
@@ -5816,11 +5815,8 @@ NTSTATUS WINAPI RtlFindActivationContextSectionGuid( ULONG flags, const GUID *ex if (!data || data->cbSize < FIELD_OFFSET(ACTCTX_SECTION_KEYED_DATA, ulAssemblyRosterIndex) || !guid) return STATUS_INVALID_PARAMETER;
- if (NtCurrentTeb()->ActivationContextStack.ActiveFrame) - { - ACTIVATION_CONTEXT *actctx = check_actctx(NtCurrentTeb()->ActivationContextStack.ActiveFrame->ActivationContext); - if (actctx) status = find_guid( actctx, section_kind, guid, flags, data ); - } + actctx = check_actctx( get_current_actctx_no_addref() ); + if (actctx) status = find_guid( actctx, section_kind, guid, flags, data );
if (status != STATUS_SUCCESS) status = find_guid( process_actctx, section_kind, guid, flags, data );