From bc854efd7c20802a28499779dc35e3394ff9ac5e Mon Sep 17 00:00:00 2001 From: Jinoh Kang Date: Sat, 18 Mar 2023 17:02:22 +0900 Subject: [PATCH] ntdll: Open application manifest files with FILE_SHARE_DELETE. Today, RtlCreateActivationContext (CreateActCtxW) opens the source manifest file via NtOpenFile without the FILE_SHARE_DELETE sharing mode. This causes CreateActCtxW to fail if the source manifest file was created with the FILE_DELETE_ON_CLOSE flag. FILE_DELETE_ON_CLOSE is often used for temporary files that should be automatically deleted after use, even if the creator process crashes. Fix this by specifying FILE_SHARE_DELETE for sharing mode when opening the source manifest or module file. This allows the source manifest or module file to be marked as deleted while it is open. Note that concurrent deletion is not an issue for the following reasons: - The ability to read from an open file handle is unaffected by deletion of the corresponding file's name. - RtlCreateActivationContext does not open the source manifest or module file by the given filename (lpSource) more than once. --- dlls/kernel32/tests/actctx.c | 1 - dlls/ntdll/actctx.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dlls/kernel32/tests/actctx.c b/dlls/kernel32/tests/actctx.c index 9dbf77bc761..da351e70466 100644 --- a/dlls/kernel32/tests/actctx.c +++ b/dlls/kernel32/tests/actctx.c @@ -2917,7 +2917,6 @@ static void test_CreateActCtx_share_mode(void) actctx.lpSource = tmp_manifest_pathname; handle = CreateActCtxW(&actctx); - todo_wine ok(handle != INVALID_HANDLE_VALUE, "CreateActCtxW returned error %lu\n", GetLastError()); ok(handle != NULL, "CreateActCtxW returned %p\n", handle); diff --git a/dlls/ntdll/actctx.c b/dlls/ntdll/actctx.c index 721a2f339a5..b275a7f5b49 100644 --- a/dlls/ntdll/actctx.c +++ b/dlls/ntdll/actctx.c @@ -2925,7 +2925,8 @@ static NTSTATUS open_nt_file( HANDLE *handle, UNICODE_STRING *name ) attr.ObjectName = name; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; - return NtOpenFile( handle, GENERIC_READ | SYNCHRONIZE, &attr, &io, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_ALERT ); + return NtOpenFile( handle, GENERIC_READ | SYNCHRONIZE, &attr, &io, + FILE_SHARE_READ | FILE_SHARE_DELETE, FILE_SYNCHRONOUS_IO_ALERT ); } static NTSTATUS get_manifest_in_module( struct actctx_loader* acl, struct assembly_identity* ai,