mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 07:32:57 +00:00
[NTOS:CM] Consistently use synchronous I/O for registry hives.
Our current CmpFileRead/CmpFileWrite do not wait for completion, so will cause stack corruption if used on files opened in async mode.
This commit is contained in:
parent
dfb7e2d639
commit
79b0fce5dc
2 changed files with 22 additions and 4 deletions
|
@ -366,7 +366,10 @@ CmpOpenHiveFiles(IN PCUNICODE_STRING BaseName,
|
||||||
/* Default attributes */
|
/* Default attributes */
|
||||||
AttributeFlags = FILE_ATTRIBUTE_NORMAL;
|
AttributeFlags = FILE_ATTRIBUTE_NORMAL;
|
||||||
|
|
||||||
/* Now create the file */
|
/* Now create the file.
|
||||||
|
* Note: We use FILE_SYNCHRONOUS_IO_NONALERT here to simplify CmpFileRead/CmpFileWrite.
|
||||||
|
* Windows does async I/O and therefore does not use this flag (or SYNCHRONIZE).
|
||||||
|
*/
|
||||||
Status = ZwCreateFile(Primary,
|
Status = ZwCreateFile(Primary,
|
||||||
DesiredAccess | SYNCHRONIZE,
|
DesiredAccess | SYNCHRONIZE,
|
||||||
&ObjectAttributes,
|
&ObjectAttributes,
|
||||||
|
@ -543,16 +546,19 @@ CmpOpenHiveFiles(IN PCUNICODE_STRING BaseName,
|
||||||
AttributeFlags |= FILE_ATTRIBUTE_HIDDEN;
|
AttributeFlags |= FILE_ATTRIBUTE_HIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now create the file */
|
/* Now create the file.
|
||||||
|
* Note: We use FILE_SYNCHRONOUS_IO_NONALERT here to simplify CmpFileRead/CmpFileWrite.
|
||||||
|
* Windows does async I/O and therefore does not use this flag (or SYNCHRONIZE).
|
||||||
|
*/
|
||||||
Status = ZwCreateFile(Log,
|
Status = ZwCreateFile(Log,
|
||||||
DesiredAccess,
|
DesiredAccess | SYNCHRONIZE,
|
||||||
&ObjectAttributes,
|
&ObjectAttributes,
|
||||||
&IoStatusBlock,
|
&IoStatusBlock,
|
||||||
NULL,
|
NULL,
|
||||||
AttributeFlags,
|
AttributeFlags,
|
||||||
ShareMode,
|
ShareMode,
|
||||||
CreateDisposition,
|
CreateDisposition,
|
||||||
IoFlags,
|
FILE_SYNCHRONOUS_IO_NONALERT | IoFlags,
|
||||||
NULL,
|
NULL,
|
||||||
0);
|
0);
|
||||||
if ((NT_SUCCESS(Status)) && (MarkAsSystemHive))
|
if ((NT_SUCCESS(Status)) && (MarkAsSystemHive))
|
||||||
|
|
|
@ -89,6 +89,8 @@ CmpFileRead(IN PHHIVE RegistryHive,
|
||||||
_FileOffset.QuadPart = *FileOffset;
|
_FileOffset.QuadPart = *FileOffset;
|
||||||
Status = ZwReadFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
|
Status = ZwReadFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
|
||||||
Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
|
Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
|
||||||
|
/* We do synchronous I/O for simplicity - see CmpOpenHiveFiles. */
|
||||||
|
ASSERT(Status != STATUS_PENDING);
|
||||||
return NT_SUCCESS(Status) ? TRUE : FALSE;
|
return NT_SUCCESS(Status) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +119,11 @@ CmpFileWrite(IN PHHIVE RegistryHive,
|
||||||
_FileOffset.QuadPart = *FileOffset;
|
_FileOffset.QuadPart = *FileOffset;
|
||||||
Status = ZwWriteFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
|
Status = ZwWriteFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
|
||||||
Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
|
Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
|
||||||
|
/* We do synchronous I/O for simplicity - see CmpOpenHiveFiles.
|
||||||
|
* Windows optimizes here by starting an async write for each 64k chunk,
|
||||||
|
* then waiting for all writes to complete at once.
|
||||||
|
*/
|
||||||
|
ASSERT(Status != STATUS_PENDING);
|
||||||
return NT_SUCCESS(Status) ? TRUE : FALSE;
|
return NT_SUCCESS(Status) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,5 +185,10 @@ CmpFileFlush(IN PHHIVE RegistryHive,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
Status = ZwFlushBuffersFile(HiveHandle, &IoStatusBlock);
|
Status = ZwFlushBuffersFile(HiveHandle, &IoStatusBlock);
|
||||||
|
|
||||||
|
/* This operation is always synchronous */
|
||||||
|
ASSERT(Status != STATUS_PENDING);
|
||||||
|
ASSERT(Status == IoStatusBlock.Status);
|
||||||
|
|
||||||
return NT_SUCCESS(Status) ? TRUE : FALSE;
|
return NT_SUCCESS(Status) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue