For React Native.
-- v2: ntdll: Implement RtlQueryInformationActiveActivationContext().
From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/ntdll/actctx.c | 10 +++++++ dlls/ntdll/ntdll.spec | 2 +- dlls/ntdll/tests/Makefile.in | 1 + dlls/ntdll/tests/resource.rc | 24 +++++++++++++++++ dlls/ntdll/tests/rtl.c | 42 +++++++++++++++++++++++++++++ dlls/ntdll/tests/wine_test.manifest | 4 +++ include/winternl.h | 1 + 7 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 dlls/ntdll/tests/resource.rc create mode 100644 dlls/ntdll/tests/wine_test.manifest
diff --git a/dlls/ntdll/actctx.c b/dlls/ntdll/actctx.c index 206dd8a1819..9828d90d11d 100644 --- a/dlls/ntdll/actctx.c +++ b/dlls/ntdll/actctx.c @@ -5799,6 +5799,16 @@ NTSTATUS WINAPI RtlQueryInformationActivationContext( ULONG flags, HANDLE handle return STATUS_SUCCESS; }
+/****************************************************************** + * RtlQueryInformationActiveActivationContext (NTDLL.@) + */ +NTSTATUS WINAPI RtlQueryInformationActiveActivationContext( ULONG class, PVOID buffer, + SIZE_T buffer_size, SIZE_T *return_length ) +{ + return RtlQueryInformationActivationContext( QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX, NULL, NULL, + class, buffer, buffer_size, return_length ); +} + /*********************************************************************** * RtlFindActivationContextSectionString (NTDLL.@) * diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 2b3450f9899..4e36bfe2662 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -943,7 +943,7 @@ @ stdcall RtlQueryHeapInformation(long long ptr long ptr) @ stdcall RtlQueryInformationAcl(ptr ptr long long) @ stdcall RtlQueryInformationActivationContext(long long ptr long ptr long ptr) -@ stub RtlQueryInformationActiveActivationContext +@ stdcall RtlQueryInformationActiveActivationContext(long ptr long ptr) @ stub RtlQueryInterfaceMemoryStream @ stdcall RtlQueryPackageIdentity(long ptr ptr ptr ptr ptr) @ stdcall RtlQueryPerformanceCounter(ptr) diff --git a/dlls/ntdll/tests/Makefile.in b/dlls/ntdll/tests/Makefile.in index 3742968c415..f8554e95ad3 100644 --- a/dlls/ntdll/tests/Makefile.in +++ b/dlls/ntdll/tests/Makefile.in @@ -17,6 +17,7 @@ SOURCES = \ pipe.c \ port.c \ reg.c \ + resource.rc \ rtl.c \ rtlbitmap.c \ rtlstr.c \ diff --git a/dlls/ntdll/tests/resource.rc b/dlls/ntdll/tests/resource.rc new file mode 100644 index 00000000000..80795fe03c9 --- /dev/null +++ b/dlls/ntdll/tests/resource.rc @@ -0,0 +1,24 @@ +/* + * Resources for ntdll test suite. + * + * Copyright 2025 Zhiyi Zhang for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "windef.h" + +/* @makedep: wine_test.manifest */ +124 24 wine_test.manifest diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c index f5db5cdc6e2..e1411ef968e 100644 --- a/dlls/ntdll/tests/rtl.c +++ b/dlls/ntdll/tests/rtl.c @@ -29,6 +29,7 @@ #define WIN32_NO_STATUS #include "windef.h" #include "winbase.h" +#include "winuser.h" #include "winreg.h" #include "winternl.h" #include "in6addr.h" @@ -121,6 +122,7 @@ static void (WINAPI *pRtlInitializeGenericTable)(RTL_GENERIC_TABLE *, PRTL_ static void * (WINAPI *pRtlFindExportedRoutineByName)(HMODULE,const char *); static void * (WINAPI *pRtlLookupElementGenericTable)(PRTL_GENERIC_TABLE, void *); static ULONG (WINAPI *pRtlNumberGenericTableElements)(PRTL_GENERIC_TABLE); +static NTSTATUS (WINAPI *pRtlQueryInformationActiveActivationContext)(ULONG,PVOID,SIZE_T,SIZE_T *); static NTSTATUS (WINAPI *pLdrEnumerateLoadedModules)(void *, void *, void *); static NTSTATUS (WINAPI *pLdrRegisterDllNotification)(ULONG, PLDR_DLL_NOTIFICATION_FUNCTION, void *, void **); static NTSTATUS (WINAPI *pLdrUnregisterDllNotification)(void *); @@ -193,6 +195,7 @@ static void InitFunctionPtrs(void) pRtlFindExportedRoutineByName = (void *)GetProcAddress(hntdll, "RtlFindExportedRoutineByName"); pRtlLookupElementGenericTable = (void *)GetProcAddress(hntdll, "RtlLookupElementGenericTable"); pRtlNumberGenericTableElements = (void *)GetProcAddress(hntdll, "RtlNumberGenericTableElements"); + pRtlQueryInformationActiveActivationContext = (void *)GetProcAddress(hntdll, "RtlQueryInformationActiveActivationContext"); pLdrEnumerateLoadedModules = (void *)GetProcAddress(hntdll, "LdrEnumerateLoadedModules"); pLdrRegisterDllNotification = (void *)GetProcAddress(hntdll, "LdrRegisterDllNotification"); pLdrUnregisterDllNotification = (void *)GetProcAddress(hntdll, "LdrUnregisterDllNotification"); @@ -220,6 +223,18 @@ static void InitFunctionPtrs(void) ok(strlen(src) == 15, "Source must be 16 bytes long!\n"); }
+static HANDLE create_actctx_from_module_manifest(void) +{ + ACTCTXW actctx; + + memset( &actctx, 0, sizeof(ACTCTXW) ); + actctx.cbSize = sizeof(actctx); + actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID; + actctx.lpResourceName = MAKEINTRESOURCEW( 124 ); + actctx.hModule = GetModuleHandleW( NULL ); + return CreateActCtxW( &actctx ); +} + static void test_RtlQueryProcessDebugInformation(void) { DEBUG_BUFFER *buffer; @@ -5476,6 +5491,32 @@ static void test_RtlDeriveCapabilitySidsFromName(void) free( group_sid ); }
+static void test_RtlQueryInformationActiveActivationContext(void) +{ + ACTIVATION_CONTEXT_BASIC_INFORMATION basic; + ULONG_PTR cookie; + NTSTATUS status; + HANDLE context; + SIZE_T size; + BOOL ret; + + context = create_actctx_from_module_manifest(); + ok( context != INVALID_HANDLE_VALUE, "Failed to create context, error %lu.\n", GetLastError() ); + ret = ActivateActCtx( context, &cookie ); + ok( ret, "ActivateActCtx failed, error %lu.\n", GetLastError() ); + + status = pRtlQueryInformationActiveActivationContext( ActivationContextBasicInformation, &basic, + sizeof(basic), &size ); + ok( status == STATUS_SUCCESS, "Got unexpected status %#lx.\n", status ); + ok( size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION), "Size mismatch.\n" ); + ok( basic.dwFlags == 0, "Got unexpected flags %#lx.\n", basic.dwFlags ); + ok( basic.hActCtx == context, "Got unexpected handle.\n" ); + + ret = DeactivateActCtx( 0, cookie ); + ok( ret, "DeactivateActCtx failed, error %lu.\n", GetLastError() ); + ReleaseActCtx( context ); +} + START_TEST(rtl) { InitFunctionPtrs(); @@ -5546,4 +5587,5 @@ START_TEST(rtl) test_RtlGetElementGenericTable(); test_RtlCreateServiceSid(); test_RtlDeriveCapabilitySidsFromName(); + test_RtlQueryInformationActiveActivationContext(); } diff --git a/dlls/ntdll/tests/wine_test.manifest b/dlls/ntdll/tests/wine_test.manifest new file mode 100644 index 00000000000..de77de3e201 --- /dev/null +++ b/dlls/ntdll/tests/wine_test.manifest @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> + <assemblyIdentity version="1.0.0.0" name="Wine.Test"/> +</assembly> diff --git a/include/winternl.h b/include/winternl.h index aa19907dc25..86f5f4e5480 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -4987,6 +4987,7 @@ NTSYSAPI NTSTATUS WINAPI RtlQueryEnvironmentVariable_U(PWSTR,PUNICODE_STRING,PU NTSYSAPI NTSTATUS WINAPI RtlQueryHeapInformation(HANDLE,HEAP_INFORMATION_CLASS,PVOID,SIZE_T,PSIZE_T); NTSYSAPI NTSTATUS WINAPI RtlQueryInformationAcl(PACL,LPVOID,DWORD,ACL_INFORMATION_CLASS); NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActivationContext(ULONG,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*); +NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActiveActivationContext(ULONG,PVOID,SIZE_T,SIZE_T *); NTSYSAPI NTSTATUS WINAPI RtlQueryPackageIdentity(HANDLE,WCHAR*,SIZE_T*,WCHAR*,SIZE_T*,BOOLEAN*); NTSYSAPI BOOL WINAPI RtlQueryPerformanceCounter(LARGE_INTEGER*); NTSYSAPI BOOL WINAPI RtlQueryPerformanceFrequency(LARGE_INTEGER*);
Nikolay Sivov (@nsivov) commented about dlls/ntdll/tests/rtl.c:
free( group_sid );
}
+static void test_RtlQueryInformationActiveActivationContext(void) +{
- ACTIVATION_CONTEXT_BASIC_INFORMATION basic;
- ULONG_PTR cookie;
- NTSTATUS status;
- HANDLE context;
- SIZE_T size;
- BOOL ret;
- context = create_actctx_from_module_manifest();
- ok( context != INVALID_HANDLE_VALUE, "Failed to create context, error %lu.\n", GetLastError() );
- ret = ActivateActCtx( context, &cookie );
- ok( ret, "ActivateActCtx failed, error %lu.\n", GetLastError() );
It's better to have this created dynamically from a file, we don't need a resource section just for that.
Another option is to have RtlQueryInformationActiveActivationContext test in kernel32/tests where we have all the helpers available.
Nikolay Sivov (@nsivov) commented about dlls/ntdll/tests/rtl.c:
- HANDLE context;
- SIZE_T size;
- BOOL ret;
- context = create_actctx_from_module_manifest();
- ok( context != INVALID_HANDLE_VALUE, "Failed to create context, error %lu.\n", GetLastError() );
- ret = ActivateActCtx( context, &cookie );
- ok( ret, "ActivateActCtx failed, error %lu.\n", GetLastError() );
- status = pRtlQueryInformationActiveActivationContext( ActivationContextBasicInformation, &basic,
sizeof(basic), &size );
- ok( status == STATUS_SUCCESS, "Got unexpected status %#lx.\n", status );
- ok( size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION), "Size mismatch.\n" );
- ok( basic.dwFlags == 0, "Got unexpected flags %#lx.\n", basic.dwFlags );
- ok( basic.hActCtx == context, "Got unexpected handle.\n" );
Now this is missing a Release call.
On Mon Jun 9 10:40:35 2025 +0000, Nikolay Sivov wrote:
Now this is missing a Release call.
What's missing? There is `ReleaseActCtx( context );` at line 5517.
On Mon Jun 9 10:40:35 2025 +0000, Nikolay Sivov wrote:
It's better to have this created dynamically from a file, we don't need a resource section just for that. Another option is to have RtlQueryInformationActiveActivationContext test in kernel32/tests where we have all the helpers available.
Okay. I will move it to kernel32/tests/actctx.c
On Mon Jun 9 10:46:02 2025 +0000, Zhiyi Zhang wrote:
What's missing? There is `ReleaseActCtx( context );` at line 5517.
That's for the one that you created. Another one is returned in basic.hActCtx.