imagehlp: Implement ImageLoad and cleanup ImageUnload.
Signed-off-by: Vijay Kiran Kamuju <infyquest@gmail.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
3eca7c1f8e
commit
55a62c739c
|
@ -33,8 +33,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Data
|
* Data
|
||||||
*/
|
*/
|
||||||
|
static LIST_ENTRY image_list = { &image_list, &image_list };
|
||||||
static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
|
|
||||||
|
|
||||||
DECLSPEC_HIDDEN extern HANDLE IMAGEHLP_hHeap;
|
DECLSPEC_HIDDEN extern HANDLE IMAGEHLP_hHeap;
|
||||||
|
|
||||||
|
@ -69,57 +68,62 @@ DWORD WINAPI GetImageUnusedHeaderBytes(
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* ImageLoad (IMAGEHLP.@)
|
* ImageLoad (IMAGEHLP.@)
|
||||||
*/
|
*/
|
||||||
PLOADED_IMAGE WINAPI ImageLoad(PCSTR DllName, PCSTR DllPath)
|
PLOADED_IMAGE WINAPI ImageLoad(PCSTR dll_name, PCSTR dll_path)
|
||||||
{
|
{
|
||||||
PLOADED_IMAGE pLoadedImage;
|
LOADED_IMAGE *image;
|
||||||
|
|
||||||
FIXME("(%s, %s): stub\n", DllName, DllPath);
|
TRACE("(%s, %s)\n", dll_name, dll_path);
|
||||||
|
|
||||||
pLoadedImage = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
|
image = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(*image));
|
||||||
if (pLoadedImage)
|
if (!image) return NULL;
|
||||||
pLoadedImage->FileHeader = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(IMAGE_NT_HEADERS));
|
|
||||||
|
|
||||||
return pLoadedImage;
|
if (!MapAndLoad(dll_name, dll_path, image, TRUE, TRUE))
|
||||||
|
{
|
||||||
|
HeapFree(IMAGEHLP_hHeap, 0, image);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
image->Links.Flink = image_list.Flink;
|
||||||
|
image->Links.Blink = &image_list;
|
||||||
|
image_list.Flink->Blink = &image->Links;
|
||||||
|
image_list.Flink = &image->Links;
|
||||||
|
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* ImageUnload (IMAGEHLP.@)
|
* ImageUnload (IMAGEHLP.@)
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
|
BOOL WINAPI ImageUnload(PLOADED_IMAGE loaded_image)
|
||||||
{
|
{
|
||||||
LIST_ENTRY *pCurrent, *pFind;
|
LIST_ENTRY *entry, *mark;
|
||||||
|
PLOADED_IMAGE image;
|
||||||
|
|
||||||
TRACE("(%p)\n", pLoadedImage);
|
TRACE("(%p)\n", loaded_image);
|
||||||
|
|
||||||
if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
|
/* FIXME: do we really need to check this? */
|
||||||
|
mark = &image_list;
|
||||||
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
||||||
{
|
{
|
||||||
/* No image loaded or null pointer */
|
image = CONTAINING_RECORD(entry, LOADED_IMAGE, Links);
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
if (image == loaded_image)
|
||||||
return FALSE;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFind=&pLoadedImage->Links;
|
if (entry == mark)
|
||||||
pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
|
|
||||||
while((pCurrent != pFind) &&
|
|
||||||
(pCurrent != NULL))
|
|
||||||
pCurrent = pCurrent->Flink;
|
|
||||||
if(!pCurrent)
|
|
||||||
{
|
{
|
||||||
/* Not found */
|
/* Not found */
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pCurrent->Blink)
|
entry->Blink->Flink = entry->Flink;
|
||||||
pCurrent->Blink->Flink = pCurrent->Flink;
|
entry->Flink->Blink = entry->Blink;
|
||||||
else
|
|
||||||
IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
|
|
||||||
pCurrent->Flink, LOADED_IMAGE, Links):NULL;
|
|
||||||
|
|
||||||
if(pCurrent->Flink)
|
UnMapAndLoad(loaded_image);
|
||||||
pCurrent->Flink->Blink = pCurrent->Blink;
|
HeapFree(IMAGEHLP_hHeap, 0, loaded_image);
|
||||||
|
|
||||||
return FALSE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
|
@ -457,9 +457,9 @@ static void test_image_load(void)
|
||||||
|
|
||||||
if (img)
|
if (img)
|
||||||
{
|
{
|
||||||
todo_wine ok(!strcmp(img->ModuleName, temp_file),
|
ok(!strcmp(img->ModuleName, temp_file),
|
||||||
"unexpected ModuleName, got %s instead of %s\n", img->ModuleName, temp_file);
|
"unexpected ModuleName, got %s instead of %s\n", img->ModuleName, temp_file);
|
||||||
todo_wine ok(img->MappedAddress != NULL, "MappedAddress != NULL\n");
|
ok(img->MappedAddress != NULL, "MappedAddress != NULL\n");
|
||||||
if (img->MappedAddress)
|
if (img->MappedAddress)
|
||||||
{
|
{
|
||||||
ok(!memcmp(img->MappedAddress, &bin.dos_header, sizeof(bin.dos_header)),
|
ok(!memcmp(img->MappedAddress, &bin.dos_header, sizeof(bin.dos_header)),
|
||||||
|
@ -468,10 +468,10 @@ static void test_image_load(void)
|
||||||
ok(img->FileHeader != NULL, "FileHeader != NULL\n");
|
ok(img->FileHeader != NULL, "FileHeader != NULL\n");
|
||||||
if (img->FileHeader)
|
if (img->FileHeader)
|
||||||
{
|
{
|
||||||
todo_wine ok(!memcmp(img->FileHeader, &bin.nt_headers, sizeof(bin.nt_headers)),
|
ok(!memcmp(img->FileHeader, &bin.nt_headers, sizeof(bin.nt_headers)),
|
||||||
"FileHeader doesn't point to IMAGE_NT_HEADERS32\n");
|
"FileHeader doesn't point to IMAGE_NT_HEADERS32\n");
|
||||||
}
|
}
|
||||||
todo_wine ok(img->NumberOfSections == 3,
|
ok(img->NumberOfSections == 3,
|
||||||
"unexpected NumberOfSections, got %d instead of 3\n", img->NumberOfSections);
|
"unexpected NumberOfSections, got %d instead of 3\n", img->NumberOfSections);
|
||||||
if (img->NumberOfSections >= 3)
|
if (img->NumberOfSections >= 3)
|
||||||
{
|
{
|
||||||
|
@ -485,7 +485,7 @@ static void test_image_load(void)
|
||||||
"unexpected name for section 2, expected .idata, got %s\n",
|
"unexpected name for section 2, expected .idata, got %s\n",
|
||||||
(const char *)img->Sections[2].Name);
|
(const char *)img->Sections[2].Name);
|
||||||
}
|
}
|
||||||
todo_wine ok(img->Characteristics == 0x102,
|
ok(img->Characteristics == 0x102,
|
||||||
"unexpected Characteristics, got 0x%x instead of 0x102\n", img->Characteristics);
|
"unexpected Characteristics, got 0x%x instead of 0x102\n", img->Characteristics);
|
||||||
ok(img->fSystemImage == 0,
|
ok(img->fSystemImage == 0,
|
||||||
"unexpected fSystemImage, got %d instead of 0\n", img->fSystemImage);
|
"unexpected fSystemImage, got %d instead of 0\n", img->fSystemImage);
|
||||||
|
@ -495,7 +495,7 @@ static void test_image_load(void)
|
||||||
"unexpected fReadOnly, got %d instead of 1\n", img->fReadOnly);
|
"unexpected fReadOnly, got %d instead of 1\n", img->fReadOnly);
|
||||||
todo_wine ok(img->Version == 1 || broken(!img->Version) /* <= WinXP */,
|
todo_wine ok(img->Version == 1 || broken(!img->Version) /* <= WinXP */,
|
||||||
"unexpected Version, got %d instead of 1\n", img->Version);
|
"unexpected Version, got %d instead of 1\n", img->Version);
|
||||||
todo_wine ok(img->SizeOfImage == 0x600,
|
ok(img->SizeOfImage == 0x600,
|
||||||
"unexpected SizeOfImage, got 0x%x instead of 0x600\n", img->SizeOfImage);
|
"unexpected SizeOfImage, got 0x%x instead of 0x600\n", img->SizeOfImage);
|
||||||
|
|
||||||
count = 0xdeadbeef;
|
count = 0xdeadbeef;
|
||||||
|
|
Loading…
Reference in New Issue