ntdll-NtQuerySection: For section queries return real file size.

This commit is contained in:
Sebastian Lackner 2016-03-11 02:42:52 +01:00
parent 66ba61188b
commit 5a9e5cae3c
3 changed files with 140 additions and 1 deletions

View File

@ -0,0 +1,59 @@
From e25dd58ca9b187745ddfb4b8eb10cbcef24992de Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Wed, 9 Mar 2016 13:06:13 +0800
Subject: server: CreateFileMapping should not fail without SEC_COMMIT for a
named file section.
Anonymous file mapping already behaves this way.
---
dlls/kernel32/tests/virtual.c | 5 ++---
server/mapping.c | 5 +++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 10e72b2..6d25b5f 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -3961,9 +3961,7 @@ todo_wine
SetLastError(0xdeadbef);
mapping = CreateFileMappingA(file, NULL, PAGE_READONLY|SEC_RESERVE, 0, 0, NULL);
-todo_wine
ok(mapping != 0, "CreateFileMapping error %u\n", GetLastError());
- if (!mapping) goto skip1;
memset(&info, 0x55, sizeof(info));
ret = 0xdeadbeef;
@@ -3971,11 +3969,12 @@ todo_wine
ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
+todo_wine
ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
+todo_wine
ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
CloseHandle(mapping);
-skip1:
CloseHandle(file);
SetLastError(0xdeadbef);
diff --git a/server/mapping.c b/server/mapping.c
index ec0ef98..aa38193 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -539,8 +539,9 @@ static struct object *create_mapping( struct object *root, const struct unicode_
if (!(protect & VPROT_COMMITTED))
{
- set_error( STATUS_INVALID_PARAMETER );
- goto error;
+ if (!(mapping->committed = mem_alloc( offsetof(struct ranges, ranges[8]) ))) goto error;
+ mapping->committed->count = 0;
+ mapping->committed->max = 8;
}
if (!(file = get_file_obj( current->process, handle, access ))) goto error;
fd = get_obj_fd( (struct object *)file );
--
2.7.1

View File

@ -0,0 +1,76 @@
From 83766ac8e17968e234462a35588bc0765a0f35aa Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Wed, 9 Mar 2016 13:51:59 +0800
Subject: ntdll: For section queries return real file size.
---
dlls/kernel32/tests/virtual.c | 4 ----
dlls/ntdll/virtual.c | 9 +++++++++
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 6d25b5f..485e2f3 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -3844,7 +3844,6 @@ static void test_NtQuerySection(void)
ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
todo_wine
ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
-todo_wine
ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
status = pNtQuerySection(mapping, SectionImageInformation, &info, sizeof(info.basic), &ret);
@@ -3868,7 +3867,6 @@ todo_wine
ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
todo_wine
ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
-todo_wine
ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
UnmapViewOfFile(p);
@@ -3954,7 +3952,6 @@ todo_wine
ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
todo_wine
ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
-todo_wine
ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
CloseHandle(mapping);
@@ -3971,7 +3968,6 @@ todo_wine
ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
todo_wine
ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
-todo_wine
ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
CloseHandle(mapping);
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 5a8d85c..f00aae9 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -2538,6 +2538,7 @@ NTSTATUS WINAPI SYSCALL(NtQuerySection)( HANDLE handle, SECTION_INFORMATION_CLAS
short machine, subsystem;
short major_subsystem, minor_subsystem;
short characteristics, dll_characteristics;
+ int unix_fd, needs_close;
NTSTATUS res;
if (info_class == SectionBasicInformation)
@@ -2579,6 +2580,14 @@ NTSTATUS WINAPI SYSCALL(NtQuerySection)( HANDLE handle, SECTION_INFORMATION_CLAS
SERVER_END_REQ;
if (res) return res;
+ if (!(protect & VPROT_IMAGE) && dup_mapping &&
+ !server_get_unix_fd( dup_mapping, 0, &unix_fd, &needs_close, NULL, NULL ))
+ {
+ struct stat st;
+ if (!fstat( unix_fd, &st )) size.QuadPart = st.st_size;
+ if (needs_close) close( unix_fd );
+ }
+
if (dup_mapping) close_handle( dup_mapping );
if (shared_file) close_handle( shared_file );
--
2.7.1

View File

@ -51,7 +51,7 @@ usage()
# Get the upstream commit sha
upstream_commit()
{
echo "887b445bb87861f2c11e6c5248d105c1fc52f125"
echo "9da6dd2ac93c97bc6f8cd60f26f20f632b8d8ce0"
}
# Show version information
@ -4949,9 +4949,13 @@ fi
if test "$enable_ntdll_NtQuerySection" -eq 1; then
patch_apply ntdll-NtQuerySection/0001-ntdll-Implement-NtQuerySection.patch
patch_apply ntdll-NtQuerySection/0002-kernel32-tests-Add-tests-for-NtQuerySection.patch
patch_apply ntdll-NtQuerySection/0003-server-CreateFileMapping-should-not-fail-without-SEC.patch
patch_apply ntdll-NtQuerySection/0004-ntdll-For-section-queries-return-real-file-size.patch
(
echo '+ { "Dmitry Timoshkov", "ntdll: Implement NtQuerySection.", 2 },';
echo '+ { "Dmitry Timoshkov", "kernel32/tests: Add tests for NtQuerySection.", 2 },';
echo '+ { "Dmitry Timoshkov", "server: CreateFileMapping should not fail without SEC_COMMIT for a named file section.", 1 },';
echo '+ { "Dmitry Timoshkov", "ntdll: For section queries return real file size.", 1 },';
) >> "$patchlist"
fi