1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ps/i386/psldt.c
5 * PURPOSE: LDT support for x86
6 * PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* FUNCTIONS *****************************************************************/
16
17 VOID
18 NTAPI
PspDeleteLdt(PEPROCESS Process)19 PspDeleteLdt(PEPROCESS Process)
20 {
21 /* FIXME - LdtInformation must be null as long as we don't implement VDMs */
22 ASSERT(Process->LdtInformation == NULL);
23 }
24
25 VOID
26 NTAPI
PspDeleteVdmObjects(PEPROCESS Process)27 PspDeleteVdmObjects(PEPROCESS Process)
28 {
29 /* If there are no VDM objects, just exit */
30 if (Process->VdmObjects == NULL)
31 return;
32
33 /* FIXME: Need to do more than just freeing the main VdmObjects member! */
34 UNIMPLEMENTED;
35
36 /* Free VDM objects */
37 ExFreePoolWithTag(Process->VdmObjects, TAG_KERNEL);
38 Process->VdmObjects = NULL;
39 }
40
41 NTSTATUS
42 NTAPI
PspQueryDescriptorThread(IN PETHREAD Thread,IN PVOID ThreadInformation,IN ULONG ThreadInformationLength,OUT PULONG ReturnLength OPTIONAL)43 PspQueryDescriptorThread(IN PETHREAD Thread,
44 IN PVOID ThreadInformation,
45 IN ULONG ThreadInformationLength,
46 OUT PULONG ReturnLength OPTIONAL)
47 {
48 DESCRIPTOR_TABLE_ENTRY DescriptorEntry;
49 LDT_ENTRY Descriptor;
50 NTSTATUS Status;
51 PAGED_CODE();
52
53 /* Verify the size */
54 if (ThreadInformationLength != sizeof(DESCRIPTOR_TABLE_ENTRY))
55 {
56 /* Fail */
57 return STATUS_INFO_LENGTH_MISMATCH;
58 }
59
60 /* Enter SEH for the copy */
61 _SEH2_TRY
62 {
63 /* Get the descriptor */
64 RtlCopyMemory(&DescriptorEntry,
65 ThreadInformation,
66 sizeof(DESCRIPTOR_TABLE_ENTRY));
67 }
68 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
69 {
70 /* Return the exception code */
71 _SEH2_YIELD(return _SEH2_GetExceptionCode());
72 }
73 _SEH2_END;
74
75 /* Check if this is a GDT selector */
76 if (!(DescriptorEntry.Selector & 0x4))
77 {
78 /* Get the GDT entry */
79 Status = Ke386GetGdtEntryThread(&Thread->Tcb,
80 DescriptorEntry.Selector & 0xFFFFFFF8,
81 (PKGDTENTRY)&Descriptor);
82 if (!NT_SUCCESS(Status)) return Status;
83
84 /* Enter SEH for the copy */
85 _SEH2_TRY
86 {
87 /* Copy the GDT entry to caller */
88 RtlCopyMemory(&((PDESCRIPTOR_TABLE_ENTRY)ThreadInformation)->
89 Descriptor,
90 &Descriptor,
91 sizeof(LDT_ENTRY));
92 if (ReturnLength) *ReturnLength = sizeof(LDT_ENTRY);
93 }
94 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
95 {
96 /* Return the exception code */
97 _SEH2_YIELD(return _SEH2_GetExceptionCode());
98 }
99 _SEH2_END;
100
101 /* Success */
102 Status = STATUS_SUCCESS;
103 }
104 else
105 {
106 /* This is only supported for VDM, which we don't implement */
107 ASSERT(Thread->ThreadsProcess->LdtInformation == NULL);
108 Status = STATUS_NO_LDT;
109 }
110
111 /* Return status to caller */
112 return Status;
113 }
114