1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * PROJECT: ReactOS kernel-mode tests
3*c2c66affSColin Finck * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4*c2c66affSColin Finck * PURPOSE: Kernel-Mode Test Suite Io Regressions KM-Test (Mdl)
5*c2c66affSColin Finck * PROGRAMMER: Aleksey Bragin <aleksey@reactos.org>
6*c2c66affSColin Finck */
7*c2c66affSColin Finck
8*c2c66affSColin Finck #include <kmt_test.h>
9*c2c66affSColin Finck
10*c2c66affSColin Finck #define NDEBUG
11*c2c66affSColin Finck #include <debug.h>
12*c2c66affSColin Finck
START_TEST(IoMdl)13*c2c66affSColin Finck START_TEST(IoMdl)
14*c2c66affSColin Finck {
15*c2c66affSColin Finck PMDL Mdl;
16*c2c66affSColin Finck PIRP Irp;
17*c2c66affSColin Finck PVOID VirtualAddress;
18*c2c66affSColin Finck ULONG MdlSize = 2*4096+184; // 2 pages and some random value
19*c2c66affSColin Finck ULONG TooLargeMdlSize = (0x10000 - sizeof(MDL)) / sizeof(ULONG_PTR) * PAGE_SIZE;
20*c2c66affSColin Finck
21*c2c66affSColin Finck // Try to alloc 2Gb MDL
22*c2c66affSColin Finck Mdl = IoAllocateMdl(NULL, 2048UL*0x100000, FALSE, FALSE, NULL);
23*c2c66affSColin Finck
24*c2c66affSColin Finck ok(Mdl == NULL,
25*c2c66affSColin Finck "IoAllocateMdl should fail allocation of 2Gb or more, but got Mdl=0x%X\n",
26*c2c66affSColin Finck (UINT_PTR)Mdl);
27*c2c66affSColin Finck
28*c2c66affSColin Finck if (Mdl)
29*c2c66affSColin Finck IoFreeMdl(Mdl);
30*c2c66affSColin Finck
31*c2c66affSColin Finck // Now create a valid MDL
32*c2c66affSColin Finck VirtualAddress = ExAllocatePool(NonPagedPool, MdlSize);
33*c2c66affSColin Finck Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, NULL);
34*c2c66affSColin Finck ok(Mdl != NULL, "Mdl allocation failed\n");
35*c2c66affSColin Finck // Check fields of the allocated struct
36*c2c66affSColin Finck ok(Mdl->Next == NULL, "Mdl->Next should be NULL, but is 0x%X\n",
37*c2c66affSColin Finck (UINT_PTR)Mdl->Next);
38*c2c66affSColin Finck ok(Mdl->ByteCount == MdlSize,
39*c2c66affSColin Finck "Mdl->ByteCount should be equal to MdlSize, but is 0x%X\n",
40*c2c66affSColin Finck (UINT_PTR)Mdl->ByteCount);
41*c2c66affSColin Finck // TODO: Check other fields of MDL struct
42*c2c66affSColin Finck
43*c2c66affSColin Finck IoFreeMdl(Mdl);
44*c2c66affSColin Finck
45*c2c66affSColin Finck // Test maximum size for an MDL
46*c2c66affSColin Finck Mdl = IoAllocateMdl(NULL, TooLargeMdlSize, FALSE, FALSE, NULL);
47*c2c66affSColin Finck ok(Mdl == NULL, "Mdl allocation for %lu bytes succeeded\n", TooLargeMdlSize);
48*c2c66affSColin Finck if (Mdl) IoFreeMdl(Mdl);
49*c2c66affSColin Finck
50*c2c66affSColin Finck Mdl = IoAllocateMdl(NULL, TooLargeMdlSize - PAGE_SIZE + 1, FALSE, FALSE, NULL);
51*c2c66affSColin Finck ok(Mdl == NULL, "Mdl allocation for %lu bytes succeeded\n", TooLargeMdlSize - PAGE_SIZE + 1);
52*c2c66affSColin Finck if (Mdl) IoFreeMdl(Mdl);
53*c2c66affSColin Finck
54*c2c66affSColin Finck Mdl = IoAllocateMdl(NULL, TooLargeMdlSize - PAGE_SIZE, FALSE, FALSE, NULL);
55*c2c66affSColin Finck ok(Mdl != NULL, "Mdl allocation for %lu bytes failed\n", TooLargeMdlSize - PAGE_SIZE);
56*c2c66affSColin Finck if (Mdl) IoFreeMdl(Mdl);
57*c2c66affSColin Finck
58*c2c66affSColin Finck Mdl = IoAllocateMdl(NULL, TooLargeMdlSize / 2, FALSE, FALSE, NULL);
59*c2c66affSColin Finck ok(Mdl != NULL, "Mdl allocation for %lu bytes failed\n", TooLargeMdlSize / 2);
60*c2c66affSColin Finck if (Mdl) IoFreeMdl(Mdl);
61*c2c66affSColin Finck
62*c2c66affSColin Finck // Allocate now with pointer to an Irp
63*c2c66affSColin Finck Irp = IoAllocateIrp(1, FALSE);
64*c2c66affSColin Finck ok(Irp != NULL, "IRP allocation failed\n");
65*c2c66affSColin Finck Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, Irp);
66*c2c66affSColin Finck ok(Mdl != NULL, "Mdl allocation failed\n");
67*c2c66affSColin Finck ok(Irp->MdlAddress == Mdl, "Irp->MdlAddress should be 0x%X, but is 0x%X\n",
68*c2c66affSColin Finck (UINT_PTR)Mdl, (UINT_PTR)Irp->MdlAddress);
69*c2c66affSColin Finck
70*c2c66affSColin Finck IoFreeMdl(Mdl);
71*c2c66affSColin Finck
72*c2c66affSColin Finck // TODO: Check a case when SecondaryBuffer == TRUE
73*c2c66affSColin Finck
74*c2c66affSColin Finck IoFreeIrp(Irp);
75*c2c66affSColin Finck ExFreePool(VirtualAddress);
76*c2c66affSColin Finck }
77