:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / ldr / userldr.c
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS kernel
4  * FILE:            ntoskrnl/ldr/sysdll.c
5  * PURPOSE:         Loaders for PE executables
6  * PROGRAMMERS:     Jean Michault
7  *                  Rex Jolliff (rex@lvcablemodem.com)
8  * UPDATE HISTORY:
9  *   DW   26/01/00  Created
10  */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/module.h>
16 #include <internal/ntoskrnl.h>
17 #include <internal/ob.h>
18 #include <internal/ps.h>
19 #include <napi/teb.h>
20 #include <internal/ldr.h>
21
22 #define NDEBUG
23 #include <internal/debug.h>
24
25
26 /* FUNCTIONS *****************************************************************/
27
28 NTSTATUS LdrpMapImage(HANDLE ProcessHandle,
29                       HANDLE SectionHandle,
30                       PVOID* ReturnedImageBase)
31 /*
32  * FUNCTION: LdrpMapImage maps a user-mode image into an address space
33  * PARAMETERS:
34  *   ProcessHandle
35  *              Points to the process to map the image into
36  * 
37  *   SectionHandle
38  *              Points to the section to map
39  * 
40  * RETURNS: Status
41  */
42 {   
43   ULONG ViewSize;
44   PVOID ImageBase;
45   NTSTATUS Status;
46
47   ViewSize = 0;
48   ImageBase = 0;
49   
50   Status = ZwMapViewOfSection(SectionHandle,
51                               ProcessHandle,
52                               (PVOID*)&ImageBase,
53                               0,
54                               ViewSize,
55                               NULL,
56                               &ViewSize,
57                               0,
58                               MEM_COMMIT,
59                               PAGE_READWRITE);
60   if (!NT_SUCCESS(Status))
61     {
62       CPRINT("Image map view of section failed (Status %x)", Status);
63       return(Status);
64     }
65   
66    *ReturnedImageBase = ImageBase;
67    
68    return(STATUS_SUCCESS);
69 }