1
0
Fork 0
mirror of synced 2025-03-07 03:53:26 +01:00

kernel32/tests: Improve loading of debugger's test children results.

Even if there's a synchronisation mechanism between kernel32:debugger
and its children which ensures that child has finished writing to and
closed the blackbox logging file before reading it, there's no
guarantee that the file is not re-opened by another process: antivirus,
file indexing...
And according to [1], even the OS itself can still have opened references
to it.

So, always open/read the blackbox file in read share mode to work around
this issue.

Also, harden the code for potential errors, and be nicer in where
failures come from.

[1] https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/irp-mj-cleanup

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53456
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
This commit is contained in:
Eric Pouech 2022-12-16 16:38:54 +01:00 committed by Alexandre Julliard
parent 2acacb83d1
commit 2486f5a002

View file

@ -132,38 +132,45 @@ static void save_blackbox(const char* logfile, void* blackbox, int size, const c
{
HANDLE hFile;
DWORD written;
BOOL ret;
hFile=CreateFileA(logfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
hFile = CreateFileA(logfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, 0);
ok(hFile != INVALID_HANDLE_VALUE, "Couldn't create %s: %lu\n", logfile, GetLastError());
if (hFile == INVALID_HANDLE_VALUE)
return;
WriteFile(hFile, blackbox, size, &written, NULL);
ret = WriteFile(hFile, blackbox, size, &written, NULL);
ok(ret && written == size, "Error writing\n");
if (dbgtrace && dbgtrace[0])
WriteFile(hFile, dbgtrace, strlen(dbgtrace), &written, NULL);
{
ret = WriteFile(hFile, dbgtrace, strlen(dbgtrace), &written, NULL);
ok(ret && written == strlen(dbgtrace), "Error writing\n");
}
CloseHandle(hFile);
}
static int load_blackbox(const char* logfile, void* blackbox, int size)
#define load_blackbox(a, b, c) _load_blackbox(__LINE__, (a), (b), (c))
static int _load_blackbox(unsigned int line, const char* logfile, void* blackbox, int size)
{
HANDLE hFile;
DWORD read;
BOOL ret;
char buf[4096];
hFile=CreateFileA(logfile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
hFile = CreateFileA(logfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
if (hFile == INVALID_HANDLE_VALUE)
{
ok(0, "unable to open '%s'\n", logfile);
ok_(__FILE__, line)(0, "unable to open '%s': %#lx\n", logfile, GetLastError());
return 0;
}
SetLastError(0xdeadbeef);
ret=ReadFile(hFile, blackbox, size, &read, NULL);
ret = ReadFile(hFile, blackbox, size, &read, NULL);
ok(ret, "ReadFile failed: %ld\n", GetLastError());
ok(read == size, "wrong size for '%s': read=%ld\n", logfile, read);
ret = ReadFile(hFile, buf, sizeof(buf) - 1, &read, NULL);
if (ret && read)
{
buf[read] = 0;
trace("debugger traces:\n%s", buf);
trace("debugger traces:>>>\n%s\n<<< Done.\n", buf);
}
CloseHandle(hFile);
return 1;