1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory 4 * PURPOSE: Test for NtOpenKey data alignment 5 * PROGRAMMER: Mark Jansen (mark.jansen@reactos.org) 6 */ 7 8 #include "precomp.h" 9 10 #define TEST_STR L"\\Registry\\Machine\\SOFTWARE" 11 12 START_TEST(NtOpenKey) 13 { 14 OBJECT_ATTRIBUTES Object; 15 UNICODE_STRING String; 16 char GccShouldNotAlignThis[40 * 2]; 17 char GccShouldNotAlignThis2[20]; 18 PVOID Alias = GccShouldNotAlignThis + 1; 19 PVOID UnalignedKey = GccShouldNotAlignThis2 + 1; 20 21 HANDLE KeyHandle; 22 NTSTATUS Status; 23 24 memcpy(Alias, TEST_STR, sizeof(TEST_STR)); 25 26 27 RtlInitUnicodeString(&String, TEST_STR); 28 InitializeObjectAttributes(&Object, &String, OBJ_CASE_INSENSITIVE, NULL, NULL); 29 30 Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &Object); 31 ok_ntstatus(Status, STATUS_SUCCESS); 32 33 if (!NT_SUCCESS(Status)) 34 return; 35 36 NtClose(KeyHandle); 37 38 String.Buffer = Alias; 39 ok_hex(((ULONG_PTR)String.Buffer) % 2, 1); 40 Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &Object); 41 ok_ntstatus(Status, STATUS_DATATYPE_MISALIGNMENT); // FIXME: Later windows versions succeed here. 42 if (NT_SUCCESS(Status)) 43 NtClose(KeyHandle); 44 45 RtlInitUnicodeString(&String, TEST_STR); 46 ok_hex(((ULONG_PTR)UnalignedKey) % 2, 1); 47 Status = NtOpenKey(UnalignedKey, KEY_QUERY_VALUE, &Object); 48 ok_ntstatus(Status, STATUS_SUCCESS); 49 if (NT_SUCCESS(Status)) 50 { 51 NtClose(*(HANDLE*)(UnalignedKey)); 52 } 53 } 54