wined3d: Force stream info update on vertex shader change.
[wine.git] / dlls / imagehlp / access.c
blob9e1f1875d68ea8c440051883b466d57782e4b246
1 /*
2 * IMAGEHLP library
4 * Copyright 1998 Patrik Stridvall
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnt.h"
26 #include "winternl.h"
27 #include "winerror.h"
28 #include "wine/debug.h"
29 #include "imagehlp.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
33 /***********************************************************************
34 * Data
37 static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
39 static LOADED_IMAGE IMAGEHLP_EmptyLoadedImage = {
40 NULL, /* ModuleName */
41 0, /* hFile */
42 NULL, /* MappedAddress */
43 NULL, /* FileHeader */
44 NULL, /* LastRvaSection */
45 0, /* NumberOfSections */
46 NULL, /* Sections */
47 1, /* Characteristics */
48 FALSE, /* fSystemImage */
49 FALSE, /* fDOSImage */
50 FALSE, /* fReadOnly */
51 0, /* Version */
52 { &IMAGEHLP_EmptyLoadedImage.Links, &IMAGEHLP_EmptyLoadedImage.Links }, /* Links */
53 148, /* SizeOfImage; */
56 DECLSPEC_HIDDEN extern HANDLE IMAGEHLP_hHeap;
58 /***********************************************************************
59 * GetImageConfigInformation (IMAGEHLP.@)
61 BOOL WINAPI GetImageConfigInformation(
62 PLOADED_IMAGE LoadedImage,
63 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
65 FIXME("(%p, %p): stub\n",
66 LoadedImage, ImageConfigInformation
68 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
69 return FALSE;
72 /***********************************************************************
73 * GetImageUnusedHeaderBytes (IMAGEHLP.@)
75 DWORD WINAPI GetImageUnusedHeaderBytes(
76 PLOADED_IMAGE LoadedImage,
77 LPDWORD SizeUnusedHeaderBytes)
79 FIXME("(%p, %p): stub\n",
80 LoadedImage, SizeUnusedHeaderBytes
82 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
83 return 0;
86 /***********************************************************************
87 * ImageLoad (IMAGEHLP.@)
89 PLOADED_IMAGE WINAPI ImageLoad(PCSTR DllName, PCSTR DllPath)
91 PLOADED_IMAGE pLoadedImage;
93 FIXME("(%s, %s): stub\n", DllName, DllPath);
95 pLoadedImage = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
96 if (pLoadedImage)
97 pLoadedImage->FileHeader = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(IMAGE_NT_HEADERS));
99 return pLoadedImage;
102 /***********************************************************************
103 * ImageUnload (IMAGEHLP.@)
105 BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
107 LIST_ENTRY *pCurrent, *pFind;
109 TRACE("(%p)\n", pLoadedImage);
111 if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
113 /* No image loaded or null pointer */
114 SetLastError(ERROR_INVALID_PARAMETER);
115 return FALSE;
118 pFind=&pLoadedImage->Links;
119 pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
120 while((pCurrent != pFind) &&
121 (pCurrent != NULL))
122 pCurrent = pCurrent->Flink;
123 if(!pCurrent)
125 /* Not found */
126 SetLastError(ERROR_INVALID_PARAMETER);
127 return FALSE;
130 if(pCurrent->Blink)
131 pCurrent->Blink->Flink = pCurrent->Flink;
132 else
133 IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
134 pCurrent->Flink, LOADED_IMAGE, Links):NULL;
136 if(pCurrent->Flink)
137 pCurrent->Flink->Blink = pCurrent->Blink;
139 return FALSE;
142 /***********************************************************************
143 * MapAndLoad (IMAGEHLP.@)
145 BOOL WINAPI MapAndLoad(PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
146 BOOL bDotDll, BOOL bReadOnly)
148 CHAR szFileName[MAX_PATH];
149 HANDLE hFile = INVALID_HANDLE_VALUE;
150 HANDLE hFileMapping = NULL;
151 PVOID mapping = NULL;
152 PIMAGE_NT_HEADERS pNtHeader = NULL;
154 TRACE("(%s, %s, %p, %d, %d)\n",
155 pszImageName, pszDllPath, pLoadedImage, bDotDll, bReadOnly);
157 if (!SearchPathA(pszDllPath, pszImageName, bDotDll ? ".DLL" : ".EXE",
158 sizeof(szFileName), szFileName, NULL))
160 SetLastError(ERROR_FILE_NOT_FOUND);
161 goto Error;
164 hFile = CreateFileA(szFileName,
165 GENERIC_READ | (bReadOnly ? 0 : GENERIC_WRITE),
166 FILE_SHARE_READ,
167 NULL, OPEN_EXISTING, 0, NULL);
168 if (hFile == INVALID_HANDLE_VALUE)
170 WARN("CreateFile: Error = %d\n", GetLastError());
171 goto Error;
174 hFileMapping = CreateFileMappingA(hFile, NULL,
175 (bReadOnly ? PAGE_READONLY : PAGE_READWRITE) | SEC_COMMIT,
176 0, 0, NULL);
177 if (!hFileMapping)
179 WARN("CreateFileMapping: Error = %d\n", GetLastError());
180 goto Error;
183 mapping = MapViewOfFile(hFileMapping, bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0);
184 CloseHandle(hFileMapping);
185 if (!mapping)
187 WARN("MapViewOfFile: Error = %d\n", GetLastError());
188 goto Error;
191 if (!(pNtHeader = RtlImageNtHeader(mapping)))
193 WARN("Not an NT header\n");
194 UnmapViewOfFile(mapping);
195 goto Error;
198 pLoadedImage->ModuleName = HeapAlloc(GetProcessHeap(), 0,
199 strlen(szFileName) + 1);
200 if (pLoadedImage->ModuleName) strcpy(pLoadedImage->ModuleName, szFileName);
201 pLoadedImage->hFile = hFile;
202 pLoadedImage->MappedAddress = mapping;
203 pLoadedImage->FileHeader = pNtHeader;
204 pLoadedImage->Sections = (PIMAGE_SECTION_HEADER)
205 ((LPBYTE) &pNtHeader->OptionalHeader +
206 pNtHeader->FileHeader.SizeOfOptionalHeader);
207 pLoadedImage->NumberOfSections = pNtHeader->FileHeader.NumberOfSections;
208 pLoadedImage->SizeOfImage = GetFileSize(hFile, NULL);
209 pLoadedImage->Characteristics = pNtHeader->FileHeader.Characteristics;
210 pLoadedImage->LastRvaSection = pLoadedImage->Sections;
212 pLoadedImage->fSystemImage = FALSE; /* FIXME */
213 pLoadedImage->fDOSImage = FALSE; /* FIXME */
215 pLoadedImage->Links.Flink = &pLoadedImage->Links;
216 pLoadedImage->Links.Blink = &pLoadedImage->Links;
218 return TRUE;
220 Error:
221 if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
222 return FALSE;
225 /***********************************************************************
226 * SetImageConfigInformation (IMAGEHLP.@)
228 BOOL WINAPI SetImageConfigInformation(
229 PLOADED_IMAGE LoadedImage,
230 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
232 FIXME("(%p, %p): stub\n",
233 LoadedImage, ImageConfigInformation
235 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
236 return FALSE;
239 /***********************************************************************
240 * UnMapAndLoad (IMAGEHLP.@)
242 BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
244 HeapFree(GetProcessHeap(), 0, pLoadedImage->ModuleName);
245 /* FIXME: MSDN states that a new checksum is computed and stored into the file */
246 if (pLoadedImage->MappedAddress) UnmapViewOfFile(pLoadedImage->MappedAddress);
247 if (pLoadedImage->hFile != INVALID_HANDLE_VALUE) CloseHandle(pLoadedImage->hFile);
248 return TRUE;