ReactOS  0.4.14-dev-390-g34947ad
access.c File Reference
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winnt.h"
#include "winternl.h"
#include "winerror.h"
#include "wine/debug.h"
#include "imagehlp.h"
Include dependency graph for access.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (imagehlp)
 
BOOL WINAPI GetImageConfigInformation (PLOADED_IMAGE LoadedImage, PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
 
DWORD WINAPI GetImageUnusedHeaderBytes (PLOADED_IMAGE LoadedImage, LPDWORD SizeUnusedHeaderBytes)
 
PLOADED_IMAGE WINAPI ImageLoad (PCSTR dll_name, PCSTR dll_path)
 
BOOL WINAPI ImageUnload (PLOADED_IMAGE loaded_image)
 
BOOL WINAPI MapAndLoad (PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage, BOOL bDotDll, BOOL bReadOnly)
 
BOOL WINAPI SetImageConfigInformation (PLOADED_IMAGE LoadedImage, PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
 
BOOL WINAPI UnMapAndLoad (PLOADED_IMAGE pLoadedImage)
 

Variables

static LIST_ENTRY image_list = { &image_list, &image_list }
 

Function Documentation

◆ GetImageConfigInformation()

BOOL WINAPI GetImageConfigInformation ( PLOADED_IMAGE  LoadedImage,
PIMAGE_LOAD_CONFIG_DIRECTORY  ImageConfigInformation 
)

Definition at line 42 of file access.c.

45 {
46  FIXME("(%p, %p): stub\n",
47  LoadedImage, ImageConfigInformation
48  );
50  return FALSE;
51 }
#define FIXME(fmt,...)
Definition: debug.h:110
#define SetLastError(x)
Definition: compat.h:417
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ GetImageUnusedHeaderBytes()

DWORD WINAPI GetImageUnusedHeaderBytes ( PLOADED_IMAGE  LoadedImage,
LPDWORD  SizeUnusedHeaderBytes 
)

Definition at line 56 of file access.c.

59 {
60  FIXME("(%p, %p): stub\n",
61  LoadedImage, SizeUnusedHeaderBytes
62  );
64  return 0;
65 }
#define FIXME(fmt,...)
Definition: debug.h:110
#define SetLastError(x)
Definition: compat.h:417
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ ImageLoad()

PLOADED_IMAGE WINAPI ImageLoad ( PCSTR  dll_name,
PCSTR  dll_path 
)

Definition at line 70 of file access.c.

71 {
73 
74  TRACE("(%s, %s)\n", dll_name, dll_path);
75 
76  image = HeapAlloc(GetProcessHeap(), 0, sizeof(*image));
77  if (!image) return NULL;
78 
79  if (!MapAndLoad(dll_name, dll_path, image, TRUE, TRUE))
80  {
82  return NULL;
83  }
84 
85  image->Links.Flink = image_list.Flink;
86  image->Links.Blink = &image_list;
87  image_list.Flink->Blink = &image->Links;
88  image_list.Flink = &image->Links;
89 
90  return image;
91 }
GLeglImageOES image
Definition: gl.h:2204
#define TRUE
Definition: types.h:120
BOOL WINAPI MapAndLoad(PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage, BOOL bDotDll, BOOL bReadOnly)
Definition: access.c:131
static LIST_ENTRY image_list
Definition: access.c:36
smooth NULL
Definition: ftsmooth.c:416
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define HeapFree(x, y, z)
Definition: compat.h:402

◆ ImageUnload()

BOOL WINAPI ImageUnload ( PLOADED_IMAGE  loaded_image)

Definition at line 96 of file access.c.

97 {
98  LIST_ENTRY *entry, *mark;
100 
101  TRACE("(%p)\n", loaded_image);
102 
103  /* FIXME: do we really need to check this? */
104  mark = &image_list;
105  for (entry = mark->Flink; entry != mark; entry = entry->Flink)
106  {
108  if (image == loaded_image)
109  break;
110  }
111 
112  if (entry == mark)
113  {
114  /* Not found */
116  return FALSE;
117  }
118 
119  entry->Blink->Flink = entry->Flink;
120  entry->Flink->Blink = entry->Blink;
121 
122  UnMapAndLoad(loaded_image);
123  HeapFree(GetProcessHeap(), 0, loaded_image);
124 
125  return TRUE;
126 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
Definition: access.c:228
GLeglImageOES image
Definition: gl.h:2204
#define TRUE
Definition: types.h:120
static LIST_ENTRY image_list
Definition: access.c:36
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
#define SetLastError(x)
Definition: compat.h:417
uint32_t entry
Definition: isohybrid.c:63
Definition: typedefs.h:117
#define HeapFree(x, y, z)
Definition: compat.h:402

◆ MapAndLoad()

BOOL WINAPI MapAndLoad ( PCSTR  pszImageName,
PCSTR  pszDllPath,
PLOADED_IMAGE  pLoadedImage,
BOOL  bDotDll,
BOOL  bReadOnly 
)

Definition at line 131 of file access.c.

133 {
134  CHAR szFileName[MAX_PATH];
136  HANDLE hFileMapping = NULL;
137  PVOID mapping = NULL;
138  PIMAGE_NT_HEADERS pNtHeader = NULL;
139 
140  TRACE("(%s, %s, %p, %d, %d)\n",
141  pszImageName, pszDllPath, pLoadedImage, bDotDll, bReadOnly);
142 
143  if (!SearchPathA(pszDllPath, pszImageName, bDotDll ? ".DLL" : ".EXE",
144  sizeof(szFileName), szFileName, NULL))
145  {
147  goto Error;
148  }
149 
150  hFile = CreateFileA(szFileName,
151  GENERIC_READ | (bReadOnly ? 0 : GENERIC_WRITE),
153  NULL, OPEN_EXISTING, 0, NULL);
155  {
156  WARN("CreateFile: Error = %d\n", GetLastError());
157  goto Error;
158  }
159 
160  hFileMapping = CreateFileMappingA(hFile, NULL,
161  (bReadOnly ? PAGE_READONLY : PAGE_READWRITE) | SEC_COMMIT,
162  0, 0, NULL);
163  if (!hFileMapping)
164  {
165  WARN("CreateFileMapping: Error = %d\n", GetLastError());
166  goto Error;
167  }
168 
169  mapping = MapViewOfFile(hFileMapping, bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0);
170  CloseHandle(hFileMapping);
171  if (!mapping)
172  {
173  WARN("MapViewOfFile: Error = %d\n", GetLastError());
174  goto Error;
175  }
176 
177  if (!(pNtHeader = RtlImageNtHeader(mapping)))
178  {
179  WARN("Not an NT header\n");
181  goto Error;
182  }
183 
184  pLoadedImage->ModuleName = HeapAlloc(GetProcessHeap(), 0,
185  strlen(szFileName) + 1);
186  if (pLoadedImage->ModuleName) strcpy(pLoadedImage->ModuleName, szFileName);
187  pLoadedImage->hFile = hFile;
188  pLoadedImage->MappedAddress = mapping;
189  pLoadedImage->FileHeader = pNtHeader;
190  pLoadedImage->Sections = (PIMAGE_SECTION_HEADER)
191  ((LPBYTE) &pNtHeader->OptionalHeader +
192  pNtHeader->FileHeader.SizeOfOptionalHeader);
193  pLoadedImage->NumberOfSections = pNtHeader->FileHeader.NumberOfSections;
194  pLoadedImage->SizeOfImage = GetFileSize(hFile, NULL);
195  pLoadedImage->Characteristics = pNtHeader->FileHeader.Characteristics;
196  pLoadedImage->LastRvaSection = pLoadedImage->Sections;
197 
198  pLoadedImage->fSystemImage = FALSE; /* FIXME */
199  pLoadedImage->fDOSImage = FALSE; /* FIXME */
200 
201  pLoadedImage->Links.Flink = &pLoadedImage->Links;
202  pLoadedImage->Links.Blink = &pLoadedImage->Links;
203 
204  return TRUE;
205 
206 Error:
208  return FALSE;
209 }
BOOLEAN fDOSImage
Definition: dbghelp.h:112
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
HANDLE hFile
Definition: dbghelp.h:100
#define MapViewOfFile
Definition: compat.h:410
PIMAGE_SECTION_HEADER Sections
Definition: dbghelp.h:109
LPCWSTR pszImageName
Definition: env.c:55
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
char CHAR
Definition: xmlstorage.h:175
#define WARN(fmt,...)
Definition: debug.h:111
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define FILE_SHARE_READ
Definition: compat.h:125
ULONG NumberOfSections
Definition: dbghelp.h:108
unsigned char * LPBYTE
Definition: typedefs.h:52
#define SEC_COMMIT
Definition: mmtypes.h:99
DWORD WINAPI SearchPathA(IN LPCSTR lpPath OPTIONAL, IN LPCSTR lpFileName, IN LPCSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart OPTIONAL)
Definition: path.c:1122
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
#define FILE_MAP_READ
Definition: compat.h:435
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define OPEN_EXISTING
Definition: compat.h:434
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
PUCHAR MappedAddress
Definition: dbghelp.h:101
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
PIMAGE_SECTION_HEADER LastRvaSection
Definition: dbghelp.h:107
#define FILE_MAP_WRITE
Definition: winbase.h:154
#define MAX_PATH
Definition: compat.h:26
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
BOOL Error
Definition: chkdsk.c:66
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define SetLastError(x)
Definition: compat.h:417
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
ULONG Characteristics
Definition: dbghelp.h:110
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
PSTR ModuleName
Definition: dbghelp.h:99
#define PAGE_READONLY
Definition: compat.h:127
PIMAGE_NT_HEADERS32 FileHeader
Definition: dbghelp.h:105
#define RtlImageNtHeader
Definition: compat.h:465
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
LIST_ENTRY Links
Definition: dbghelp.h:115
ULONG SizeOfImage
Definition: dbghelp.h:116
#define UnmapViewOfFile
Definition: compat.h:411
HANDLE NTAPI CreateFileMappingA(IN HANDLE hFile, IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes, IN DWORD flProtect, IN DWORD dwMaximumSizeHigh, IN DWORD dwMaximumSizeLow, IN LPCSTR lpName)
Definition: filemap.c:23
BOOLEAN fSystemImage
Definition: dbghelp.h:111
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by BindImageEx(), ImageLoad(), and START_TEST().

◆ SetImageConfigInformation()

BOOL WINAPI SetImageConfigInformation ( PLOADED_IMAGE  LoadedImage,
PIMAGE_LOAD_CONFIG_DIRECTORY  ImageConfigInformation 
)

Definition at line 214 of file access.c.

217 {
218  FIXME("(%p, %p): stub\n",
219  LoadedImage, ImageConfigInformation
220  );
222  return FALSE;
223 }
#define FIXME(fmt,...)
Definition: debug.h:110
#define SetLastError(x)
Definition: compat.h:417
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ UnMapAndLoad()

BOOL WINAPI UnMapAndLoad ( PLOADED_IMAGE  pLoadedImage)

Definition at line 228 of file access.c.

229 {
230  HeapFree(GetProcessHeap(), 0, pLoadedImage->ModuleName);
231  /* FIXME: MSDN states that a new checksum is computed and stored into the file */
232  if (pLoadedImage->MappedAddress) UnmapViewOfFile(pLoadedImage->MappedAddress);
233  if (pLoadedImage->hFile != INVALID_HANDLE_VALUE) CloseHandle(pLoadedImage->hFile);
234  return TRUE;
235 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
HANDLE hFile
Definition: dbghelp.h:100
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
PUCHAR MappedAddress
Definition: dbghelp.h:101
#define GetProcessHeap()
Definition: compat.h:403
PSTR ModuleName
Definition: dbghelp.h:99
#define UnmapViewOfFile
Definition: compat.h:411
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by BindImageEx(), and ImageUnload().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( imagehlp  )

Variable Documentation

◆ image_list

LIST_ENTRY image_list = { &image_list, &image_list }
static

Definition at line 36 of file access.c.

Referenced by ImageLoad(), and ImageUnload().