ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
February 2008
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
21 participants
460 discussions
Start a n
N
ew thread
[gbrunmar] 32122: * Implemented IDirect3D9's GetAdapterCount() and GetAdapterIdentifier() * Made d3d9.dll compile with MSVC
by gbrunmar@svn.reactos.org
Author: gbrunmar Date: Tue Feb 5 00:33:12 2008 New Revision: 32122 URL:
http://svn.reactos.org/svn/reactos?rev=32122&view=rev
Log: * Implemented IDirect3D9's GetAdapterCount() and GetAdapterIdentifier() * Made d3d9.dll compile with MSVC Added: trunk/reactos/dll/directx/d3d9/adapter.c (with props) trunk/reactos/dll/directx/d3d9/adapter.h (with props) Modified: trunk/reactos/dll/directx/d3d9/d3d9.rbuild trunk/reactos/dll/directx/d3d9/d3d9_common.h trunk/reactos/dll/directx/d3d9/d3d9_create.c trunk/reactos/dll/directx/d3d9/d3d9_helpers.c trunk/reactos/dll/directx/d3d9/d3d9_helpers.h trunk/reactos/dll/directx/d3d9/d3d9_impl.c trunk/reactos/dll/directx/d3d9/d3d9_private.h Added: trunk/reactos/dll/directx/d3d9/adapter.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/adapter.c…
============================================================================== --- trunk/reactos/dll/directx/d3d9/adapter.c (added) +++ trunk/reactos/dll/directx/d3d9/adapter.c Tue Feb 5 00:33:12 2008 @@ -1,0 +1,156 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS ReactX + * FILE: dll/directx/d3d9/adapter.c + * PURPOSE: d3d9.dll adapter info functions + * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se> + */ + +#include "d3d9_common.h" +#include <d3d9.h> +#include <ddraw.h> +#include <strsafe.h> + +typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); +typedef BOOL (WINAPI *LPFN_DISABLEWOW64FSREDIRECTION) (PVOID*); +typedef BOOL (WINAPI *LPFN_REVERTWOW64FSREDIRECTION) (PVOID); + +static BOOL GetDriverName(LPDISPLAY_DEVICEA pDisplayDevice, D3DADAPTER_IDENTIFIER9* pIdentifier) +{ + HKEY hKey; + BOOL bResult = FALSE; + + if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE, pDisplayDevice->DeviceKey + strlen("\\Registry\\Machine\\"), 0, KEY_QUERY_VALUE, &hKey)) + { + DWORD DriverNameLength = MAX_DEVICE_IDENTIFIER_STRING - (DWORD)strlen(".dll"); + DWORD Type = 0; + + if (ERROR_SUCCESS == RegQueryValueExA(hKey, "InstalledDisplayDrivers", 0, &Type, (LPBYTE)pIdentifier->Driver, &DriverNameLength)) + { + pIdentifier->Driver[DriverNameLength] = '\0'; + StringCbCatA(pIdentifier->Driver, MAX_DEVICE_IDENTIFIER_STRING, ".dll"); + bResult = TRUE; + } + + RegCloseKey(hKey); + } + + return bResult; +} + +static void GetDriverVersion(LPDISPLAY_DEVICEA pDisplayDevice, D3DADAPTER_IDENTIFIER9* pIdentifier) +{ + HMODULE hModule; + LPFN_ISWOW64PROCESS fnIsWow64Process; + BOOL bIsWow64 = FALSE; + PVOID OldWow64RedirectValue; + UINT DriverFileSize; + + hModule = GetModuleHandleA("KERNEL32"); + fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(hModule, "IsWow64Process"); + if (fnIsWow64Process) + { + fnIsWow64Process(GetCurrentProcess(), &bIsWow64); + if (bIsWow64) + { + LPFN_DISABLEWOW64FSREDIRECTION fnDisableWow64FsRedirection; + fnDisableWow64FsRedirection = (LPFN_DISABLEWOW64FSREDIRECTION)GetProcAddress(hModule, "Wow64DisableWow64FsRedirection"); + fnDisableWow64FsRedirection(&OldWow64RedirectValue); + } + } + + DriverFileSize = GetFileVersionInfoSizeA(pIdentifier->Driver, NULL); + if (DriverFileSize > 0) + { + VS_FIXEDFILEINFO* FixedFileInfo = NULL; + LPVOID pBlock = LocalAlloc(LMEM_ZEROINIT, DriverFileSize); + + if (TRUE == GetFileVersionInfoA(pIdentifier->Driver, 0, DriverFileSize, pBlock)) + { + if (TRUE == VerQueryValueA(pBlock, "\\", (LPVOID*)&FixedFileInfo, &DriverFileSize)) + { + pIdentifier->DriverVersion.HighPart = FixedFileInfo->dwFileVersionMS; + pIdentifier->DriverVersion.LowPart = FixedFileInfo->dwFileVersionLS; + } + } + + LocalFree(pBlock); + } + + if (bIsWow64) + { + LPFN_REVERTWOW64FSREDIRECTION fnRevertWow64FsRedirection; + fnRevertWow64FsRedirection = (LPFN_REVERTWOW64FSREDIRECTION)GetProcAddress(hModule, "Wow64RevertWow64FsRedirection"); + fnRevertWow64FsRedirection(&OldWow64RedirectValue); + } +} + + +static void ParseField(LPCSTR lpszDeviceKey, LPDWORD pField, LPCSTR lpszSubString) +{ + const char* ResultStr; + ResultStr = strstr(lpszDeviceKey, lpszSubString); + if (ResultStr != NULL) + { + *pField = strtol(ResultStr + strlen(lpszSubString), NULL, 16); + } +} + +static void GetDeviceId(LPCSTR lpszDeviceKey, D3DADAPTER_IDENTIFIER9* pIdentifier) +{ + ParseField(lpszDeviceKey, &pIdentifier->VendorId, "VEN_"); + ParseField(lpszDeviceKey, &pIdentifier->DeviceId, "DEV_"); + ParseField(lpszDeviceKey, &pIdentifier->SubSysId, "SUBSYS_"); + ParseField(lpszDeviceKey, &pIdentifier->Revision, "REV_"); +} + +static void GenerateDeviceIdentifier(D3DADAPTER_IDENTIFIER9* pIdentifier) +{ + DWORD* dwIdentifier = (DWORD*)&pIdentifier->DeviceIdentifier; + + pIdentifier->DeviceIdentifier = CLSID_DirectDraw; + + dwIdentifier[0] ^= pIdentifier->VendorId; + dwIdentifier[1] ^= pIdentifier->DeviceId; + dwIdentifier[2] ^= pIdentifier->SubSysId; + dwIdentifier[3] ^= pIdentifier->Revision; + dwIdentifier[2] ^= pIdentifier->DriverVersion.LowPart; + dwIdentifier[3] ^= pIdentifier->DriverVersion.HighPart; +} + +BOOL GetAdapterInfo(LPCSTR lpszDeviceName, D3DADAPTER_IDENTIFIER9* pIdentifier) +{ + DISPLAY_DEVICEA DisplayDevice; + DWORD AdapterIndex; + BOOL FoundDisplayDevice; + + memset(&DisplayDevice, 0, sizeof(DISPLAY_DEVICEA)); + DisplayDevice.cb = sizeof(DISPLAY_DEVICEA); + + AdapterIndex = 0; + FoundDisplayDevice = FALSE; + while (EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) == TRUE) + { + if (_stricmp(lpszDeviceName, DisplayDevice.DeviceName) == 0) + { + FoundDisplayDevice = TRUE; + break; + } + } + + /* No matching display device found? */ + if (FALSE == FoundDisplayDevice) + return FALSE; + + lstrcpynA(pIdentifier->Description, DisplayDevice.DeviceString, MAX_DEVICE_IDENTIFIER_STRING); + lstrcpynA(pIdentifier->DeviceName, DisplayDevice.DeviceName, CCHDEVICENAME); + + if (GetDriverName(&DisplayDevice, pIdentifier) == TRUE) + GetDriverVersion(&DisplayDevice, pIdentifier); + + GetDeviceId(DisplayDevice.DeviceID, pIdentifier); + + GenerateDeviceIdentifier(pIdentifier); + + return TRUE; +} Propchange: trunk/reactos/dll/directx/d3d9/adapter.c ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/dll/directx/d3d9/adapter.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/adapter.h…
============================================================================== --- trunk/reactos/dll/directx/d3d9/adapter.h (added) +++ trunk/reactos/dll/directx/d3d9/adapter.h Tue Feb 5 00:33:12 2008 @@ -1,0 +1,14 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS ReactX + * FILE: dll/directx/d3d9/adapter.h + * PURPOSE: d3d9.dll adapter info functions + * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se> + */ + +#ifndef _ADAPTER_H_ +#define _ADAPTER_H_ + +BOOL GetAdapterInfo(LPCSTR lpszDeviceName, D3DADAPTER_IDENTIFIER9* pIdentifier); + +#endif Propchange: trunk/reactos/dll/directx/d3d9/adapter.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/reactos/dll/directx/d3d9/d3d9.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9.rbui…
============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9.rbuild (original) +++ trunk/reactos/dll/directx/d3d9/d3d9.rbuild Tue Feb 5 00:33:12 2008 @@ -10,10 +10,12 @@ <library>uuid</library> <library>dxguid</library> <library>strsafe</library> + <library>version</library> <file>d3d9.c</file> <file>d3d9_helpers.c</file> <file>d3d9_impl.c</file> <file>d3d9_create.c</file> + <file>adapter.c</file> <file>d3d9.rc</file> </module> Modified: trunk/reactos/dll/directx/d3d9/d3d9_common.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_comm…
============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_common.h (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_common.h Tue Feb 5 00:33:12 2008 @@ -14,6 +14,6 @@ #define DLLAPI __declspec(dllexport) #define DX_D3D9_DEBUG 0x80000000 -extern const struct IDirect3D9Vtbl Direct3D9_Vtbl; +extern struct IDirect3D9Vtbl Direct3D9_Vtbl; #endif // _D3D9_COMMON_H_ Modified: trunk/reactos/dll/directx/d3d9/d3d9_create.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_crea…
============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_create.c (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_create.c Tue Feb 5 00:33:12 2008 @@ -46,31 +46,46 @@ pDisplayAdapter->bInUseFlag = TRUE; } +static BOOL GetDirect3DAdapterInfo(IN OUT LPDIRECT3D9_DISPLAYADAPTER_INT pDisplayAdapter) +{ + HDC hDC; + + /* Check if minimum DirectDraw is supported */ + if (IsDirectDrawSupported() == FALSE) + return FALSE; + + /* Test DC creation for the display device */ + if (NULL == (hDC = CreateDCA(NULL, pDisplayAdapter->szDeviceName, NULL, NULL))) + return FALSE; + + DeleteDC(hDC); + return TRUE; +} + static BOOL GetDisplayDeviceInfo(IN OUT LPDIRECT3D9_INT pDirect3D9) { DISPLAY_DEVICEA DisplayDevice; DWORD AdapterIndex; - HDC hDC; memset(&DisplayDevice, 0, sizeof(DISPLAY_DEVICEA)); DisplayDevice.cb = sizeof(DISPLAY_DEVICEA); - pDirect3D9->dwNumDisplayAdapters = 0; + pDirect3D9->NumDisplayAdapters = 0; D3D9_PrimaryDeviceName[0] = '\0'; AdapterIndex = 0; while (EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) == TRUE && - pDirect3D9->dwNumDisplayAdapters < DX_D3D9_MAX_NUM_ADAPTERS) + pDirect3D9->NumDisplayAdapters < DX_D3D9_MAX_NUM_ADAPTERS) { if ((DisplayDevice.StateFlags & (DISPLAY_DEVICE_DISCONNECT | DISPLAY_DEVICE_MIRRORING_DRIVER)) == 0 && (DisplayDevice.StateFlags & (DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) != 0) { - SetAdapterInfo(&pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters], &DisplayDevice); + SetAdapterInfo(&pDirect3D9->DisplayAdapters[pDirect3D9->NumDisplayAdapters], &DisplayDevice); - if (pDirect3D9->dwNumDisplayAdapters == 0) + if (pDirect3D9->NumDisplayAdapters == 0) lstrcpynA(D3D9_PrimaryDeviceName, DisplayDevice.DeviceName, sizeof(D3D9_PrimaryDeviceName)); - ++pDirect3D9->dwNumDisplayAdapters; + ++pDirect3D9->NumDisplayAdapters; break; } @@ -79,27 +94,22 @@ AdapterIndex = 0; while (EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) == TRUE && - pDirect3D9->dwNumDisplayAdapters < DX_D3D9_MAX_NUM_ADAPTERS) + pDirect3D9->NumDisplayAdapters < DX_D3D9_MAX_NUM_ADAPTERS) { if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0 && (DisplayDevice.StateFlags & (DISPLAY_DEVICE_MIRRORING_DRIVER | DISPLAY_DEVICE_PRIMARY_DEVICE)) == 0) { - SetAdapterInfo(&pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters], &DisplayDevice); - ++pDirect3D9->dwNumDisplayAdapters; + SetAdapterInfo(&pDirect3D9->DisplayAdapters[pDirect3D9->NumDisplayAdapters], &DisplayDevice); + ++pDirect3D9->NumDisplayAdapters; } ++AdapterIndex; } - /* Check if minimum DirectDraw is supported */ - if (IsDirectDrawSupported() == FALSE) - return FALSE; - - /* Test DC creation for primary display device */ - if (NULL == (hDC = CreateDCA(NULL, D3D9_PrimaryDeviceName, NULL, NULL))) - return FALSE; - - DeleteDC(hDC); + for (AdapterIndex = 0; AdapterIndex < pDirect3D9->NumDisplayAdapters; AdapterIndex++) + { + GetDirect3DAdapterInfo(&pDirect3D9->DisplayAdapters[AdapterIndex]); + } return TRUE; } Modified: trunk/reactos/dll/directx/d3d9/d3d9_helpers.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_help…
============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_helpers.c (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_helpers.c Tue Feb 5 00:33:12 2008 @@ -27,10 +27,10 @@ DWORD Type; LONG Ret; - if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, D3D9_DebugRegPath, 0, KEY_QUERY_VALUE, &hKey)) + if (ERROR_SUCCESS != RegOpenKeyExA(HKEY_LOCAL_MACHINE, D3D9_DebugRegPath, 0, KEY_QUERY_VALUE, &hKey)) return FALSE; - Ret = RegQueryValueEx(hKey, ValueName, 0, &Type, DataBuffer, DataBufferSize); + Ret = RegQueryValueExA(hKey, ValueName, 0, &Type, DataBuffer, DataBufferSize); RegCloseKey(hKey); Modified: trunk/reactos/dll/directx/d3d9/d3d9_helpers.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_help…
============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_helpers.h (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_helpers.h Tue Feb 5 00:33:12 2008 @@ -10,6 +10,9 @@ #include "d3d9_common.h" #include "d3d9_private.h" + +#define LOCK_D3D9() EnterCriticalSection(&This->d3d9_cs); +#define UNLOCK_D3D9() LeaveCriticalSection(&This->d3d9_cs); /* Convert a IDirect3D9 pointer safely to the internal implementation struct */ LPDIRECT3D9_INT impl_from_IDirect3D9(LPDIRECT3D9 iface); Modified: trunk/reactos/dll/directx/d3d9/d3d9_impl.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_impl…
============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_impl.c (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_impl.c Tue Feb 5 00:33:12 2008 @@ -8,8 +8,9 @@ #include "d3d9_common.h" #include <d3d9.h> +#include <debug.h> #include "d3d9_helpers.h" -#include <debug.h> +#include "adapter.h" /* IDirect3D9: IUnknown implementation */ static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface, REFIID riid, LPVOID* ppvObject) @@ -59,17 +60,93 @@ return D3D_OK; } +/*++ +* @name IDirect3D9::GetAdapterCount +* @implemented +* +* The function IDirect3D9Impl_GetAdapterCount returns the number of adapters +* +* @param LPDIRECT3D iface +* Pointer to the IDirect3D object returned from Direct3DCreate9() +* +* @return +* The number of display adapters on the system when Direct3DCreate9() was called. +* +*/ static UINT WINAPI IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface) { - UNIMPLEMENTED - - return D3D_OK; -} - -static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface, UINT Adapter, DWORD Flags, + UINT NumDisplayAdapters; + + LPDIRECT3D9_INT This = impl_from_IDirect3D9(iface); + LOCK_D3D9(); + + NumDisplayAdapters = This->NumDisplayAdapters; + + UNLOCK_D3D9(); + return NumDisplayAdapters; +} + +/*++ +* @name IDirect3D9::GetAdapterIdentifier +* @implemented +* +* The function IDirect3D9Impl_GetAdapterIdentifier gathers information about +* a specified display adapter and fills the pIdentifier argument with the available information. +* +* @param LPDIRECT3D iface +* Pointer to the IDirect3D object returned from Direct3DCreate9() +* +* @param UINT Adapter +* Adapter index to get information about. D3DADAPTER_DEFAULT is the primary display. +* The maximum value for this is the value returned by IDirect3D::GetAdapterCount(). +* +* @param DWORD Flags +* Ignored at the moment, but the only valid flag is D3DENUM_WHQL_LEVEL +* +* @param D3DADAPTER_IDENTIFIER9* pIdentifier +* Pointer to a D3DADAPTER_IDENTIFIER9 structure to be filled with the available information +* about the display adapter. +* +* @return +* If the method successfully fills the pIdentified structure, the return value is D3D_OK. +* If Adapter is out of range, Flags is invalid or pIdentifier is a bad pointer, the return value +* will be D3DERR_INVALIDCALL. +* +*/ +HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) { - UNIMPLEMENTED + LPDIRECT3D9_INT This = impl_from_IDirect3D9(iface); + LOCK_D3D9(); + + if (Adapter >= This->NumDisplayAdapters) + { + DPRINT1("Invalid Adapter number specified"); + UNLOCK_D3D9(); + return D3DERR_INVALIDCALL; + } + + if (Flags & ~D3DENUM_WHQL_LEVEL) + { + DPRINT1("Invalid Flags specified"); + UNLOCK_D3D9(); + return D3DERR_INVALIDCALL; + } + + if (IsBadWritePtr(pIdentifier, sizeof(D3DADAPTER_IDENTIFIER9))) + { + UNLOCK_D3D9(); + return D3DERR_INVALIDCALL; + } + + memset(pIdentifier, 0, sizeof(D3DADAPTER_IDENTIFIER9)); + + if (FALSE == GetAdapterInfo(This->DisplayAdapters[Adapter].szDeviceName, pIdentifier)) + { + DPRINT1("Internal error: Couldn't get the adapter info for device (%d): %s", Adapter, This->DisplayAdapters[Adapter].szDeviceName); + UNLOCK_D3D9(); + return D3DERR_INVALIDCALL; + } return D3D_OK; } @@ -150,7 +227,7 @@ { UNIMPLEMENTED - return D3D_OK; + return NULL; } static HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, @@ -163,7 +240,7 @@ return D3D_OK; } -const IDirect3D9Vtbl Direct3D9_Vtbl = +IDirect3D9Vtbl Direct3D9_Vtbl = { /* IUnknown */ IDirect3D9Impl_QueryInterface, Modified: trunk/reactos/dll/directx/d3d9/d3d9_private.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_priv…
============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_private.h (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_private.h Tue Feb 5 00:33:12 2008 @@ -26,7 +26,7 @@ /* 0x0130 */ DWORD unknown000007; /* 0x0134 */ DWORD unknown000008; /* 0x0138 */ DWORD unknown000009; -/* 0x013c */ DWORD unknown000010; +/* 0x013c */ DWORD unknown000010; /* D3D9_DRIVERCAPS? */ /* 0x0140 */ DWORD unknown000011; /* 0x0144 */ DWORD unknown000012; /* 0x0148 */ DWORD unknown000013; @@ -126,13 +126,13 @@ typedef struct _tagDIRECT3D9_INT_ { -/* 0x0000 */ const struct IDirect3D9Vtbl *lpVtbl; /* LPDIRECTD3D9 functoions table */ +/* 0x0000 */ struct IDirect3D9Vtbl *lpVtbl; /* LPDIRECTD3D9 functoions table */ /* 0x0004 */ CRITICAL_SECTION d3d9_cs; /* 0x001c */ DWORD unknown000007; /* 0x00000001 */ /* 0x0020 */ DWORD dwProcessId; /* 0x0024 */ struct _tagDIRECT3D9_INT_ *lpInt; /* 0x0028 */ LONG dwRefCnt; /* Increases and decreases by AddRef() and Release() */ -/* 0x002c */ DWORD dwNumDisplayAdapters; +/* 0x002c */ UINT NumDisplayAdapters; /* 0x0030 */ Direct3D9DisplayAdapterInfo_INT DisplayAdapters[DX_D3D9_MAX_NUM_ADAPTERS]; /* 0x2100 */ DWORD unknown002112; /* 0x2104 */ DWORD unknown002113; @@ -2543,7 +2543,7 @@ /* 0x4698 */ DWORD unknown004518; /* 0x469c */ DWORD unknown004519; /* 0x46a0 */ DWORD unknown004520; -/* 0x46a4 */ DWORD unknown004521; +/* 0x46a4 */ DWORD unknown004521; // Software only /* 0x46a8 */ DWORD unknown004522; /* 0x46ac */ DWORD unknown004523; /* 0x46b0 */ DWORD unknown004524;
16 years, 10 months
1
0
0
0
[janderwald] 32121: - insert new entry when required - check for null
by janderwald@svn.reactos.org
Author: janderwald Date: Tue Feb 5 00:24:09 2008 New Revision: 32121 URL:
http://svn.reactos.org/svn/reactos?rev=32121&view=rev
Log: - insert new entry when required - check for null Modified: trunk/reactos/subsystems/win32/csrss/api/alias.c Modified: trunk/reactos/subsystems/win32/csrss/api/alias.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/api…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/api/alias.c (original) +++ trunk/reactos/subsystems/win32/csrss/api/alias.c Tue Feb 5 00:24:09 2008 @@ -106,6 +106,9 @@ PALIAS_ENTRY IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName) { + if (Header == NULL) + return NULL; + PALIAS_ENTRY RootHeader = Header->Data; while(RootHeader) { @@ -303,7 +306,7 @@ } Header = IntFindAliasHeader(RootHeader, Request->Data.AddConsoleAlias.lpExeName); - if (!Header) + if (!Header && Request->Data.AddConsoleAlias.lpTarget != NULL) { Header = IntCreateAliasHeader(Request->Data.AddConsoleAlias.lpExeName); if (!Header) @@ -311,6 +314,7 @@ Request->Status = STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES; } + IntInsertAliasHeader(&RootHeader, Header); } if (Request->Data.AddConsoleAlias.lpTarget == NULL) // delete the entry
16 years, 10 months
1
0
0
0
[fireball] 32120: - Build FreeLdr the same way other modules are built, by using gcc -Wl. - This allows us to get rid of the /math directory and use -lgcc instead. - Get rid of -ffreestanding, -fno-builtin and -O2. The former are not needed anymore since we're properly building a "freestanding" image anyway, just like the kernel. The latter is removed since optimization flags come from the project settings. - Update code to fix warnings caused since we've removed -ffreestanding. GCC now warns ab
by fireball@svn.reactos.org
Author: fireball Date: Mon Feb 4 23:27:43 2008 New Revision: 32120 URL:
http://svn.reactos.org/svn/reactos?rev=32120&view=rev
Log: - Build FreeLdr the same way other modules are built, by using gcc -Wl. - This allows us to get rid of the /math directory and use -lgcc instead. - Get rid of -ffreestanding, -fno-builtin and -O2. The former are not needed anymore since we're properly building a "freestanding" image anyway, just like the kernel. The latter is removed since optimization flags come from the project settings. - Update code to fix warnings caused since we've removed -ffreestanding. GCC now warns about printf, sprintf and other C calls (including a change from %wZ to %S in winldr.c's sprintf calls). - Don't use printf anymore -- rename freeldr's implementation to TuiPrintf. Just like in the kernel, you can't use printf in freeldr (since it's not running in a standard/full CRT environment). - 124kb saved! Removed: trunk/reactos/boot/freeldr/freeldr/math/ Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c trunk/reactos/boot/freeldr/freeldr/custom.c trunk/reactos/boot/freeldr/freeldr/disk/disk.c trunk/reactos/boot/freeldr/freeldr/disk/partition.c trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild trunk/reactos/boot/freeldr/freeldr/include/freeldr.h trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h trunk/reactos/boot/freeldr/freeldr/rtl/bget.c trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild trunk/reactos/boot/freeldr/freeldr/ui/tui.c trunk/reactos/boot/freeldr/freeldr/windows/winldr.c trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c Mon Feb 4 23:27:43 2008 @@ -579,7 +579,7 @@ MmHeapFree(PartialResourceList); /* Set 'Identifier' value */ - sprintf(Identifier, "FLOPPY%u", FloppyNumber + 1); + sprintf(Identifier, "FLOPPY%ld", FloppyNumber + 1); FldrSetIdentifier(PeripheralKey, Identifier); } } @@ -1218,7 +1218,7 @@ MmHeapFree(PartialResourceList); /* Set 'Identifier' value */ - sprintf(Buffer, "COM%u", i + 1); + sprintf(Buffer, "COM%ld", i + 1); FldrSetIdentifier(ControllerKey, Buffer); DbgPrint((DPRINT_HWDETECT, "Created value: Identifier %s\n", @@ -1323,7 +1323,7 @@ MmHeapFree(PartialResourceList); /* Set 'Identifier' value */ - sprintf(Buffer, "PARALLEL%u", i + 1); + sprintf(Buffer, "PARALLEL%ld", i + 1); FldrSetIdentifier(ControllerKey, Buffer); DbgPrint((DPRINT_HWDETECT, "Created value: Identifier %s\n", Modified: trunk/reactos/boot/freeldr/freeldr/custom.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/custo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/custom.c (original) +++ trunk/reactos/boot/freeldr/freeldr/custom.c Mon Feb 4 23:27:43 2008 @@ -91,7 +91,7 @@ // Generate a unique section name MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomBootDisk%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second); + sprintf(SectionName, "CustomBootDisk%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -140,7 +140,7 @@ // Generate a unique section name MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomBootPartition%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second); + sprintf(SectionName, "CustomBootPartition%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -202,7 +202,7 @@ // Generate a unique section name MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomBootSectorFile%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second); + sprintf(SectionName, "CustomBootSectorFile%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -278,7 +278,7 @@ // Generate a unique section name MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomReactOS%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second); + sprintf(SectionName, "CustomReactOS%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -357,7 +357,7 @@ // Generate a unique section name MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomLinux%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second); + sprintf(SectionName, "CustomLinux%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) Modified: trunk/reactos/boot/freeldr/freeldr/disk/disk.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/disk/disk.c (original) +++ trunk/reactos/boot/freeldr/freeldr/disk/disk.c Mon Feb 4 23:27:43 2008 @@ -41,7 +41,7 @@ if (bReportError == FALSE) return; - sprintf(ErrorCodeString, "%s\n\nError Code: 0x%x\nError: %s", ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode)); + sprintf(ErrorCodeString, "%s\n\nError Code: 0x%lx\nError: %s", ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode)); DbgPrint((DPRINT_DISK, "%s\n", ErrorCodeString)); Modified: trunk/reactos/boot/freeldr/freeldr/disk/partition.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/disk/partition.c (original) +++ trunk/reactos/boot/freeldr/freeldr/disk/partition.c Mon Feb 4 23:27:43 2008 @@ -230,7 +230,7 @@ // Check the partition table magic value if (BootRecord->MasterBootRecordMagic != 0xaa55) { - sprintf(ErrMsg, "Invalid partition table magic 0x%x found on drive 0x%x", + sprintf(ErrMsg, "Invalid partition table magic 0x%x found on drive 0x%lx", BootRecord->MasterBootRecordMagic, DriveNumber); DiskError(ErrMsg, 0); return FALSE; Modified: trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild Mon Feb 4 23:27:43 2008 @@ -13,6 +13,9 @@ <library>cmlib</library> <library>rtl</library> <library>libcntpr</library> + <linkerflag>-nostartfiles</linkerflag> + <linkerflag>-nostdlib</linkerflag> + <linkerflag>-lgcc</linkerflag> </module> </if> <if property="ARCH" value="powerpc"> Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild Mon Feb 4 23:27:43 2008 @@ -8,11 +8,8 @@ <include base="freeldr_base">cache</include> <include base="ntoskrnl">include</include> <define name="_NTHAL_" /> - <compilerflag>-ffreestanding</compilerflag> - <compilerflag>-fno-builtin</compilerflag> <compilerflag>-fno-inline</compilerflag> <compilerflag>-fno-zero-initialized-in-bss</compilerflag> - <compilerflag>-Os</compilerflag> <file>_alloca.S</file> <file>archmach.c</file> <file>hardware.c</file> Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild Mon Feb 4 23:27:43 2008 @@ -7,11 +7,8 @@ <include base="ntoskrnl">include</include> <define name="_NTHAL_" /> <define name="_NTSYSTEM_" /> - <compilerflag>-ffreestanding</compilerflag> - <compilerflag>-fno-builtin</compilerflag> <compilerflag>-fno-inline</compilerflag> <compilerflag>-fno-zero-initialized-in-bss</compilerflag> - <compilerflag>-Os</compilerflag> <directory name="cache"> <file>blocklist.c</file> <file>cache.c</file> @@ -35,9 +32,6 @@ <file>ini_init.c</file> <file>inifile.c</file> <file>parse.c</file> - </directory> - <directory name="math"> - <file>libgcc2.c</file> </directory> <directory name="mm"> <file>meminit.c</file> Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild Mon Feb 4 23:27:43 2008 @@ -4,11 +4,8 @@ <include base="freeldr_base64k">include</include> <include base="ntoskrnl">include</include> <define name="_NTHAL_" /> - <compilerflag>-ffreestanding</compilerflag> - <compilerflag>-fno-builtin</compilerflag> <compilerflag>-fno-inline</compilerflag> <compilerflag>-fno-zero-initialized-in-bss</compilerflag> - <compilerflag>-Os</compilerflag> <directory name="arch"> <if property="ARCH" value="i386"> <directory name="i386"> Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild Mon Feb 4 23:27:43 2008 @@ -4,11 +4,8 @@ <include base="freeldr_main">include</include> <include base="ntoskrnl">include</include> <define name="_NTHAL_" /> - <compilerflag>-ffreestanding</compilerflag> - <compilerflag>-fno-builtin</compilerflag> <compilerflag>-fno-inline</compilerflag> <compilerflag>-fno-zero-initialized-in-bss</compilerflag> - <compilerflag>-Os</compilerflag> <file>bootmgr.c</file> <file>drivemap.c</file> <file>miscboot.c</file> Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild Mon Feb 4 23:27:43 2008 @@ -3,8 +3,6 @@ <module name="freeldr_startup" type="objectlibrary"> <include base="freeldr_startup">include</include> <include base="ntoskrnl">include</include> - <compilerflag>-ffreestanding</compilerflag> - <compilerflag>-fno-builtin</compilerflag> <compilerflag>-fno-inline</compilerflag> <compilerflag>-fno-zero-initialized-in-bss</compilerflag> <directory name="arch"> Modified: trunk/reactos/boot/freeldr/freeldr/include/freeldr.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/freeldr.h (original) +++ trunk/reactos/boot/freeldr/freeldr/include/freeldr.h Mon Feb 4 23:27:43 2008 @@ -26,6 +26,7 @@ #include <stdio.h> #include <ctype.h> #define NTOSAPI +#define printf TuiPrintf #include <ntddk.h> #include <arc/arc.h> #include <ketypes.h> Modified: trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h (original) +++ trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h Mon Feb 4 23:27:43 2008 @@ -46,7 +46,7 @@ VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length); - +int TuiPrintf(const char *format, ... ); UCHAR TuiTextToColor(PCSTR ColorText); // Converts the text color into it's equivalent color value UCHAR TuiTextToFillStyle(PCSTR FillStyleText); // Converts the text fill into it's equivalent fill value Modified: trunk/reactos/boot/freeldr/freeldr/rtl/bget.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/rtl/b…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/rtl/bget.c (original) +++ trunk/reactos/boot/freeldr/freeldr/rtl/bget.c Mon Feb 4 23:27:43 2008 @@ -445,6 +445,9 @@ #include <stdio.h> +int TuiPrintf(const char *format, ... ); +#define printf TuiPrintf + #ifdef lint #define NDEBUG /* Exits in asserts confuse lint */ /* LINTLIBRARY */ /* Don't complain about def, no ref */ Modified: trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/setup…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild (original) +++ trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild Mon Feb 4 23:27:43 2008 @@ -11,4 +11,7 @@ <library>cmlib</library> <library>rtl</library> <library>libcntpr</library> + <linkerflag>-nostartfiles</linkerflag> + <linkerflag>-nostdlib</linkerflag> + <linkerflag>-lgcc</linkerflag> </module> Modified: trunk/reactos/boot/freeldr/freeldr/ui/tui.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/tu…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/ui/tui.c (original) +++ trunk/reactos/boot/freeldr/freeldr/ui/tui.c Mon Feb 4 23:27:43 2008 @@ -25,7 +25,7 @@ * printf() - prints formatted text to stdout * originally from GRUB */ -int printf(const char *format, ... ) +int TuiPrintf(const char *format, ... ) { va_list ap; va_start(ap,format); Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c Mon Feb 4 23:27:43 2008 @@ -259,7 +259,7 @@ PVOID DriverBase; // Separate the path to file name and directory path - sprintf(DriverPath, "%wZ", FilePath); + sprintf(DriverPath, "%S", FilePath->Buffer); DriverNamePos = strrchr(DriverPath, '\\'); if (DriverNamePos != NULL) { @@ -282,7 +282,7 @@ } // It's not loaded, we have to load it - sprintf(FullPath,"%s%wZ", BootPath, FilePath); + sprintf(FullPath,"%s%S", BootPath, FilePath->Buffer); Status = WinLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase); if (!Status) return FALSE; @@ -586,3 +586,4 @@ } } + Modified: trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/backend/mingw…
============================================================================== --- trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp (original) +++ trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp Mon Feb 4 23:27:43 2008 @@ -3547,11 +3547,11 @@ fprintf ( fMakefile, "\t$(ECHO_LD)\n" ); fprintf ( fMakefile, - "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n", - GetLinkerMacro ().c_str (), + "\t${gcc} -Wl,--subsystem,native -Wl,-Ttext,0x8000 -o %s %s %s %s\n", backend->GetFullName ( junk_tmp ).c_str (), objectsMacro.c_str (), - linkDepsMacro.c_str () ); + linkDepsMacro.c_str (), + GetLinkerMacro ().c_str ()); fprintf ( fMakefile, "\t${objcopy} -O binary %s $@\n", backend->GetFullName ( junk_tmp ).c_str () );
16 years, 10 months
1
0
0
0
[janderwald] 32119: - rename member
by janderwald@svn.reactos.org
Author: janderwald Date: Mon Feb 4 21:58:46 2008 New Revision: 32119 URL:
http://svn.reactos.org/svn/reactos?rev=32119&view=rev
Log: - rename member Modified: trunk/reactos/include/reactos/subsys/csrss/csrss.h Modified: trunk/reactos/include/reactos/subsys/csrss/csrss.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/subsys/csr…
============================================================================== --- trunk/reactos/include/reactos/subsys/csrss/csrss.h (original) +++ trunk/reactos/include/reactos/subsys/csrss/csrss.h Mon Feb 4 21:58:46 2008 @@ -435,7 +435,7 @@ DWORD BytesWritten; DWORD AliasBufferLength; LPWSTR AliasBuffer; -} CSRSS_GET_ALL_CONSOLE_ALIAS, *PCSRSS_GET_ALL_CONSOLE_ALIAS; +} CSRSS_GET_ALL_CONSOLE_ALIASES, *PCSRSS_GET_ALL_CONSOLE_ALIAS; typedef struct { @@ -529,7 +529,7 @@ #define START_SCREEN_SAVER (0x37) #define ADD_CONSOLE_ALIAS (0x38) #define GET_CONSOLE_ALIAS (0x39) -#define GET_ALL_CONSOLE_ALIAS (0x3A) +#define GET_ALL_CONSOLE_ALIASES (0x3A) #define GET_ALL_CONSOLE_ALIASES_LENGTH (0x3B) #define GET_CONSOLE_ALIASES_EXES (0x3C) #define GET_CONSOLE_ALIASES_EXES_LENGTH (0x3D) @@ -600,7 +600,7 @@ CSRSS_GET_PROCESS_LIST GetProcessListRequest; CSRSS_ADD_CONSOLE_ALIAS AddConsoleAlias; CSRSS_GET_CONSOLE_ALIAS GetConsoleAlias; - CSRSS_GET_ALL_CONSOLE_ALIAS GetAllConsoleAlias; + CSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAlias; CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH GetAllConsoleAliasesLength; CSRSS_GET_CONSOLE_ALIASES_EXES GetConsoleAliasesExes; CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH GetConsoleAliasesExesLength;
16 years, 10 months
1
0
0
0
[janderwald] 32118: - call csrss for Console alias related functions
by janderwald@svn.reactos.org
Author: janderwald Date: Mon Feb 4 21:58:17 2008 New Revision: 32118 URL:
http://svn.reactos.org/svn/reactos?rev=32118&view=rev
Log: - call csrss for Console alias related functions Modified: trunk/reactos/dll/win32/kernel32/misc/console.c Modified: trunk/reactos/dll/win32/kernel32/misc/console.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/co…
============================================================================== --- trunk/reactos/dll/win32/kernel32/misc/console.c (original) +++ trunk/reactos/dll/win32/kernel32/misc/console.c Mon Feb 4 21:58:17 2008 @@ -27,14 +27,10 @@ DWORD dwUsed; } ALIAS, *LPALIAS; -static LPALIAS lpFirst = NULL; -static LPALIAS lpLast = NULL; - extern BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event); extern __declspec(noreturn) VOID CALLBACK ConsoleControlDispatcher(DWORD CodeAndFlag); extern RTL_CRITICAL_SECTION ConsoleLock; extern BOOL WINAPI IsDebuggerPresent(VOID); -static VOID partstrlwr (LPWSTR str); /* GLOBALS *******************************************************************/ @@ -43,19 +39,6 @@ static PHANDLER_ROUTINE* CtrlHandlers = NULL; static ULONG NrCtrlHandlers = 0; static WCHAR InputExeName[MAX_PATH + 1] = L""; - -/* module internal functions */ -/* strlwr only for first word in string */ -static VOID -partstrlwr (LPWSTR str) -{ - LPWSTR c = str; - while (*c && !iswspace (*c) && *c != L'=') - { - *c = towlower (*c); - c++; - } -} /* Default Console Control Handler *******************************************/ @@ -206,125 +189,28 @@ LPCWSTR lpTarget, LPCWSTR lpExeName /* FIXME: currently ignored */) { - LPALIAS ptr = lpFirst; - LPALIAS prev = NULL; - LPALIAS entry = NULL; - LPWSTR s; - - if (!lpTarget) - { - /* delete */ - while (ptr) - { - if (!wcsicmp (ptr->lpName, lpSource)) - { - if (prev) - prev->next = ptr->next; - else - lpFirst = ptr->next; - RtlFreeHeap (GetProcessHeap(), 0, ptr->lpName); - RtlFreeHeap (GetProcessHeap(), 0, ptr->lpSubst); - RtlFreeHeap (GetProcessHeap(), 0, ptr); - return TRUE; - } - prev = ptr; - ptr = ptr->next; - } - } - else - { - /* add */ - while (ptr) - { - if (!wcsicmp (ptr->lpName, lpSource)) - { - s = (LPWSTR) RtlAllocateHeap (GetProcessHeap(), 0, ((wcslen (lpTarget) + 1) * sizeof(WCHAR))); - if (!s) - { - return FALSE; - } - - RtlFreeHeap (GetProcessHeap(), 0, ptr->lpSubst); - ptr->lpSubst = s; - wcscpy (ptr->lpSubst, lpTarget); - return TRUE; - } - ptr = ptr->next; - } - - ptr = (LPALIAS) RtlAllocateHeap (GetProcessHeap(), 0, sizeof(ALIAS)); - if (!ptr) - return FALSE; - - ptr->next = 0; - - ptr->lpName = (LPWSTR) RtlAllocateHeap (GetProcessHeap(), 0, ((wcslen (lpSource) + 1) * sizeof(WCHAR))); - if (!ptr->lpName) - { - RtlFreeHeap (GetProcessHeap(), 0, ptr); - return FALSE; - } - wcscpy (ptr->lpName, lpSource); - - ptr->lpSubst = (LPWSTR) RtlAllocateHeap (GetProcessHeap(), 0, ((wcslen (lpTarget) + 1) * sizeof(WCHAR))); - if (!ptr->lpSubst) - { - RtlFreeHeap (GetProcessHeap(), 0, ptr->lpName); - RtlFreeHeap (GetProcessHeap(), 0, ptr); - return FALSE; - } - wcscpy (ptr->lpSubst, lpTarget); - - /* it's necessary for recursive substitution */ - partstrlwr (ptr->lpSubst); - - ptr->dwUsed = 0; - - /* Alias table must be sorted! - * Here a little example: - * command line = "ls -c" - * If the entries are - * ls=dir - * ls -c=ls /w - * command line will be expanded to "dir -c" which is not correct. - * If the entries are sortet as - * ls -c=ls /w - * ls=dir - * it will be expanded to "dir /w" which is a valid DOS command. - */ - entry = lpFirst; - prev = 0; - while (entry) - { - if (wcsicmp (ptr->lpName, entry->lpName) > 0) - - { - if (prev) - { - prev->next = ptr; - ptr->next = entry; - } - else - { - ptr->next = entry; - lpFirst = ptr; - } - return TRUE; - } - prev = entry; - entry = entry->next; - } - - /* The new entry is the smallest (or the first) and must be - * added to the end of the list. - */ - if (!lpFirst) - lpFirst = ptr; - else - lpLast->next = ptr; - lpLast = ptr; - } - return TRUE; + CSR_API_MESSAGE Request; + ULONG CsrRequest; + NTSTATUS Status; + + CsrRequest = MAKE_CSR_API(ADD_CONSOLE_ALIAS, CSR_NATIVE); + + Request.Data.AddConsoleAlias.lpExeName = lpExeName; + Request.Data.AddConsoleAlias.lpTarget = lpTarget; + Request.Data.AddConsoleAlias.lpSource = lpSource; + + Status = CsrClientCallServer(& Request, + NULL, + CsrRequest, + sizeof(CSR_API_MESSAGE)); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + + return TRUE; } @@ -418,38 +304,36 @@ GetConsoleAliasW (LPWSTR lpSource, LPWSTR lpTargetBuffer, DWORD TargetBufferLength, - LPWSTR lpExeName) /* FIXME: currently ignored */ -{ - DWORD dwRet = 0; - - if (!lpTargetBuffer) - return 0; - - LPALIAS ptr = lpFirst; - while (ptr) - { - if (wcscmp(ptr->lpName, lpSource) == 0) - { - if (TargetBufferLength >= wcslen(ptr->lpSubst) +1) - { - wcscpy(lpTargetBuffer, ptr->lpSubst); - dwRet = wcslen(ptr->lpSubst); - break; - } - else - { - return 0; - } - } - ptr = ptr->next; - } - - return dwRet; -} - - -/* - * @unimplemented + LPWSTR lpExeName) +{ + CSR_API_MESSAGE Request; + ULONG CsrRequest; + NTSTATUS Status; + + CsrRequest = MAKE_CSR_API(GET_CONSOLE_ALIAS, CSR_NATIVE); + + Request.Data.GetConsoleAlias.lpExeName = lpExeName; + Request.Data.GetConsoleAlias.lpSource = lpSource; + Request.Data.GetConsoleAlias.TargetBuffer = lpTargetBuffer; + Request.Data.GetConsoleAlias.TargetBufferLength = TargetBufferLength; + + Status = CsrClientCallServer(& Request, + NULL, + CsrRequest, + sizeof(CSR_API_MESSAGE)); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + + return Request.Data.GetConsoleAlias.BytesWritten / sizeof(WCHAR); +} + + +/* + * @implemented */ DWORD STDCALL GetConsoleAliasA (LPSTR lpSource, @@ -457,59 +341,130 @@ DWORD TargetBufferLength, LPSTR lpExeName) { - DPRINT1("GetConsoleAliasA(0x%p, 0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", lpSource, lpTargetBuffer, TargetBufferLength, lpExeName); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} - - -/* - * @unimplemented + LPWSTR lpwSource; + LPWSTR lpwExeName; + LPWSTR lpwTargetBuffer; + UINT dwSourceSize; + UINT dwExeNameSize; + UINT dwResult; + + dwSourceSize = (strlen(lpSource)+1) * sizeof(WCHAR); + lpwSource = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSourceSize); + MultiByteToWideChar(CP_ACP, 0, lpSource, -1, lpwSource, dwSourceSize); + + dwExeNameSize = (strlen(lpExeName)+1) * sizeof(WCHAR); + lpwExeName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwExeNameSize); + MultiByteToWideChar(CP_ACP, 0, lpExeName, -1, lpwExeName, dwExeNameSize); + + lpwTargetBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, TargetBufferLength * sizeof(WCHAR)); + + dwResult = GetConsoleAliasW(lpwSource, lpwTargetBuffer, TargetBufferLength, lpwExeName); + + HeapFree(GetProcessHeap(), 0, lpwSource); + HeapFree(GetProcessHeap(), 0, lpwExeName); + + if (dwResult) + dwResult = WideCharToMultiByte(CP_ACP, 0, lpwTargetBuffer, dwResult, lpTargetBuffer, TargetBufferLength, NULL, NULL); + + HeapFree(GetProcessHeap(), 0, lpwTargetBuffer); + + return dwResult; +} + + +/* + * @implemented */ DWORD STDCALL GetConsoleAliasExesW (LPWSTR lpExeNameBuffer, DWORD ExeNameBufferLength) { - DPRINT1("GetConsoleAliasExesW(0x%p, 0x%x) UNIMPLEMENTED!\n", lpExeNameBuffer, ExeNameBufferLength); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} - - -/* - * @unimplemented + CSR_API_MESSAGE Request; + ULONG CsrRequest; + NTSTATUS Status; + + CsrRequest = MAKE_CSR_API(GET_CONSOLE_ALIASES_EXES, CSR_NATIVE); + Request.Data.GetConsoleAliasesExes.ExeNames = lpExeNameBuffer; + Request.Data.GetConsoleAliasesExes.Length = ExeNameBufferLength; + + Status = CsrClientCallServer(& Request, + NULL, + CsrRequest, + sizeof(CSR_API_MESSAGE)); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + + return Request.Data.GetConsoleAliasesExes.BytesWritten / sizeof(WCHAR); +} + + +/* + * @implemented */ DWORD STDCALL GetConsoleAliasExesA (LPSTR lpExeNameBuffer, DWORD ExeNameBufferLength) { - DPRINT1("GetConsoleAliasExesA(0x%p, 0x%x) UNIMPLEMENTED!\n", lpExeNameBuffer, ExeNameBufferLength); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} - - -/* - * @unimplemented + LPWSTR lpwExeNameBuffer; + DWORD dwResult; + + lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength * sizeof(WCHAR)); + + dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength); + + if (dwResult) + dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult, lpExeNameBuffer, ExeNameBufferLength, NULL, NULL); + + HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer); + return dwResult; +} + +/* + * @implemented + */ +DWORD STDCALL +GetConsoleAliasExesLengthW (VOID) +{ + CSR_API_MESSAGE Request; + ULONG CsrRequest; + NTSTATUS Status; + + CsrRequest = MAKE_CSR_API(GET_CONSOLE_ALIASES_EXES_LENGTH, CSR_NATIVE); + Request.Data.GetConsoleAliasesExesLength.Length = 0; + + + Status = CsrClientCallServer(& Request, + NULL, + CsrRequest, + sizeof(CSR_API_MESSAGE)); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + + return Request.Data.GetConsoleAliasesExesLength.Length; +} + +/* + * @implemented */ DWORD STDCALL GetConsoleAliasExesLengthA (VOID) { - DPRINT1("GetConsoleAliasExesLengthA() UNIMPLEMENTED!\n"); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} - - -/* - * @unimplemented - */ -DWORD STDCALL -GetConsoleAliasExesLengthW (VOID) -{ - DPRINT1("GetConsoleAliasExesLengthW() UNIMPLEMENTED!\n"); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; + DWORD dwLength; + + dwLength = GetConsoleAliasExesLengthW(); + + if (dwLength) + dwLength /= sizeof(WCHAR); + + return dwLength; } @@ -519,47 +474,64 @@ DWORD STDCALL GetConsoleAliasesW (LPWSTR AliasBuffer, DWORD AliasBufferLength, - LPWSTR ExeName) /* FIXME: currently ignored */ -{ - DWORD len; - WCHAR Buffer[MAX_PATH]; - LPWSTR AliasPtr; - - if (!AliasBuffer) - return 0; - - AliasPtr = AliasBuffer; - len = GetConsoleAliasesLengthW (ExeName); - if (len > AliasBufferLength) - return 0; - - LPALIAS ptr = lpFirst; - while (ptr) - { - swprintf(Buffer, L"%s=%s" , ptr->lpName, ptr->lpSubst); - wcscpy(AliasBuffer, Buffer); - AliasBuffer += wcslen(Buffer) + 1; - ptr = ptr->next; - } - - return (INT) (AliasBuffer - AliasPtr); -} - - -/* - * @unimplemented + LPWSTR ExeName) +{ + CSR_API_MESSAGE Request; + ULONG CsrRequest; + NTSTATUS Status; + DWORD dwLength; + + dwLength = GetConsoleAliasesLengthW(ExeName); + if (!dwLength || dwLength > AliasBufferLength) + return FALSE; + + CsrRequest = MAKE_CSR_API(GET_ALL_CONSOLE_ALIASES, CSR_NATIVE); + Request.Data.GetAllConsoleAlias.AliasBuffer = AliasBuffer; + Request.Data.GetAllConsoleAlias.AliasBufferLength = AliasBufferLength; + Request.Data.GetAllConsoleAlias.lpExeName = ExeName; + + Status = CsrClientCallServer(& Request, + NULL, + CsrRequest, + sizeof(CSR_API_MESSAGE)); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + + return Request.Data.GetAllConsoleAlias.BytesWritten / sizeof(WCHAR); +} + + +/* + * @implemented */ DWORD STDCALL GetConsoleAliasesA (LPSTR AliasBuffer, DWORD AliasBufferLength, LPSTR ExeName) - /* - * Undocumented - */ -{ - DPRINT1("GetConsoleAliasesA(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", AliasBuffer, AliasBufferLength, ExeName); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; +{ + DWORD dwRetVal = 0; + LPWSTR lpwExeName = NULL; + LPWSTR lpwAliasBuffer; + + if (ExeName) + BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*) &lpwExeName); + + lpwAliasBuffer = HeapAlloc(GetProcessHeap(), 0, AliasBufferLength * sizeof(WCHAR)); + + dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength, lpwExeName); + + if (lpwExeName) + RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpwExeName); + + if (dwRetVal) + dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal, AliasBuffer, AliasBufferLength, NULL, NULL); + + HeapFree(GetProcessHeap(), 0, lpwAliasBuffer); + return dwRetVal; } @@ -567,18 +539,28 @@ * @implemented */ DWORD STDCALL -GetConsoleAliasesLengthW (LPWSTR lpExeName /* FIXME: currently ignored */) -{ - DWORD len = 0; - LPALIAS ptr = lpFirst; - while (ptr) - { - len += wcslen(ptr->lpName) * sizeof(WCHAR); - len += wcslen(ptr->lpSubst) * sizeof(WCHAR); - len += 2 * sizeof(WCHAR); /* '=' + '\0' */ - ptr = ptr->next; - } - return len; +GetConsoleAliasesLengthW (LPWSTR lpExeName) +{ + CSR_API_MESSAGE Request; + ULONG CsrRequest; + NTSTATUS Status; + + CsrRequest = MAKE_CSR_API(GET_ALL_CONSOLE_ALIASES_LENGTH, CSR_NATIVE); + Request.Data.GetAllConsoleAliasesLength.lpExeName = lpExeName; + Request.Data.GetAllConsoleAliasesLength.Length = 0; + + Status = CsrClientCallServer(&Request, + NULL, + CsrRequest, + sizeof(CSR_API_MESSAGE)); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + + return Request.Data.GetAllConsoleAliasesLength.Length; } @@ -594,7 +576,9 @@ if (lpExeName) BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW); - dwRetVal = (GetConsoleAliasesLengthW(lpExeNameW) / sizeof(WCHAR)); + dwRetVal = GetConsoleAliasesLengthW(lpExeNameW); + if (dwRetVal) + dwRetVal /= sizeof(WCHAR); /* Clean up */ if (lpExeNameW)
16 years, 10 months
1
0
0
0
[janderwald] 32117: - implement GetConsoleAlias* AddConsoleAlias function in csrss -
by janderwald@svn.reactos.org
Author: janderwald Date: Mon Feb 4 21:57:19 2008 New Revision: 32117 URL:
http://svn.reactos.org/svn/reactos?rev=32117&view=rev
Log: - implement GetConsoleAlias* AddConsoleAlias function in csrss - Added: trunk/reactos/subsystems/win32/csrss/api/alias.c (with props) Modified: trunk/reactos/subsystems/win32/csrss/csrss.rbuild trunk/reactos/subsystems/win32/csrss/include/api.h trunk/reactos/subsystems/win32/csrss/init.c Added: trunk/reactos/subsystems/win32/csrss/api/alias.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/api…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/api/alias.c (added) +++ trunk/reactos/subsystems/win32/csrss/api/alias.c Mon Feb 4 21:57:19 2008 @@ -1,0 +1,475 @@ +/* $Id: init.c 31400 2007-12-22 17:18:32Z fireball $ + * PROJECT: ReactOS CSRSS + * LICENSE: GPL - See COPYING in the top level directory + * FILE: subsystems/win32/csrss/api/alias.c + * PURPOSE: CSRSS alias support functions + * COPYRIGHT: Christoph Wittich + * Johannes Anderwald + * + */ + + +/* INCLUDES ******************************************************************/ + +#include <csrss.h> + +#define NDEBUG +#include <debug.h> + +typedef struct tagALIAS_ENTRY +{ + LPCWSTR lpSource; + LPCWSTR lpTarget; + struct tagALIAS_ENTRY * Next; +}ALIAS_ENTRY, *PALIAS_ENTRY; + + +typedef struct tagALIAS_HEADER +{ + LPCWSTR lpExeName; + PALIAS_ENTRY Data; + struct tagALIAS_HEADER * Next; + +}ALIAS_HEADER, *PALIAS_HEADER; + +static PALIAS_HEADER RootHeader = NULL; + +static +PALIAS_HEADER +IntFindAliasHeader(PALIAS_HEADER RootHeader, LPCWSTR lpExeName) +{ + while(RootHeader) + { + INT diff = _wcsicmp(RootHeader->lpExeName, lpExeName); + if (!diff) + return RootHeader; + + if (diff < 0) + break; + + RootHeader = RootHeader->Next; + } + return NULL; +} + +PALIAS_HEADER +IntCreateAliasHeader(LPCWSTR lpExeName) +{ + PALIAS_HEADER Entry; + UINT dwLength = wcslen(lpExeName) + 1; + + Entry = RtlAllocateHeap(CsrssApiHeap, 0, sizeof(ALIAS_HEADER) + sizeof(WCHAR) * dwLength); + if (!Entry) + return Entry; + + Entry->lpExeName = (LPCWSTR)(Entry + sizeof(ALIAS_HEADER)); + wcscpy((WCHAR*)Entry->lpExeName, lpExeName); + Entry->Next = NULL; + return Entry; +} + +VOID +IntInsertAliasHeader(PALIAS_HEADER * RootHeader, PALIAS_HEADER NewHeader) +{ + PALIAS_HEADER CurrentHeader; + PALIAS_HEADER LastHeader = NULL; + + if (*RootHeader == 0) + { + *RootHeader = NewHeader; + return; + } + + CurrentHeader = *RootHeader; + + while(CurrentHeader) + { + INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName); + if (Diff < 0) + { + if (!LastHeader) + *RootHeader = NewHeader; + else + LastHeader->Next = NewHeader; + + NewHeader->Next = CurrentHeader; + return; + } + LastHeader = CurrentHeader; + CurrentHeader = CurrentHeader->Next; + } + + LastHeader->Next = NewHeader; + NewHeader->Next = NULL; +} + +PALIAS_ENTRY +IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName) +{ + PALIAS_ENTRY RootHeader = Header->Data; + while(RootHeader) + { + INT diff = _wcsicmp(RootHeader->lpSource, lpSrcName); + if (!diff) + return RootHeader; + + if (diff < 0) + break; + + RootHeader = RootHeader->Next; + } + return NULL; +} + + +VOID +IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry) +{ + PALIAS_ENTRY CurrentEntry; + PALIAS_ENTRY LastEntry = NULL; + + CurrentEntry = Header->Data; + + if (!CurrentEntry) + { + Header->Data = NewEntry; + return; + } + + while(CurrentEntry) + { + INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource); + if (Diff < 0) + { + if (!LastEntry) + Header->Data = NewEntry; + else + LastEntry->Next = NewEntry; + NewEntry->Next = CurrentEntry; + return; + } + LastEntry = CurrentEntry; + CurrentEntry = CurrentEntry->Next; + } + + LastEntry->Next = NewEntry; + NewEntry->Next = NULL; +} + +PALIAS_ENTRY +IntCreateAliasEntry(LPCWSTR lpSource, LPCWSTR lpTarget) +{ + UINT dwSource; + UINT dwTarget; + PALIAS_ENTRY Entry; + + dwSource = wcslen(lpSource) + 1; + dwTarget = wcslen(lpTarget) + 1; + + Entry = RtlAllocateHeap(CsrssApiHeap, 0, sizeof(ALIAS_ENTRY) + sizeof(WCHAR) * (dwSource + dwTarget)); + if (!Entry) + return Entry; + + Entry->lpSource = (LPCWSTR)(Entry + sizeof(ALIAS_ENTRY)); + wcscpy((LPWSTR)Entry->lpSource, lpSource); + Entry->lpTarget = Entry->lpSource + dwSource; + wcscpy((LPWSTR)Entry->lpTarget, lpTarget); + Entry->Next = NULL; + + return Entry; +} + +UINT +IntGetConsoleAliasesExesLength(PALIAS_HEADER RootHeader) +{ + UINT length = 0; + + while(RootHeader) + { + length += (wcslen(RootHeader->lpExeName) + 1) * sizeof(WCHAR); + } + if (length) + length++; // last entry entry is terminated with 2 zero bytes + + return length; +} + +UINT +IntGetConsoleAliasesExes(PALIAS_HEADER RootHeader, LPWSTR TargetBuffer, UINT TargetBufferSize) +{ + UINT Offset = 0; + UINT Length; + + TargetBufferSize /= sizeof(WCHAR); + while(RootHeader) + { + Length = wcslen(RootHeader->lpExeName) + 1; + if (TargetBufferSize > Offset + Length) + { + wcscpy(&TargetBuffer[Offset], RootHeader->lpExeName); + Offset += Length; + } + else + { + break; + } + RootHeader = RootHeader->Next; + } + Length = min(Offset+1, TargetBufferSize); + TargetBuffer[Length] = L'\0'; + return Length * sizeof(WCHAR); +} + +UINT +IntGetAllConsoleAliasesLength(PALIAS_HEADER Header) +{ + UINT Length = 0; + PALIAS_ENTRY CurEntry = Header->Data; + + while(CurEntry) + { + Length += wcslen(CurEntry->lpSource); + Length += wcslen(CurEntry->lpTarget); + Length += 2; // zero byte and '=' + } + if (Length) + Length++; // extra zero + + return sizeof(WCHAR) * Length; +} +UINT +IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT TargetBufferLength) +{ + PALIAS_ENTRY CurEntry = Header->Data; + UINT Offset = 0; + UINT SrcLength, TargetLength; + + TargetBufferLength /= sizeof(WCHAR); + while(CurEntry) + { + SrcLength = wcslen(CurEntry->lpSource) + 1; + TargetLength = wcslen(CurEntry->lpTarget) + 1; + if (Offset + TargetLength + SrcLength >= TargetBufferLength) + break; + + wcscpy(&TargetBuffer[Offset], CurEntry->lpSource); + Offset += SrcLength; + TargetBuffer[Offset] = L'='; + wcscpy(&TargetBuffer[Offset], CurEntry->lpTarget); + Offset += TargetLength; + + CurEntry = CurEntry->Next; + } + TargetBuffer[Offset] = L'\0'; + return Offset * sizeof(WCHAR); +} +VOID +IntDeleteAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY Entry) +{ + PALIAS_ENTRY LastEntry; + PALIAS_ENTRY CurEntry; + + if (Header->Data == Entry) + { + Header->Data = Entry->Next; + RtlFreeHeap(CsrssApiHeap, 0, Entry); + return; + } + LastEntry = Header->Data; + CurEntry = LastEntry->Next; + + while(CurEntry) + { + if (CurEntry == Entry) + { + LastEntry->Next = Entry->Next; + RtlFreeHeap(CsrssApiHeap, 0, Entry); + return; + } + LastEntry = CurEntry; + CurEntry = CurEntry->Next; + } +} + +CSR_API(CsrAddConsoleAlias) +{ + PALIAS_HEADER Header; + PALIAS_ENTRY Entry; + + if (Request->Data.AddConsoleAlias.lpExeName == NULL || Request->Data.AddConsoleAlias.lpSource == NULL) + { + Request->Status = STATUS_INVALID_PARAMETER; + return Request->Status; + } + + Header = IntFindAliasHeader(RootHeader, Request->Data.AddConsoleAlias.lpExeName); + if (!Header) + { + Header = IntCreateAliasHeader(Request->Data.AddConsoleAlias.lpExeName); + if (!Header) + { + Request->Status = STATUS_INSUFFICIENT_RESOURCES; + return STATUS_INSUFFICIENT_RESOURCES; + } + } + + if (Request->Data.AddConsoleAlias.lpTarget == NULL) // delete the entry + { + Entry = IntGetAliasEntry(Header, Request->Data.AddConsoleAlias.lpSource); + if (Entry) + { + IntDeleteAliasEntry(Header, Entry); + Request->Status = STATUS_SUCCESS; + } + else + { + Request->Status = STATUS_INVALID_PARAMETER; + } + + return Request->Status; + } + + Entry = IntCreateAliasEntry(Request->Data.AddConsoleAlias.lpSource, + Request->Data.AddConsoleAlias.lpTarget); + + if (!Entry) + { + Request->Status = STATUS_INSUFFICIENT_RESOURCES; + return STATUS_INSUFFICIENT_RESOURCES; + } + + IntInsertAliasEntry(Header, Entry); + + Request->Status = STATUS_SUCCESS; + return Request->Status; +} + +CSR_API(CsrGetConsoleAlias) +{ + PALIAS_HEADER Header; + PALIAS_ENTRY Entry; + UINT Length; + + if (Request->Data.GetConsoleAlias.lpExeName == NULL || Request->Data.GetConsoleAlias.TargetBuffer == NULL || + Request->Data.GetConsoleAlias.TargetBufferLength == 0 || Request->Data.GetConsoleAlias.lpSource == NULL) + { + Request->Status = STATUS_INVALID_PARAMETER; + return Request->Status; + } + + Header = IntFindAliasHeader(RootHeader, Request->Data.GetAllConsoleAlias.lpExeName); + if (!Header) + { + Request->Status = ERROR_NO_DATA; // FIXME + return ERROR_NO_DATA; + } + + Entry = IntGetAliasEntry(Header, Request->Data.GetConsoleAlias.lpSource); + if (!Entry) + { + Request->Status = ERROR_NO_DATA; // FIXME + return ERROR_NO_DATA; + } + + Length = (wcslen(Entry->lpTarget)+1) * sizeof(WCHAR); + if (Length > Request->Data.GetConsoleAlias.TargetBufferLength) + { + Request->Status = ERROR_INSUFFICIENT_BUFFER; + return ERROR_INSUFFICIENT_BUFFER; + } + wcscpy(Request->Data.GetConsoleAlias.TargetBuffer, Entry->lpTarget); + Request->Data.GetConsoleAlias.BytesWritten = Length; + Request->Status = STATUS_SUCCESS; + return STATUS_SUCCESS; +} + +CSR_API(CsrGetAllConsoleAliases) +{ + ULONG BytesWritten; + PALIAS_HEADER Header; + + if (Request->Data.GetAllConsoleAlias.lpExeName == NULL) + { + Request->Status = STATUS_INVALID_PARAMETER; + return Request->Status; + } + + Header = IntFindAliasHeader(RootHeader, Request->Data.GetAllConsoleAlias.lpExeName); + if (!Header) + { + Request->Status = ERROR_NO_DATA; // FIXME + return ERROR_NO_DATA; + } + + if (IntGetAllConsoleAliasesLength(Header) > Request->Data.GetAllConsoleAlias.AliasBufferLength) + { + Request->Status = ERROR_INSUFFICIENT_BUFFER; + return ERROR_INSUFFICIENT_BUFFER; + } + + BytesWritten = IntGetAllConsoleAliases(Header, + Request->Data.GetAllConsoleAlias.AliasBuffer, + Request->Data.GetAllConsoleAlias.AliasBufferLength); + + Request->Data.GetAllConsoleAlias.BytesWritten = BytesWritten; + Request->Status = STATUS_SUCCESS; + return STATUS_SUCCESS; +} + +CSR_API(CsrGetAllConsoleAliasesLength) +{ + PALIAS_HEADER Header; + UINT Length; + + if (Request->Data.GetAllConsoleAliasesLength.lpExeName == NULL) + { + Request->Status = STATUS_INVALID_PARAMETER; + return Request->Status; + } + + Header = IntFindAliasHeader(RootHeader, Request->Data.GetAllConsoleAliasesLength.lpExeName); + if (!Header) + { + Request->Status = ERROR_NO_DATA; // FIXME + return ERROR_NO_DATA; + } + + Length = IntGetAllConsoleAliasesLength(Header); + Request->Data.GetAllConsoleAliasesLength.Length = Length; + Request->Status = STATUS_SUCCESS; + return STATUS_SUCCESS; + +} + +CSR_API(CsrGetConsoleAliasesExes) +{ + UINT BytesWritten; + UINT ExesLength = IntGetConsoleAliasesExesLength(RootHeader); + + if (ExesLength > Request->Data.GetConsoleAliasesExes.Length) + { + Request->Status = ERROR_INSUFFICIENT_BUFFER; + return ERROR_INSUFFICIENT_BUFFER; + } + + if (Request->Data.GetConsoleAliasesExes.ExeNames == NULL) + { + Request->Status = STATUS_INVALID_PARAMETER; + return Request->Status; + } + + BytesWritten = IntGetConsoleAliasesExes(RootHeader, + Request->Data.GetConsoleAliasesExes.ExeNames, + Request->Data.GetConsoleAliasesExes.Length); + + Request->Data.GetConsoleAliasesExes.BytesWritten = BytesWritten; + Request->Status = STATUS_SUCCESS; + return Request->Status; +} + +CSR_API(CsrGetConsoleAliasesExesLength) +{ + Request->Status = STATUS_SUCCESS; + Request->Data.GetConsoleAliasesExesLength.Length = IntGetConsoleAliasesExesLength(RootHeader); + return STATUS_SUCCESS; +} Propchange: trunk/reactos/subsystems/win32/csrss/api/alias.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/reactos/subsystems/win32/csrss/csrss.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/csrss.rbuild (original) +++ trunk/reactos/subsystems/win32/csrss/csrss.rbuild Mon Feb 4 21:57:19 2008 @@ -11,11 +11,13 @@ <library>nt</library> <library>ntdll</library> <library>smdll</library> + <library>msvcrt</library> <directory name="api"> <file>handle.c</file> <file>process.c</file> <file>user.c</file> <file>wapi.c</file> + <file>alias.c</file> </directory> <pch>csrss.h</pch> <file>csrss.c</file> Modified: trunk/reactos/subsystems/win32/csrss/include/api.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/inc…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/include/api.h (original) +++ trunk/reactos/subsystems/win32/csrss/include/api.h Mon Feb 4 21:57:19 2008 @@ -149,6 +149,14 @@ CSR_API(CsrSetLogonNotifyWindow); CSR_API(CsrRegisterLogonProcess); +CSR_API(CsrAddConsoleAlias); +CSR_API(CsrGetConsoleAlias); +CSR_API(CsrGetAllConsoleAliases); +CSR_API(CsrGetAllConsoleAliasesLength); +CSR_API(CsrGetConsoleAliasesExes); +CSR_API(CsrGetConsoleAliasesExesLength); + + #endif /* ndef API_H_INCLUDED */ /* EOF */ Modified: trunk/reactos/subsystems/win32/csrss/init.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/ini…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/init.c (original) +++ trunk/reactos/subsystems/win32/csrss/init.c Mon Feb 4 21:57:19 2008 @@ -293,6 +293,12 @@ CSRSS_DEFINE_API(VERIFY_HANDLE, CsrVerifyHandle), CSRSS_DEFINE_API(DUPLICATE_HANDLE, CsrDuplicateHandle), CSRSS_DEFINE_API(GET_INPUT_WAIT_HANDLE, CsrGetInputWaitHandle), + CSRSS_DEFINE_API(ADD_CONSOLE_ALIAS, CsrAddConsoleAlias), + CSRSS_DEFINE_API(GET_CONSOLE_ALIAS, CsrGetConsoleAlias), + CSRSS_DEFINE_API(GET_ALL_CONSOLE_ALIASES, CsrGetAllConsoleAliases), + CSRSS_DEFINE_API(GET_ALL_CONSOLE_ALIASES_LENGTH, CsrGetAllConsoleAliasesLength), + CSRSS_DEFINE_API(GET_CONSOLE_ALIASES_EXES, CsrGetConsoleAliasesExes), + CSRSS_DEFINE_API(GET_CONSOLE_ALIASES_EXES_LENGTH, CsrGetConsoleAliasesExesLength), { 0, 0, NULL } };
16 years, 10 months
1
0
0
0
[fireball] 32116: - Add missing registry values.
by fireball@svn.reactos.org
Author: fireball Date: Mon Feb 4 20:10:01 2008 New Revision: 32116 URL:
http://svn.reactos.org/svn/reactos?rev=32116&view=rev
Log: - Add missing registry values. Modified: trunk/reactos/include/psdk/regstr.h Modified: trunk/reactos/include/psdk/regstr.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/regstr.h?rev=…
============================================================================== --- trunk/reactos/include/psdk/regstr.h (original) +++ trunk/reactos/include/psdk/regstr.h Mon Feb 4 20:10:01 2008 @@ -752,6 +752,42 @@ #define REGSTR_VAL_JOYOEMCAL10 TEXT("OEMCal10") #define REGSTR_VAL_JOYOEMCAL11 TEXT("OEMCal11") #define REGSTR_VAL_JOYOEMCAL12 TEXT("OEMCal12") +#define REGSTR_KEY_DEVICE_PROPERTIES TEXT("Properties") +#define REGSTR_VAL_SLOTNUMBER TEXT("SlotNumber") +#define REGSTR_VAL_ATTACHEDCOMPONENTS TEXT("AttachedComponents") +#define REGSTR_VAL_BASEDEVICEPATH TEXT("BaseDevicePath") +#define REGSTR_VAL_SYSTEMBUSNUMBER TEXT("SystemBusNumber") +#define REGSTR_VAL_BUSDATATYPE TEXT("BusDataType") +#define REGSTR_VAL_INTERFACETYPE TEXT("InterfaceType") +#define REGSTR_VAL_SERVICE TEXT("Service") +#define REGSTR_VAL_DETECTSIGNATURE TEXT("DetectSignature") +#define REGSTR_VAL_CLASSGUID TEXT("ClassGUID") +#define REGSTR_VAL_INSTANCEIDENTIFIER TEXT("InstanceIdentifier") +#define REGSTR_VAL_DUPLICATEOF TEXT("DuplicateOf") +#define REGSTR_VAL_STATUSFLAGS TEXT("StatusFlags") +#define REGSTR_VAL_DISABLECOUNT TEXT("DisableCount") +#define REGSTR_VAL_UNKNOWNPROBLEMS TEXT("UnknownProblem") +#define REGSTR_VAL_DOCKSTATE TEXT("DockState") +#define REGSTR_VAL_PREFERENCEORDER TEXT("PreferenceOrder") +#define REGSTR_VAL_USERWAITINTERVAL TEXT("UserWaitInterval") +#define REGSTR_VAL_DEVICE_INSTANCE TEXT("DeviceInstance") +#define REGSTR_VAL_SYMBOLIC_LINK TEXT("SymbolicLink") +#define REGSTR_VAL_DEFAULT TEXT("Default") +#define REGSTR_VAL_LOWERFILTERS TEXT("LowerFilters") +#define REGSTR_VAL_UPPERFILTERS TEXT("UpperFilters") +#define REGSTR_VAL_LOCATION_INFORMATION TEXT("LocationInformation") +#define REGSTR_VAL_UI_NUMBER TEXT("UINumber") +#define REGSTR_VAL_UI_NUMBER_DESC_FORMAT TEXT("UINumberDescFormat") +#define REGSTR_VAL_CAPABILITIES TEXT("Capabilities") +#define REGSTR_VAL_DEVICE_TYPE TEXT("DeviceType") +#define REGSTR_VAL_DEVICE_CHARACTERISTICS TEXT("DeviceCharacteristics") +#define REGSTR_VAL_DEVICE_SECURITY_DESCRIPTOR TEXT("Security") +#define REGSTR_VAL_DEVICE_EXCLUSIVE TEXT("Exclusive") +#define REGSTR_VAL_RESOURCE_PICKER_TAGS TEXT("ResourcePickerTags") +#define REGSTR_VAL_RESOURCE_PICKER_EXCEPTIONS TEXT("ResourcePickerExceptions") +#define REGSTR_VAL_CUSTOM_PROPERTY_CACHE_DATE TEXT("CustomPropertyCacheDate") +#define REGSTR_VAL_CUSTOM_PROPERTY_HW_ID_KEY TEXT("CustomPropertyHwIdKey") +#define REGSTR_VAL_LAST_UPDATE_TIME TEXT("LastUpdateTime") #ifndef NEC_98 #define REGSTR_KEY_ISAENUM TEXT("ISAPnP") #define REGSTR_KEY_EISAENUM TEXT("EISA")
16 years, 10 months
1
0
0
0
[janderwald] 32115: - add api message structs / constants for doskey
by janderwald@svn.reactos.org
Author: janderwald Date: Mon Feb 4 18:06:09 2008 New Revision: 32115 URL:
http://svn.reactos.org/svn/reactos?rev=32115&view=rev
Log: - add api message structs / constants for doskey Modified: trunk/reactos/include/reactos/subsys/csrss/csrss.h Modified: trunk/reactos/include/reactos/subsys/csrss/csrss.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/subsys/csr…
============================================================================== --- trunk/reactos/include/reactos/subsys/csrss/csrss.h (original) +++ trunk/reactos/include/reactos/subsys/csrss/csrss.h Mon Feb 4 18:06:09 2008 @@ -411,6 +411,53 @@ { HANDLE InputWaitHandle; } CSRSS_GET_INPUT_WAIT_HANDLE, *PCSRSS_GET_INPUT_WAIT_HANDLE; + +typedef struct +{ + LPCWSTR lpSource; + LPCWSTR lpTarget; + LPCWSTR lpExeName; +} CSRSS_ADD_CONSOLE_ALIAS, *PCSRSS_ADD_CONSOLE_ALIAS; + +typedef struct +{ + LPWSTR lpSource; + LPWSTR lpExeName; + DWORD BytesWritten; + DWORD TargetBufferLength; + LPWSTR TargetBuffer; + +} CSRSS_GET_CONSOLE_ALIAS, *PCSRSS_GET_CONSOLE_ALIAS; + +typedef struct +{ + LPWSTR lpExeName; + DWORD BytesWritten; + DWORD AliasBufferLength; + LPWSTR AliasBuffer; +} CSRSS_GET_ALL_CONSOLE_ALIAS, *PCSRSS_GET_ALL_CONSOLE_ALIAS; + +typedef struct +{ + LPWSTR lpExeName; + DWORD Length; +} CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH, *PCSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH; + +typedef struct +{ + BOOL Unicode; + DWORD BytesWritten; + DWORD Length; + LPWSTR ExeNames; +} CSRSS_GET_CONSOLE_ALIASES_EXES, *PCSRSS_GET_CONSOLE_ALIASES_EXES; + +typedef struct +{ + BOOL Unicode; + DWORD Length; +} CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH, *PCSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH; + + #define CSR_API_MESSAGE_HEADER_SIZE(Type) (FIELD_OFFSET(CSR_API_MESSAGE, Data) + sizeof(Type)) #define CSRSS_MAX_WRITE_CONSOLE (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE)) @@ -480,6 +527,12 @@ #define GET_INPUT_WAIT_HANDLE (0x35) #define GET_PROCESS_LIST (0x36) #define START_SCREEN_SAVER (0x37) +#define ADD_CONSOLE_ALIAS (0x38) +#define GET_CONSOLE_ALIAS (0x39) +#define GET_ALL_CONSOLE_ALIAS (0x3A) +#define GET_ALL_CONSOLE_ALIASES_LENGTH (0x3B) +#define GET_CONSOLE_ALIASES_EXES (0x3C) +#define GET_CONSOLE_ALIASES_EXES_LENGTH (0x3D) /* Keep in sync with definition below. */ #define CSRSS_HEADER_SIZE (sizeof(PORT_MESSAGE) + sizeof(ULONG) + sizeof(NTSTATUS)) @@ -545,6 +598,12 @@ CSRSS_SET_CONSOLE_OUTPUT_CP SetConsoleOutputCodePage; CSRSS_GET_INPUT_WAIT_HANDLE GetConsoleInputWaitHandle; CSRSS_GET_PROCESS_LIST GetProcessListRequest; + CSRSS_ADD_CONSOLE_ALIAS AddConsoleAlias; + CSRSS_GET_CONSOLE_ALIAS GetConsoleAlias; + CSRSS_GET_ALL_CONSOLE_ALIAS GetAllConsoleAlias; + CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH GetAllConsoleAliasesLength; + CSRSS_GET_CONSOLE_ALIASES_EXES GetConsoleAliasesExes; + CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH GetConsoleAliasesExesLength; } Data; } CSR_API_MESSAGE, *PCSR_API_MESSAGE;
16 years, 10 months
1
0
0
0
[fireball] 32114: - Sync RPC headers with Wine.
by fireball@svn.reactos.org
Author: fireball Date: Mon Feb 4 16:15:01 2008 New Revision: 32114 URL:
http://svn.reactos.org/svn/reactos?rev=32114&view=rev
Log: - Sync RPC headers with Wine. Modified: trunk/reactos/include/psdk/rpc.h trunk/reactos/include/psdk/rpcasync.h trunk/reactos/include/psdk/rpcdce.h trunk/reactos/include/psdk/rpcdcep.h trunk/reactos/include/psdk/rpcproxy.h Modified: trunk/reactos/include/psdk/rpc.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/rpc.h?rev=321…
============================================================================== --- trunk/reactos/include/psdk/rpc.h (original) +++ trunk/reactos/include/psdk/rpc.h Mon Feb 4 16:15:01 2008 @@ -91,10 +91,6 @@ #define RPCNSAPI #endif -#ifndef RPC_NO_WINDOWS_H -#include <rpcasync.h> -#endif - #ifdef __RPC_MAC__ #include <setjmp.h> #define RPCXCWORD (sizeof(jmp_buf)/sizeof(int)) @@ -167,6 +163,10 @@ #include <poppack.h> #endif +#ifndef RPC_NO_WINDOWS_H +#include <rpcasync.h> +#endif + #ifdef __cplusplus } #endif Modified: trunk/reactos/include/psdk/rpcasync.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/rpcasync.h?re…
============================================================================== --- trunk/reactos/include/psdk/rpcasync.h (original) +++ trunk/reactos/include/psdk/rpcasync.h Mon Feb 4 16:15:01 2008 @@ -17,6 +17,7 @@ */ #ifndef __WINE_RPCASYNC_H #define __WINE_RPCASYNC_H + typedef struct tagRPC_ERROR_ENUM_HANDLE { @@ -173,12 +174,12 @@ RPCRTAPI RPC_STATUS RPC_ENTRY RpcErrorLoadErrorInfo(PVOID,SIZE_T,RPC_ERROR_ENUM_HANDLE*); RPCRTAPI RPC_STATUS RPC_ENTRY RpcErrorAddRecord(RPC_EXTENDED_ERROR_INFO*); RPCRTAPI RPC_STATUS RPC_ENTRY RpcErrorClearInformation(void); -//RPCRTAPI RPC_STATUS RPC_ENTRY RpcGetAuthorizationContextForClient(RPC_BINDING_HANDLE,BOOL,LPVOID,PLARGE_INTEGER,LUID,DWORD,PVOID,PVOID*); +RPCRTAPI RPC_STATUS RPC_ENTRY RpcGetAuthorizationContextForClient(RPC_BINDING_HANDLE,BOOL,LPVOID,PLARGE_INTEGER,LUID,DWORD,PVOID,PVOID*); RPCRTAPI RPC_STATUS RPC_ENTRY RpcFreeAuthorizationContext(PVOID*); -//RPCRTAPI RPC_STATUS RPC_ENTRY RpcSsContextLockExclusive(RPC_BINDING_HANDLE,PVOID); -//RPCRTAPI RPC_STATUS RPC_ENTRY RpcSsContextLockShared(RPC_BINDING_HANDLE,PVOID); +RPCRTAPI RPC_STATUS RPC_ENTRY RpcSsContextLockExclusive(RPC_BINDING_HANDLE,PVOID); +RPCRTAPI RPC_STATUS RPC_ENTRY RpcSsContextLockShared(RPC_BINDING_HANDLE,PVOID); -//RPCRTAPI RPC_STATUS RPC_ENTRY I_RpcAsyncSetHandle(PRPC_MESSAGE,PRPC_ASYNC_STATE); +RPCRTAPI RPC_STATUS RPC_ENTRY I_RpcAsyncSetHandle(PRPC_MESSAGE,PRPC_ASYNC_STATE); RPCRTAPI RPC_STATUS RPC_ENTRY I_RpcAsyncAbortCall(PRPC_ASYNC_STATE,ULONG); RPCRTAPI int RPC_ENTRY I_RpcExceptionFilter(ULONG); Modified: trunk/reactos/include/psdk/rpcdce.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/rpcdce.h?rev=…
============================================================================== --- trunk/reactos/include/psdk/rpcdce.h (original) +++ trunk/reactos/include/psdk/rpcdce.h Mon Feb 4 16:15:01 2008 @@ -32,6 +32,7 @@ #ifndef OPTIONAL #define OPTIONAL #endif + #ifndef GUID_DEFINED #include <guiddef.h> #endif @@ -288,7 +289,7 @@ RPC_STATUS RPC_ENTRY DceErrorInqTextW(RPC_STATUS e, RPC_WSTR buffer); #define DceErrorInqText WINELIB_NAME_AW(DceErrorInqText) -RPCRTAPI void RPC_ENTRY +RPCRTAPI DECLSPEC_NORETURN void RPC_ENTRY RpcRaiseException( RPC_STATUS exception ); RPCRTAPI RPC_STATUS RPC_ENTRY @@ -365,6 +366,8 @@ RPCRTAPI RPC_STATUS RPC_ENTRY RpcServerListen( unsigned int MinimumCallThreads, unsigned int MaxCalls, unsigned int DontWait ); + +RPCRTAPI RPC_STATUS RPC_ENTRY RpcMgmtSetCancelTimeout(LONG); RPCRTAPI RPC_STATUS RPC_ENTRY RpcMgmtWaitServerListen( void ); @@ -464,6 +467,8 @@ RpcBindingInqAuthInfoW( RPC_BINDING_HANDLE Binding, RPC_WSTR *ServerPrincName, ULONG *AuthnLevel, ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc ); #define RpcBindingInqAuthInfo WINELIB_NAME_AW(RpcBindingInqAuthInfo) + +RPCRTAPI RPC_STATUS RPC_ENTRY RpcCancelThread(void*); RPCRTAPI RPC_STATUS RPC_ENTRY RpcNetworkIsProtseqValidA( RPC_CSTR protseq ); Modified: trunk/reactos/include/psdk/rpcdcep.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/rpcdcep.h?rev…
============================================================================== --- trunk/reactos/include/psdk/rpcdcep.h (original) +++ trunk/reactos/include/psdk/rpcdcep.h Mon Feb 4 16:15:01 2008 @@ -18,6 +18,10 @@ #ifndef __WINE_RPCDCEP_H #define __WINE_RPCDCEP_H + +#ifdef __cplusplus +extern "C" { +#endif typedef struct _RPC_VERSION { unsigned short MajorVersion; @@ -44,6 +48,9 @@ unsigned long RpcFlags; } RPC_MESSAGE, *PRPC_MESSAGE; +/* or'd with ProcNum */ +#define RPC_FLAGS_VALID_BIT 0x00008000 + #define RPC_CONTEXT_HANDLE_DEFAULT_GUARD ((void *)0xfffff00d) #define RPC_CONTEXT_HANDLE_DEFAULT_FLAGS 0x00000000 @@ -72,9 +79,8 @@ #define RPCFLG_ASYNCHRONOUS 0x40000000 #define RPCFLG_NON_NDR 0x80000000 -#define RPC_FLAGS_VALID_BIT 0x00008000 - typedef void (__RPC_STUB *RPC_DISPATCH_FUNCTION)(PRPC_MESSAGE Message); +typedef RPC_STATUS (RPC_ENTRY *RPC_FORWARD_FUNCTION)(UUID *InterfaceId, RPC_VERSION *InterfaceVersion, UUID *ObjectId, unsigned char *Rpcpro, void **ppDestEndpoint); typedef struct { @@ -124,6 +130,8 @@ #define TRANSPORT_TYPE_WMSG 0x08 RPCRTAPI RPC_STATUS RPC_ENTRY + I_RpcNegotiateTransferSyntax( RPC_MESSAGE* Message ); +RPCRTAPI RPC_STATUS RPC_ENTRY I_RpcGetBuffer( RPC_MESSAGE* Message ); RPCRTAPI RPC_STATUS RPC_ENTRY I_RpcGetBufferWithObject( RPC_MESSAGE* Message, UUID* ObjectUuid ); @@ -152,7 +160,7 @@ * Note that the prototypes for I_RpcBindingSetAsync are different for each case. * * Wine defaults to the WinNT case and only defines these function is MSWMSG is - * defined. Defining the NT functions by default causes MIDL generated proxys + * defined. Defining the NT functions by default causes MIDL generated proxies * to not compile. */ @@ -180,9 +188,6 @@ RPCRTAPI RPC_STATUS RPC_ENTRY I_RpcSetWMsgEndpoint( WCHAR* Endpoint ); -RPCRTAPI RPC_STATUS RPC_ENTRY - I_RpcBindingInqTransportType( RPC_BINDING_HANDLE Binding, unsigned int* Type ); - #endif #else @@ -207,4 +212,13 @@ #endif +RPCRTAPI RPC_STATUS RPC_ENTRY + I_RpcBindingInqTransportType( RPC_BINDING_HANDLE Binding, unsigned int* Type ); + +RPCRTAPI LONG RPC_ENTRY I_RpcMapWin32Status(RPC_STATUS); + +#ifdef __cplusplus +} +#endif + #endif /*__WINE_RPCDCEP_H */ Modified: trunk/reactos/include/psdk/rpcproxy.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/rpcproxy.h?re…
============================================================================== --- trunk/reactos/include/psdk/rpcproxy.h (original) +++ trunk/reactos/include/psdk/rpcproxy.h Mon Feb 4 16:15:01 2008 @@ -32,6 +32,10 @@ #endif #include <rpc.h> #include <rpcndr.h> + +#ifdef __cplusplus +extern "C" { +#endif typedef struct tagCInterfaceStubVtbl *PCInterfaceStubVtblList; typedef struct tagCInterfaceProxyVtbl *PCInterfaceProxyVtblList; @@ -357,4 +361,8 @@ #endif +#ifdef __cplusplus +} +#endif + #endif /*__WINE_RPCDCE_H */
16 years, 10 months
1
0
0
0
[fireball] 32113: - Make Mm allocation strategy low->high by default. - Clean up Mm APIs which are not needed anymore. - Get rid of the LOADER_HIGH_ZONE definition, now the real LoaderPagesSpanned value is calculated and used. As a result, minimum memory requirement (which was >= LOADER_HIGH_ZONE) is gone, and a maximum amount of memory which could be allocated is also gone (previously, not more that the LOADER_HIGH_ZONE). - IMPORTANT: The FAT filesystem caching is disabled by default now due st
by fireball@svn.reactos.org
Author: fireball Date: Mon Feb 4 13:45:55 2008 New Revision: 32113 URL:
http://svn.reactos.org/svn/reactos?rev=32113&view=rev
Log: - Make Mm allocation strategy low->high by default. - Clean up Mm APIs which are not needed anymore. - Get rid of the LOADER_HIGH_ZONE definition, now the real LoaderPagesSpanned value is calculated and used. As a result, minimum memory requirement (which was >= LOADER_HIGH_ZONE) is gone, and a maximum amount of memory which could be allocated is also gone (previously, not more that the LOADER_HIGH_ZONE). - IMPORTANT: The FAT filesystem caching is disabled by default now due strange problems in 3rd boot stage, after switching the cache to use heap routines. Cache can't use non-heap routines anymore, since the memory will overlap the contigious modules memory space which ReactOS needs. - More cleanup and more usage of the heap routines for temporary buffers. - Fix a bug in MmAllocateMemoryWithType, where result of MmFindAvailablePages was checked against -1 in error case, when in reality it's 0 (spotted by Alex). NB: 0 page is marked as a reserved in x86 arch, so it's never going to be returned as an available. Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c trunk/reactos/boot/freeldr/freeldr/cache/blocklist.c trunk/reactos/boot/freeldr/freeldr/cache/cache.c trunk/reactos/boot/freeldr/freeldr/fs/fat.c trunk/reactos/boot/freeldr/freeldr/include/mm.h trunk/reactos/boot/freeldr/freeldr/mm/meminit.c trunk/reactos/boot/freeldr/freeldr/mm/mm.c trunk/reactos/boot/freeldr/freeldr/windows/peloader.c trunk/reactos/boot/freeldr/freeldr/windows/winldr.c trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c Mon Feb 4 13:45:55 2008 @@ -582,7 +582,7 @@ FsSetFilePointer(Image, 0); /* Allocate a temporary buffer for the read */ - ReadBuffer = MmAllocateMemory(ImageSize); + ReadBuffer = MmHeapAlloc(ImageSize); /* Load the file image */ FsReadFile(Image, ImageSize, NULL, ReadBuffer); @@ -591,7 +591,7 @@ ImageSize = FrLdrReMapImage(ReadBuffer, LoadBase); /* Free the temporary buffer */ - MmFreeMemory(ReadBuffer); + MmHeapFree(ReadBuffer); /* Calculate Difference between Real Base and Compiled Base*/ Status = LdrRelocateImageWithBias(LoadBase, Modified: trunk/reactos/boot/freeldr/freeldr/cache/blocklist.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/cache…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/cache/blocklist.c (original) +++ trunk/reactos/boot/freeldr/freeldr/cache/blocklist.c Mon Feb 4 13:45:55 2008 @@ -108,7 +108,7 @@ // allocate room for the block data RtlZeroMemory(CacheBlock, sizeof(CACHE_BLOCK)); CacheBlock->BlockNumber = BlockNumber; - CacheBlock->BlockData = MmAllocateMemory(CacheDrive->BlockSize * CacheDrive->BytesPerSector); + CacheBlock->BlockData = MmHeapAlloc(CacheDrive->BlockSize * CacheDrive->BytesPerSector); if (CacheBlock->BlockData ==NULL) { MmHeapFree(CacheBlock); @@ -118,7 +118,7 @@ // Now try to read in the block if (!MachDiskReadLogicalSectors(CacheDrive->DriveNumber, (BlockNumber * CacheDrive->BlockSize), CacheDrive->BlockSize, (PVOID)DISKREADBUFFER)) { - MmFreeMemory(CacheBlock->BlockData); + MmHeapFree(CacheBlock->BlockData); MmHeapFree(CacheBlock); return NULL; } @@ -161,7 +161,7 @@ RemoveEntryList(&CacheBlockToFree->ListEntry); // Free the block memory and the block structure - MmFreeMemory(CacheBlockToFree->BlockData); + MmHeapFree(CacheBlockToFree->BlockData); MmHeapFree(CacheBlockToFree); // Update the cache data Modified: trunk/reactos/boot/freeldr/freeldr/cache/cache.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/cache…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/cache/cache.c (original) +++ trunk/reactos/boot/freeldr/freeldr/cache/cache.c Mon Feb 4 13:45:55 2008 @@ -70,7 +70,7 @@ CACHE_BLOCK, ListEntry); - MmFreeMemory(NextCacheBlock->BlockData); + MmHeapFree(NextCacheBlock->BlockData); MmHeapFree(NextCacheBlock); } } Modified: trunk/reactos/boot/freeldr/freeldr/fs/fat.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/fs/fa…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/fs/fat.c (original) +++ trunk/reactos/boot/freeldr/freeldr/fs/fat.c Mon Feb 4 13:45:55 2008 @@ -22,7 +22,7 @@ #define NDEBUG #include <debug.h> -BOOLEAN gCacheEnabled = TRUE; +BOOLEAN gCacheEnabled = FALSE; ULONG BytesPerSector; /* Number of bytes per sector */ ULONG SectorsPerCluster; /* Number of sectors per cluster */ Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/mm.h (original) +++ trunk/reactos/boot/freeldr/freeldr/include/mm.h Mon Feb 4 13:45:55 2008 @@ -47,10 +47,6 @@ ( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) ) #endif // defined __i386__ or _PPC_ or _MIPS_ -// -// This is the zone which is used by the OS loader -// -#define LOADER_HIGH_ZONE ((24*1024*1024) >> MM_PAGE_SHIFT) // 24Mb // HEAP and STACK size #define HEAP_PAGES 0x400 @@ -105,9 +101,6 @@ PVOID MmAllocateMemory(ULONG MemorySize); PVOID MmAllocateMemoryWithType(ULONG MemorySize, TYPE_OF_MEMORY MemoryType); VOID MmFreeMemory(PVOID MemoryPointer); -VOID MmChangeAllocationPolicy(BOOLEAN PolicyAllocatePagesFromEnd); -//PVOID MmAllocateLowMemory(ULONG MemorySize); -//VOID MmFreeLowMemory(PVOID MemoryPointer); PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType); PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType); Modified: trunk/reactos/boot/freeldr/freeldr/mm/meminit.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/me…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/mm/meminit.c (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/meminit.c Mon Feb 4 13:45:55 2008 @@ -393,8 +393,7 @@ if (FromEnd) { /* Allocate "high" (from end) pages */ - for (Index=/*LastFreePageHint-1*/LOADER_HIGH_ZONE-1; Index>0; Index--) - //for (Index=LastFreePageHint-1; Index>0; Index--) + for (Index=LastFreePageHint-1; Index>0; Index--) { if (RealPageLookupTable[Index].PageAllocated != LoaderFree) { Modified: trunk/reactos/boot/freeldr/freeldr/mm/mm.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/mm…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/mm/mm.c (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/mm.c Mon Feb 4 13:45:55 2008 @@ -25,12 +25,7 @@ VOID MemAllocTest(VOID); #endif // DBG -BOOLEAN AllocateFromEnd = TRUE; - -VOID MmChangeAllocationPolicy(BOOLEAN PolicyAllocatePagesFromEnd) -{ - AllocateFromEnd = PolicyAllocatePagesFromEnd; -} +ULONG LoaderPagesSpanned = 0; PVOID MmAllocateMemoryWithType(ULONG MemorySize, TYPE_OF_MEMORY MemoryType) { @@ -60,9 +55,9 @@ return NULL; } - FirstFreePageFromEnd = MmFindAvailablePages(PageLookupTableAddress, TotalPagesInLookupTable, PagesNeeded, AllocateFromEnd); - - if (FirstFreePageFromEnd == (ULONG)-1) + FirstFreePageFromEnd = MmFindAvailablePages(PageLookupTableAddress, TotalPagesInLookupTable, PagesNeeded, FALSE); + + if (FirstFreePageFromEnd == 0) { DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize)); UiMessageBoxCritical("Memory allocation failed: out of memory."); @@ -78,6 +73,10 @@ DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd)); DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer)); #endif // DBG + + // Update LoaderPagesSpanned count + if ((((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT) > LoaderPagesSpanned) + LoaderPagesSpanned = (((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT); // Now return the pointer return MemPointer; @@ -174,6 +173,10 @@ DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, StartPageNumber)); DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer)); #endif // DBG + + // Update LoaderPagesSpanned count + if ((((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT) > LoaderPagesSpanned) + LoaderPagesSpanned = (((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT); // Now return the pointer return MemPointer; @@ -227,6 +230,10 @@ DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd)); DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer)); #endif // DBG + + // Update LoaderPagesSpanned count + if ((((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT) > LoaderPagesSpanned) + LoaderPagesSpanned = (((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT); // Now return the pointer return MemPointer; Modified: trunk/reactos/boot/freeldr/freeldr/windows/peloader.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/peloader.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/peloader.c Mon Feb 4 13:45:55 2008 @@ -1,832 +1,830 @@ -/* - * PROJECT: FreeLoader - * LICENSE: GPL - See COPYING in the top level directory - * FILE: freeldr/winldr/peloader.c - * PURPOSE: Provides routines for loading PE files. To be merged with - * arch/i386/loader.c in future - * This article was very handy during development: - *
http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/
- * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org) - * The source code in this file is based on the work of respective - * authors of PE loading code in ReactOS and Brian Palmer and - * Alex Ionescu's arch/i386/loader.c, and my research project - * (creating a native EFI loader for Windows) - */ - -/* INCLUDES ***************************************************************/ -#include <freeldr.h> -#include <debug.h> - - -BOOLEAN -WinLdrpCompareDllName(IN PCH DllName, - IN PUNICODE_STRING UnicodeName); - -BOOLEAN -WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PVOID DllBase, - IN PVOID ImageBase, - IN PIMAGE_THUNK_DATA ThunkData, - IN PIMAGE_EXPORT_DIRECTORY ExportDirectory, - IN ULONG ExportSize, - IN BOOLEAN ProcessForwards); - -BOOLEAN -WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock, - PCCH DirectoryPath, - PCH ImportName, - PLDR_DATA_TABLE_ENTRY *DataTableEntry); - -BOOLEAN -WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PVOID DllBase, - IN PVOID ImageBase, - IN PIMAGE_THUNK_DATA ThunkData); - - - -/* FUNCTIONS **************************************************************/ - -/* Returns TRUE if DLL has already been loaded - looks in LoadOrderList in LPB */ -BOOLEAN -WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PCH DllName, - OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry) -{ - PLDR_DATA_TABLE_ENTRY DataTableEntry; - LIST_ENTRY *ModuleEntry; - - DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DllName %X, LoadedEntry: %X\n", - DllName, LoadedEntry)); - - /* Just go through each entry in the LoadOrderList and compare loaded module's - name with a given name */ - ModuleEntry = WinLdrBlock->LoadOrderListHead.Flink; - while (ModuleEntry != &WinLdrBlock->LoadOrderListHead) - { - /* Get pointer to the current DTE */ - DataTableEntry = CONTAINING_RECORD(ModuleEntry, - LDR_DATA_TABLE_ENTRY, - InLoadOrderLinks); - - DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DTE %p, EP %p\n", - DataTableEntry, DataTableEntry->EntryPoint)); - - /* Compare names */ - if (WinLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName)) - { - /* Yes, found it, report pointer to the loaded module's DTE - to the caller and increase load count for it */ - *LoadedEntry = DataTableEntry; - DataTableEntry->LoadCount++; - DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: LoadedEntry %X\n", DataTableEntry)); - return TRUE; - } - - /* Go to the next entry */ - ModuleEntry = ModuleEntry->Flink; - } - - /* Nothing found */ - return FALSE; -} - -BOOLEAN -WinLdrScanImportDescriptorTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PCCH DirectoryPath, - IN PLDR_DATA_TABLE_ENTRY ScanDTE) -{ - PLDR_DATA_TABLE_ENTRY DataTableEntry; - PIMAGE_IMPORT_DESCRIPTOR ImportTable; - ULONG ImportTableSize; - PCH ImportName; - BOOLEAN Status; - - /* Get a pointer to the import table of this image */ - ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase), - TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize); - - { - UNICODE_STRING BaseName; - BaseName.Buffer = VaToPa(ScanDTE->BaseDllName.Buffer); - BaseName.MaximumLength = ScanDTE->BaseDllName.MaximumLength; - BaseName.Length = ScanDTE->BaseDllName.Length; - DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%X\n", - &BaseName, ImportTable)); - } - - /* If image doesn't have any import directory - just return success */ - if (ImportTable == NULL) - return TRUE; - - /* Loop through all entries */ - for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++) - { - /* Get pointer to the name */ - ImportName = (PCH)VaToPa(RVA(ScanDTE->DllBase, ImportTable->Name)); - DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): Looking at %s\n", ImportName)); - - /* In case we get a reference to ourselves - just skip it */ - if (WinLdrpCompareDllName(ImportName, &ScanDTE->BaseDllName)) - continue; - - /* Load the DLL if it is not already loaded */ - if (!WinLdrCheckForLoadedDll(WinLdrBlock, ImportName, &DataTableEntry)) - { - Status = WinLdrpLoadAndScanReferencedDll(WinLdrBlock, - DirectoryPath, - ImportName, - &DataTableEntry); - - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, "WinLdrpLoadAndScanReferencedDll() failed\n")); - return Status; - } - } - - /* Scan its import address table */ - Status = WinLdrpScanImportAddressTable( - WinLdrBlock, - DataTableEntry->DllBase, - ScanDTE->DllBase, - (PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk)); - - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable() failed\n")); - return Status; - } - } - - return TRUE; -} - -BOOLEAN -WinLdrAllocateDataTableEntry(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PCCH BaseDllName, - IN PCCH FullDllName, - IN PVOID BasePA, - OUT PLDR_DATA_TABLE_ENTRY *NewEntry) -{ - PVOID BaseVA = PaToVa(BasePA); - PWSTR Buffer; - PLDR_DATA_TABLE_ENTRY DataTableEntry; - PIMAGE_NT_HEADERS NtHeaders; - USHORT Length; - - /* Allocate memory for a data table entry, zero-initialize it */ - DataTableEntry = (PLDR_DATA_TABLE_ENTRY)MmHeapAlloc(sizeof(LDR_DATA_TABLE_ENTRY)); - if (DataTableEntry == NULL) - return FALSE; - RtlZeroMemory(DataTableEntry, sizeof(LDR_DATA_TABLE_ENTRY)); - - /* Get NT headers from the image */ - NtHeaders = RtlImageNtHeader(BasePA); - - /* Initialize corresponding fields of DTE based on NT headers value */ - DataTableEntry->DllBase = BaseVA; - DataTableEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage; - DataTableEntry->EntryPoint = RVA(BaseVA, NtHeaders->OptionalHeader.AddressOfEntryPoint); - DataTableEntry->SectionPointer = 0; - DataTableEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum; - - /* Initialize BaseDllName field (UNICODE_STRING) from the Ansi BaseDllName - by simple conversion - copying each character */ - Length = (USHORT)(strlen(BaseDllName) * sizeof(WCHAR)); - Buffer = (PWSTR)MmHeapAlloc(Length); - if (Buffer == NULL) - { - MmHeapFree(DataTableEntry); - return FALSE; - } - RtlZeroMemory(Buffer, Length); - - DataTableEntry->BaseDllName.Length = Length; - DataTableEntry->BaseDllName.MaximumLength = Length; - DataTableEntry->BaseDllName.Buffer = PaToVa(Buffer); - while (*BaseDllName != 0) - { - *Buffer++ = *BaseDllName++; - } - - /* Initialize FullDllName field (UNICODE_STRING) from the Ansi FullDllName - using the same method */ - Length = (USHORT)(strlen(FullDllName) * sizeof(WCHAR)); - Buffer = (PWSTR)MmHeapAlloc(Length); - if (Buffer == NULL) - { - MmHeapFree(DataTableEntry); - return FALSE; - } - RtlZeroMemory(Buffer, Length); - - DataTableEntry->FullDllName.Length = Length; - DataTableEntry->FullDllName.MaximumLength = Length; - DataTableEntry->FullDllName.Buffer = PaToVa(Buffer); - while (*FullDllName != 0) - { - *Buffer++ = *FullDllName++; - } - - /* Initialize what's left - LoadCount which is 1, and set Flags so that - we know this entry is processed */ - DataTableEntry->Flags = LDRP_ENTRY_PROCESSED; - DataTableEntry->LoadCount = 1; - - /* Insert this DTE to a list in the LPB */ - InsertTailList(&WinLdrBlock->LoadOrderListHead, &DataTableEntry->InLoadOrderLinks); - - /* Save pointer to a newly allocated and initialized entry */ - *NewEntry = DataTableEntry; - - /* Return success */ - return TRUE; -} - -/* WinLdrLoadImage loads the specified image from the file (it doesn't - perform any additional operations on the filename, just directly - calls the file I/O routines), and relocates it so that it's ready - to be used when paging is enabled. - Addressing mode: physical - */ -BOOLEAN -WinLdrLoadImage(IN PCHAR FileName, - TYPE_OF_MEMORY MemoryType, - OUT PVOID *ImageBasePA) -{ - PFILE FileHandle; - PVOID PhysicalBase; - PVOID VirtualBase = NULL; - UCHAR HeadersBuffer[SECTOR_SIZE * 2]; - PIMAGE_NT_HEADERS NtHeaders; - PIMAGE_SECTION_HEADER SectionHeader; - ULONG VirtualSize, SizeOfRawData, NumberOfSections; - BOOLEAN Status; - ULONG i, BytesRead; - - CHAR ProgressString[256]; - - /* Inform user we are loading files */ - sprintf(ProgressString, "Loading %s...", FileName); - UiDrawProgressBarCenter(1, 100, ProgressString); - - /* Open the image file */ - FileHandle = FsOpenFile(FileName); - - if (FileHandle == NULL) - { - //Print(L"Can not open the file %s\n",FileName); - UiMessageBox("Can not open the file"); - return FALSE; - } - - /* Load the first 2 sectors of the image so we can read the PE header */ - Status = FsReadFile(FileHandle, SECTOR_SIZE * 2, NULL, HeadersBuffer); - if (!Status) - { - //Print(L"Error reading from file %s\n", FileName); - UiMessageBox("Error reading from file"); - FsCloseFile(FileHandle); - return FALSE; - } - - /* Now read the MZ header to get the offset to the PE Header */ - NtHeaders = RtlImageNtHeader(HeadersBuffer); - - if (!NtHeaders) - { - //Print(L"Error - no NT header found in %s\n", FileName); - UiMessageBox("Error - no NT header found"); - FsCloseFile(FileHandle); - return FALSE; - } - - /* Ensure this is executable image */ - if (((NtHeaders->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE) == 0)) - { - //Print(L"Not an executable image %s\n", FileName); - UiMessageBox("Not an executable image"); - FsCloseFile(FileHandle); - return FALSE; - } - - /* Store number of sections to read and a pointer to the first section */ - NumberOfSections = NtHeaders->FileHeader.NumberOfSections; - SectionHeader = IMAGE_FIRST_SECTION(NtHeaders); - - /* Try to allocate this memory, if fails - allocate somewhere else */ - PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage, - (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)), - MemoryType); - - if (PhysicalBase == NULL) - { - /* It's ok, we don't panic - let's allocate again at any other "low" place */ - //MmChangeAllocationPolicy(FALSE); - PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType); - //MmChangeAllocationPolicy(TRUE); - - if (PhysicalBase == NULL) - { - //Print(L"Failed to alloc pages for image %s\n", FileName); - UiMessageBox("Failed to alloc pages for image"); - FsCloseFile(FileHandle); - return FALSE; - } - } - - /* This is the real image base - in form of a virtual address */ - VirtualBase = PaToVa(PhysicalBase); - - DbgPrint((DPRINT_WINDOWS, "Base PA: 0x%X, VA: 0x%X\n", PhysicalBase, VirtualBase)); - - /* Set to 0 position and fully load the file image */ - FsSetFilePointer(FileHandle, 0); - - Status = FsReadFile(FileHandle, NtHeaders->OptionalHeader.SizeOfHeaders, NULL, PhysicalBase); - - if (!Status) - { - //Print(L"Error reading headers %s\n", FileName); - UiMessageBox("Error reading headers"); - FsCloseFile(FileHandle); - return FALSE; - } - - /* Reload the NT Header */ - NtHeaders = RtlImageNtHeader(PhysicalBase); - - /* Load the first section */ - SectionHeader = IMAGE_FIRST_SECTION(NtHeaders); - - /* Fill output parameters */ - *ImageBasePA = PhysicalBase; - - /* Walk through each section and read it (check/fix any possible - bad situations, if they arise) */ - for (i = 0; i < NumberOfSections; i++) - { - VirtualSize = SectionHeader->Misc.VirtualSize; - SizeOfRawData = SectionHeader->SizeOfRawData; - - /* Handle a case when VirtualSize equals 0 */ - if (VirtualSize == 0) - VirtualSize = SizeOfRawData; - - /* If PointerToRawData is 0, then force its size to be also 0 */ - if (SectionHeader->PointerToRawData == 0) - { - SizeOfRawData = 0; - } - else - { - /* Cut the loaded size to the VirtualSize extents */ - if (SizeOfRawData > VirtualSize) - SizeOfRawData = VirtualSize; - } - - /* Actually read the section (if its size is not 0) */ - if (SizeOfRawData != 0) - { - /* Seek to the correct position */ - FsSetFilePointer(FileHandle, SectionHeader->PointerToRawData); - - DbgPrint((DPRINT_WINDOWS, "SH->VA: 0x%X\n", SectionHeader->VirtualAddress)); - - /* Read this section from the file, size = SizeOfRawData */ - Status = FsReadFile(FileHandle, SizeOfRawData, &BytesRead, (PUCHAR)PhysicalBase + SectionHeader->VirtualAddress); - - if (!Status && (BytesRead == 0)) - { - DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): Error reading section from file!\n")); - break; - } - } - - /* Size of data is less than the virtual size - fill up the remainder with zeroes */ - if (SizeOfRawData < VirtualSize) - { - DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): SORD %d < VS %d", SizeOfRawData, VirtualSize)); - RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData); - } - - SectionHeader++; - } - - /* We are done with the file - close it */ - FsCloseFile(FileHandle); - - /* If loading failed - return right now */ - if (!Status) - return FALSE; - - - /* Relocate the image, if it needs it */ - if (NtHeaders->OptionalHeader.ImageBase != (ULONG)VirtualBase) - { - DbgPrint((DPRINT_WINDOWS, "Relocating %p -> %p\n", - NtHeaders->OptionalHeader.ImageBase, VirtualBase)); - Status = (BOOLEAN)LdrRelocateImageWithBias(PhysicalBase, - (ULONG_PTR)VirtualBase - (ULONG_PTR)PhysicalBase, - "FreeLdr", - TRUE, - TRUE, /* in case of conflict still return success */ - FALSE); - } - - return Status; -} - -/* PRIVATE FUNCTIONS *******************************************************/ - -/* DllName - physical, UnicodeString->Buffer - virtual */ -BOOLEAN -WinLdrpCompareDllName(IN PCH DllName, - IN PUNICODE_STRING UnicodeName) -{ - PWSTR Buffer; - UNICODE_STRING UnicodeNamePA; - ULONG i, Length; - - /* First obvious check: for length of two names */ - Length = strlen(DllName); - - UnicodeNamePA.Length = UnicodeName->Length; - UnicodeNamePA.MaximumLength = UnicodeName->MaximumLength; - UnicodeNamePA.Buffer = VaToPa(UnicodeName->Buffer); - DbgPrint((DPRINT_WINDOWS, "WinLdrpCompareDllName: %s and %wZ, Length = %d " - "UN->Length %d\n", DllName, &UnicodeNamePA, Length, UnicodeName->Length)); - - if ((Length * sizeof(WCHAR)) > UnicodeName->Length) - return FALSE; - - /* Store pointer to unicode string's buffer */ - Buffer = VaToPa(UnicodeName->Buffer); - - /* Loop character by character */ - for (i = 0; i < Length; i++) - { - /* Compare two characters, uppercasing them */ - if (toupper(*DllName) != toupper((CHAR)*Buffer)) - return FALSE; - - /* Move to the next character */ - DllName++; - Buffer++; - } - - /* Check, if strings either fully match, or match till the "." (w/o extension) */ - if ((UnicodeName->Length == Length * sizeof(WCHAR)) || (*Buffer == L'.')) - { - /* Yes they do */ - return TRUE; - } - - /* Strings don't match, return FALSE */ - return FALSE; -} - -BOOLEAN -WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PVOID DllBase, - IN PVOID ImageBase, - IN PIMAGE_THUNK_DATA ThunkData, - IN PIMAGE_EXPORT_DIRECTORY ExportDirectory, - IN ULONG ExportSize, - IN BOOLEAN ProcessForwards) -{ - ULONG Ordinal; - PULONG NameTable, FunctionTable; - PUSHORT OrdinalTable; - LONG High, Low, Middle, Result; - ULONG Hint; - - //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): DllBase 0x%X, ImageBase 0x%X, ThunkData 0x%X, ExportDirectory 0x%X, ExportSize %d, ProcessForwards 0x%X\n", - // DllBase, ImageBase, ThunkData, ExportDirectory, ExportSize, ProcessForwards)); - - /* Check passed DllBase param */ - if(DllBase == NULL) - { - DbgPrint((DPRINT_WINDOWS, "WARNING: DllBase == NULL!\n")); - return FALSE; - } - - /* Convert all non-critical pointers to PA from VA */ - ThunkData = VaToPa(ThunkData); - - /* Is the reference by ordinal? */ - if (IMAGE_SNAP_BY_ORDINAL(ThunkData->u1.Ordinal) && !ProcessForwards) - { - /* Yes, calculate the ordinal */ - Ordinal = (ULONG)(IMAGE_ORDINAL(ThunkData->u1.Ordinal) - (UINT32)ExportDirectory->Base); - //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal)); - } - else - { - /* It's reference by name, we have to look it up in the export directory */ - if (!ProcessForwards) - { - /* AddressOfData in thunk entry will become a virtual address (from relative) */ - //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD was %p\n", ThunkData->u1.AddressOfData)); - ThunkData->u1.AddressOfData = - (ULONG)RVA(ImageBase, ThunkData->u1.AddressOfData); - //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD became %p\n", ThunkData->u1.AddressOfData)); - } - - /* Get pointers to Name and Ordinal tables (RVA -> VA) */ - NameTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNames)); - OrdinalTable = (PUSHORT)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNameOrdinals)); - - //DbgPrint((DPRINT_WINDOWS, "NameTable 0x%X, OrdinalTable 0x%X, ED->AddressOfNames 0x%X, ED->AOFO 0x%X\n", - // NameTable, OrdinalTable, ExportDirectory->AddressOfNames, ExportDirectory->AddressOfNameOrdinals)); - - /* Get the hint, convert it to a physical pointer */ - Hint = ((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Hint; - //DbgPrint((DPRINT_WINDOWS, "HintIndex %d\n", Hint)); - - /* If Hint is less than total number of entries in the export directory, - and import name == export name, then we can just get it from the OrdinalTable */ - if ( - (Hint < ExportDirectory->NumberOfNames) && - ( - strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]), - (PCHAR)VaToPa( RVA(DllBase, NameTable[Hint])) ) == 0 - ) - ) - { - Ordinal = OrdinalTable[Hint]; - //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal)); - } - else - { - /* It's not the easy way, we have to lookup import name in the name table. - Let's use a binary search for this task. */ - - //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() looking up the import name using binary search...\n")); - - /* Low boundary is set to 0, and high boundary to the maximum index */ - Low = 0; - High = ExportDirectory->NumberOfNames - 1; - - /* Perform a binary-search loop */ - while (High >= Low) - { - /* Divide by 2 by shifting to the right once */ - Middle = (Low + High) >> 1; - - /* Compare the names */ - Result = strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]), - (PCHAR)VaToPa(RVA(DllBase, NameTable[Middle]))); - - /*DbgPrint((DPRINT_WINDOWS, "Binary search: comparing Import '__', Export '%s'\n",*/ - /*VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name[0]),*/ - /*(PCHAR)VaToPa(RVA(DllBase, NameTable[Middle]))));*/ - - /*DbgPrint((DPRINT_WINDOWS, "TE->u1.AOD %p, fulladdr %p\n", - ThunkData->u1.AddressOfData, - ((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name ));*/ - - - /* Depending on result of strcmp, perform different actions */ - if (Result < 0) - { - /* Adjust top boundary */ - High = Middle - 1; - } - else if (Result > 0) - { - /* Adjust bottom boundary */ - Low = Middle + 1; - } - else - { - /* Yay, found it! */ - break; - } - } - - /* If high boundary is less than low boundary, then no result found */ - if (High < Low) - { - //Print(L"Error in binary search\n"); - DbgPrint((DPRINT_WINDOWS, "Error in binary search!\n")); - return FALSE; - } - - /* Everything allright, get the ordinal */ - Ordinal = OrdinalTable[Middle]; - - //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() found Ordinal %d\n", Ordinal)); - } - } - - /* Check ordinal number for validity! */ - if (Ordinal >= ExportDirectory->NumberOfFunctions) - { - DbgPrint((DPRINT_WINDOWS, "Ordinal number is invalid!\n")); - return FALSE; - } - - /* Get a pointer to the function table */ - FunctionTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfFunctions)); - - /* Save a pointer to the function */ - ThunkData->u1.Function = (ULONG)RVA(DllBase, FunctionTable[Ordinal]); - - /* Is it a forwarder? (function pointer isn't within the export directory) */ - if (((ULONG)VaToPa((PVOID)ThunkData->u1.Function) > (ULONG)ExportDirectory) && - ((ULONG)VaToPa((PVOID)ThunkData->u1.Function) < ((ULONG)ExportDirectory + ExportSize))) - { - PLDR_DATA_TABLE_ENTRY DataTableEntry; - CHAR ForwardDllName[255]; - PIMAGE_EXPORT_DIRECTORY RefExportDirectory; - ULONG RefExportSize; - - /* Save the name of the forward dll */ - RtlCopyMemory(ForwardDllName, (PCHAR)VaToPa((PVOID)ThunkData->u1.Function), sizeof(ForwardDllName)); - - /* Strip out its extension */ - *strchr(ForwardDllName,'.') = '\0'; - - DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ForwardDllName %s\n", ForwardDllName)); - if (!WinLdrCheckForLoadedDll(WinLdrBlock, ForwardDllName, &DataTableEntry)) - { - /* We can't continue if DLL couldn't be loaded, so bomb out with an error */ - //Print(L"Error loading DLL!\n"); - DbgPrint((DPRINT_WINDOWS, "Error loading DLL!\n")); - return FALSE; - } - - /* Get pointer to the export directory of loaded DLL */ - RefExportDirectory = (PIMAGE_EXPORT_DIRECTORY) - RtlImageDirectoryEntryToData(VaToPa(DataTableEntry->DllBase), - TRUE, - IMAGE_DIRECTORY_ENTRY_EXPORT, - &RefExportSize); - - /* Fail if it's NULL */ - if (RefExportDirectory) - { - UCHAR Buffer[128]; - IMAGE_THUNK_DATA RefThunkData; - PIMAGE_IMPORT_BY_NAME ImportByName; - PCHAR ImportName; - BOOLEAN Status; - - /* Get pointer to the import name */ - ImportName = strchr((PCHAR)VaToPa((PVOID)ThunkData->u1.Function), '.') + 1; - - /* Create a IMAGE_IMPORT_BY_NAME structure, pointing to the local Buffer */ - ImportByName = (PIMAGE_IMPORT_BY_NAME)Buffer; - - /* Fill the name with the import name */ - RtlCopyMemory(ImportByName->Name, ImportName, strlen(ImportName)+1); - - /* Set Hint to 0 */ - ImportByName->Hint = 0; - - /* And finally point ThunkData's AddressOfData to that structure */ - RefThunkData.u1.AddressOfData = (ULONG)ImportByName; - - /* And recursively call ourselves */ - Status = WinLdrpBindImportName( - WinLdrBlock, - DataTableEntry->DllBase, - ImageBase, - &RefThunkData, - RefExportDirectory, - RefExportSize, - TRUE); - - /* Fill out the ThunkData with data from RefThunkData */ - ThunkData->u1 = RefThunkData.u1; - - /* Return what we got from the recursive call */ - return Status; - } - else - { - /* Fail if ExportDirectory is NULL */ - return FALSE; - } - } - - /* Success! */ - return TRUE; -} - -BOOLEAN -WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock, - PCCH DirectoryPath, - PCH ImportName, - PLDR_DATA_TABLE_ENTRY *DataTableEntry) -{ - CHAR FullDllName[256]; - BOOLEAN Status; - PVOID BasePA; - - /* Prepare the full path to the file to be loaded */ - strcpy(FullDllName, DirectoryPath); - strcat(FullDllName, ImportName); - - DbgPrint((DPRINT_WINDOWS, "Loading referenced DLL: %s\n", FullDllName)); - //Print(L"Loading referenced DLL: %s\n", FullDllName); - - /* Load the image */ - Status = WinLdrLoadImage(FullDllName, LoaderHalCode, &BasePA); - - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage() failed\n")); - return Status; - } - - /* Allocate DTE for newly loaded DLL */ - Status = WinLdrAllocateDataTableEntry(WinLdrBlock, - ImportName, - FullDllName, - BasePA, - DataTableEntry); - - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, - "WinLdrAllocateDataTableEntry() failed with Status=0x%X\n", Status)); - return Status; - } - - /* Scan its dependencies too */ - DbgPrint((DPRINT_WINDOWS, - "WinLdrScanImportDescriptorTable() calling ourselves for %S\n", - VaToPa((*DataTableEntry)->BaseDllName.Buffer))); - Status = WinLdrScanImportDescriptorTable(WinLdrBlock, DirectoryPath, *DataTableEntry); - - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, - "WinLdrScanImportDescriptorTable() failed with Status=0x%X\n", Status)); - return Status; - } - - return TRUE; -} - -BOOLEAN -WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PVOID DllBase, - IN PVOID ImageBase, - IN PIMAGE_THUNK_DATA ThunkData) -{ - PIMAGE_EXPORT_DIRECTORY ExportDirectory = NULL; - BOOLEAN Status; - ULONG ExportSize; - - DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): DllBase 0x%X, " - "ImageBase 0x%X, ThunkData 0x%X\n", DllBase, ImageBase, ThunkData)); - - /* Obtain the export table from the DLL's base */ - if (DllBase == NULL) - { - //Print(L"Error, DllBase == NULL!\n"); - return FALSE; - } - else - { - ExportDirectory = - (PIMAGE_EXPORT_DIRECTORY)RtlImageDirectoryEntryToData(VaToPa(DllBase), - TRUE, - IMAGE_DIRECTORY_ENTRY_EXPORT, - &ExportSize); - } - - DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): ExportDirectory 0x%X\n", ExportDirectory)); - - /* If pointer to Export Directory is */ - if (ExportDirectory == NULL) - return FALSE; - - /* Go through each entry in the thunk table and bind it */ - while (((PIMAGE_THUNK_DATA)VaToPa(ThunkData))->u1.AddressOfData != 0) - { - /* Bind it */ - Status = WinLdrpBindImportName( - WinLdrBlock, - DllBase, - ImageBase, - ThunkData, - ExportDirectory, - ExportSize, - FALSE); - - /* Move to the next entry */ - ThunkData++; - - /* Return error if binding was unsuccessful */ - if (!Status) - return Status; - } - - /* Return success */ - return TRUE; -} +/* + * PROJECT: FreeLoader + * LICENSE: GPL - See COPYING in the top level directory + * FILE: freeldr/winldr/peloader.c + * PURPOSE: Provides routines for loading PE files. To be merged with + * arch/i386/loader.c in future + * This article was very handy during development: + *
http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/
+ * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org) + * The source code in this file is based on the work of respective + * authors of PE loading code in ReactOS and Brian Palmer and + * Alex Ionescu's arch/i386/loader.c, and my research project + * (creating a native EFI loader for Windows) + */ + +/* INCLUDES ***************************************************************/ +#include <freeldr.h> +#include <debug.h> + + +BOOLEAN +WinLdrpCompareDllName(IN PCH DllName, + IN PUNICODE_STRING UnicodeName); + +BOOLEAN +WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PVOID DllBase, + IN PVOID ImageBase, + IN PIMAGE_THUNK_DATA ThunkData, + IN PIMAGE_EXPORT_DIRECTORY ExportDirectory, + IN ULONG ExportSize, + IN BOOLEAN ProcessForwards); + +BOOLEAN +WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock, + PCCH DirectoryPath, + PCH ImportName, + PLDR_DATA_TABLE_ENTRY *DataTableEntry); + +BOOLEAN +WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PVOID DllBase, + IN PVOID ImageBase, + IN PIMAGE_THUNK_DATA ThunkData); + + + +/* FUNCTIONS **************************************************************/ + +/* Returns TRUE if DLL has already been loaded - looks in LoadOrderList in LPB */ +BOOLEAN +WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PCH DllName, + OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry) +{ + PLDR_DATA_TABLE_ENTRY DataTableEntry; + LIST_ENTRY *ModuleEntry; + + DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DllName %X, LoadedEntry: %X\n", + DllName, LoadedEntry)); + + /* Just go through each entry in the LoadOrderList and compare loaded module's + name with a given name */ + ModuleEntry = WinLdrBlock->LoadOrderListHead.Flink; + while (ModuleEntry != &WinLdrBlock->LoadOrderListHead) + { + /* Get pointer to the current DTE */ + DataTableEntry = CONTAINING_RECORD(ModuleEntry, + LDR_DATA_TABLE_ENTRY, + InLoadOrderLinks); + + DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DTE %p, EP %p\n", + DataTableEntry, DataTableEntry->EntryPoint)); + + /* Compare names */ + if (WinLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName)) + { + /* Yes, found it, report pointer to the loaded module's DTE + to the caller and increase load count for it */ + *LoadedEntry = DataTableEntry; + DataTableEntry->LoadCount++; + DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: LoadedEntry %X\n", DataTableEntry)); + return TRUE; + } + + /* Go to the next entry */ + ModuleEntry = ModuleEntry->Flink; + } + + /* Nothing found */ + return FALSE; +} + +BOOLEAN +WinLdrScanImportDescriptorTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PCCH DirectoryPath, + IN PLDR_DATA_TABLE_ENTRY ScanDTE) +{ + PLDR_DATA_TABLE_ENTRY DataTableEntry; + PIMAGE_IMPORT_DESCRIPTOR ImportTable; + ULONG ImportTableSize; + PCH ImportName; + BOOLEAN Status; + + /* Get a pointer to the import table of this image */ + ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase), + TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize); + + { + UNICODE_STRING BaseName; + BaseName.Buffer = VaToPa(ScanDTE->BaseDllName.Buffer); + BaseName.MaximumLength = ScanDTE->BaseDllName.MaximumLength; + BaseName.Length = ScanDTE->BaseDllName.Length; + DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%X\n", + &BaseName, ImportTable)); + } + + /* If image doesn't have any import directory - just return success */ + if (ImportTable == NULL) + return TRUE; + + /* Loop through all entries */ + for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++) + { + /* Get pointer to the name */ + ImportName = (PCH)VaToPa(RVA(ScanDTE->DllBase, ImportTable->Name)); + DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): Looking at %s\n", ImportName)); + + /* In case we get a reference to ourselves - just skip it */ + if (WinLdrpCompareDllName(ImportName, &ScanDTE->BaseDllName)) + continue; + + /* Load the DLL if it is not already loaded */ + if (!WinLdrCheckForLoadedDll(WinLdrBlock, ImportName, &DataTableEntry)) + { + Status = WinLdrpLoadAndScanReferencedDll(WinLdrBlock, + DirectoryPath, + ImportName, + &DataTableEntry); + + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, "WinLdrpLoadAndScanReferencedDll() failed\n")); + return Status; + } + } + + /* Scan its import address table */ + Status = WinLdrpScanImportAddressTable( + WinLdrBlock, + DataTableEntry->DllBase, + ScanDTE->DllBase, + (PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk)); + + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable() failed\n")); + return Status; + } + } + + return TRUE; +} + +BOOLEAN +WinLdrAllocateDataTableEntry(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PCCH BaseDllName, + IN PCCH FullDllName, + IN PVOID BasePA, + OUT PLDR_DATA_TABLE_ENTRY *NewEntry) +{ + PVOID BaseVA = PaToVa(BasePA); + PWSTR Buffer; + PLDR_DATA_TABLE_ENTRY DataTableEntry; + PIMAGE_NT_HEADERS NtHeaders; + USHORT Length; + + /* Allocate memory for a data table entry, zero-initialize it */ + DataTableEntry = (PLDR_DATA_TABLE_ENTRY)MmHeapAlloc(sizeof(LDR_DATA_TABLE_ENTRY)); + if (DataTableEntry == NULL) + return FALSE; + RtlZeroMemory(DataTableEntry, sizeof(LDR_DATA_TABLE_ENTRY)); + + /* Get NT headers from the image */ + NtHeaders = RtlImageNtHeader(BasePA); + + /* Initialize corresponding fields of DTE based on NT headers value */ + DataTableEntry->DllBase = BaseVA; + DataTableEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage; + DataTableEntry->EntryPoint = RVA(BaseVA, NtHeaders->OptionalHeader.AddressOfEntryPoint); + DataTableEntry->SectionPointer = 0; + DataTableEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum; + + /* Initialize BaseDllName field (UNICODE_STRING) from the Ansi BaseDllName + by simple conversion - copying each character */ + Length = (USHORT)(strlen(BaseDllName) * sizeof(WCHAR)); + Buffer = (PWSTR)MmHeapAlloc(Length); + if (Buffer == NULL) + { + MmHeapFree(DataTableEntry); + return FALSE; + } + RtlZeroMemory(Buffer, Length); + + DataTableEntry->BaseDllName.Length = Length; + DataTableEntry->BaseDllName.MaximumLength = Length; + DataTableEntry->BaseDllName.Buffer = PaToVa(Buffer); + while (*BaseDllName != 0) + { + *Buffer++ = *BaseDllName++; + } + + /* Initialize FullDllName field (UNICODE_STRING) from the Ansi FullDllName + using the same method */ + Length = (USHORT)(strlen(FullDllName) * sizeof(WCHAR)); + Buffer = (PWSTR)MmHeapAlloc(Length); + if (Buffer == NULL) + { + MmHeapFree(DataTableEntry); + return FALSE; + } + RtlZeroMemory(Buffer, Length); + + DataTableEntry->FullDllName.Length = Length; + DataTableEntry->FullDllName.MaximumLength = Length; + DataTableEntry->FullDllName.Buffer = PaToVa(Buffer); + while (*FullDllName != 0) + { + *Buffer++ = *FullDllName++; + } + + /* Initialize what's left - LoadCount which is 1, and set Flags so that + we know this entry is processed */ + DataTableEntry->Flags = LDRP_ENTRY_PROCESSED; + DataTableEntry->LoadCount = 1; + + /* Insert this DTE to a list in the LPB */ + InsertTailList(&WinLdrBlock->LoadOrderListHead, &DataTableEntry->InLoadOrderLinks); + + /* Save pointer to a newly allocated and initialized entry */ + *NewEntry = DataTableEntry; + + /* Return success */ + return TRUE; +} + +/* WinLdrLoadImage loads the specified image from the file (it doesn't + perform any additional operations on the filename, just directly + calls the file I/O routines), and relocates it so that it's ready + to be used when paging is enabled. + Addressing mode: physical + */ +BOOLEAN +WinLdrLoadImage(IN PCHAR FileName, + TYPE_OF_MEMORY MemoryType, + OUT PVOID *ImageBasePA) +{ + PFILE FileHandle; + PVOID PhysicalBase; + PVOID VirtualBase = NULL; + UCHAR HeadersBuffer[SECTOR_SIZE * 2]; + PIMAGE_NT_HEADERS NtHeaders; + PIMAGE_SECTION_HEADER SectionHeader; + ULONG VirtualSize, SizeOfRawData, NumberOfSections; + BOOLEAN Status; + ULONG i, BytesRead; + + CHAR ProgressString[256]; + + /* Inform user we are loading files */ + sprintf(ProgressString, "Loading %s...", FileName); + UiDrawProgressBarCenter(1, 100, ProgressString); + + /* Open the image file */ + FileHandle = FsOpenFile(FileName); + + if (FileHandle == NULL) + { + //Print(L"Can not open the file %s\n",FileName); + UiMessageBox("Can not open the file"); + return FALSE; + } + + /* Load the first 2 sectors of the image so we can read the PE header */ + Status = FsReadFile(FileHandle, SECTOR_SIZE * 2, NULL, HeadersBuffer); + if (!Status) + { + //Print(L"Error reading from file %s\n", FileName); + UiMessageBox("Error reading from file"); + FsCloseFile(FileHandle); + return FALSE; + } + + /* Now read the MZ header to get the offset to the PE Header */ + NtHeaders = RtlImageNtHeader(HeadersBuffer); + + if (!NtHeaders) + { + //Print(L"Error - no NT header found in %s\n", FileName); + UiMessageBox("Error - no NT header found"); + FsCloseFile(FileHandle); + return FALSE; + } + + /* Ensure this is executable image */ + if (((NtHeaders->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE) == 0)) + { + //Print(L"Not an executable image %s\n", FileName); + UiMessageBox("Not an executable image"); + FsCloseFile(FileHandle); + return FALSE; + } + + /* Store number of sections to read and a pointer to the first section */ + NumberOfSections = NtHeaders->FileHeader.NumberOfSections; + SectionHeader = IMAGE_FIRST_SECTION(NtHeaders); + + /* Try to allocate this memory, if fails - allocate somewhere else */ + PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage, + (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)), + MemoryType); + + if (PhysicalBase == NULL) + { + /* It's ok, we don't panic - let's allocate again at any other "low" place */ + PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType); + + if (PhysicalBase == NULL) + { + //Print(L"Failed to alloc pages for image %s\n", FileName); + UiMessageBox("Failed to alloc pages for image"); + FsCloseFile(FileHandle); + return FALSE; + } + } + + /* This is the real image base - in form of a virtual address */ + VirtualBase = PaToVa(PhysicalBase); + + DbgPrint((DPRINT_WINDOWS, "Base PA: 0x%X, VA: 0x%X\n", PhysicalBase, VirtualBase)); + + /* Set to 0 position and fully load the file image */ + FsSetFilePointer(FileHandle, 0); + + Status = FsReadFile(FileHandle, NtHeaders->OptionalHeader.SizeOfHeaders, NULL, PhysicalBase); + + if (!Status) + { + //Print(L"Error reading headers %s\n", FileName); + UiMessageBox("Error reading headers"); + FsCloseFile(FileHandle); + return FALSE; + } + + /* Reload the NT Header */ + NtHeaders = RtlImageNtHeader(PhysicalBase); + + /* Load the first section */ + SectionHeader = IMAGE_FIRST_SECTION(NtHeaders); + + /* Fill output parameters */ + *ImageBasePA = PhysicalBase; + + /* Walk through each section and read it (check/fix any possible + bad situations, if they arise) */ + for (i = 0; i < NumberOfSections; i++) + { + VirtualSize = SectionHeader->Misc.VirtualSize; + SizeOfRawData = SectionHeader->SizeOfRawData; + + /* Handle a case when VirtualSize equals 0 */ + if (VirtualSize == 0) + VirtualSize = SizeOfRawData; + + /* If PointerToRawData is 0, then force its size to be also 0 */ + if (SectionHeader->PointerToRawData == 0) + { + SizeOfRawData = 0; + } + else + { + /* Cut the loaded size to the VirtualSize extents */ + if (SizeOfRawData > VirtualSize) + SizeOfRawData = VirtualSize; + } + + /* Actually read the section (if its size is not 0) */ + if (SizeOfRawData != 0) + { + /* Seek to the correct position */ + FsSetFilePointer(FileHandle, SectionHeader->PointerToRawData); + + DbgPrint((DPRINT_WINDOWS, "SH->VA: 0x%X\n", SectionHeader->VirtualAddress)); + + /* Read this section from the file, size = SizeOfRawData */ + Status = FsReadFile(FileHandle, SizeOfRawData, &BytesRead, (PUCHAR)PhysicalBase + SectionHeader->VirtualAddress); + + if (!Status && (BytesRead == 0)) + { + DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): Error reading section from file!\n")); + break; + } + } + + /* Size of data is less than the virtual size - fill up the remainder with zeroes */ + if (SizeOfRawData < VirtualSize) + { + DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): SORD %d < VS %d", SizeOfRawData, VirtualSize)); + RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData); + } + + SectionHeader++; + } + + /* We are done with the file - close it */ + FsCloseFile(FileHandle); + + /* If loading failed - return right now */ + if (!Status) + return FALSE; + + + /* Relocate the image, if it needs it */ + if (NtHeaders->OptionalHeader.ImageBase != (ULONG)VirtualBase) + { + DbgPrint((DPRINT_WINDOWS, "Relocating %p -> %p\n", + NtHeaders->OptionalHeader.ImageBase, VirtualBase)); + Status = (BOOLEAN)LdrRelocateImageWithBias(PhysicalBase, + (ULONG_PTR)VirtualBase - (ULONG_PTR)PhysicalBase, + "FreeLdr", + TRUE, + TRUE, /* in case of conflict still return success */ + FALSE); + } + + return Status; +} + +/* PRIVATE FUNCTIONS *******************************************************/ + +/* DllName - physical, UnicodeString->Buffer - virtual */ +BOOLEAN +WinLdrpCompareDllName(IN PCH DllName, + IN PUNICODE_STRING UnicodeName) +{ + PWSTR Buffer; + UNICODE_STRING UnicodeNamePA; + ULONG i, Length; + + /* First obvious check: for length of two names */ + Length = strlen(DllName); + + UnicodeNamePA.Length = UnicodeName->Length; + UnicodeNamePA.MaximumLength = UnicodeName->MaximumLength; + UnicodeNamePA.Buffer = VaToPa(UnicodeName->Buffer); + DbgPrint((DPRINT_WINDOWS, "WinLdrpCompareDllName: %s and %wZ, Length = %d " + "UN->Length %d\n", DllName, &UnicodeNamePA, Length, UnicodeName->Length)); + + if ((Length * sizeof(WCHAR)) > UnicodeName->Length) + return FALSE; + + /* Store pointer to unicode string's buffer */ + Buffer = VaToPa(UnicodeName->Buffer); + + /* Loop character by character */ + for (i = 0; i < Length; i++) + { + /* Compare two characters, uppercasing them */ + if (toupper(*DllName) != toupper((CHAR)*Buffer)) + return FALSE; + + /* Move to the next character */ + DllName++; + Buffer++; + } + + /* Check, if strings either fully match, or match till the "." (w/o extension) */ + if ((UnicodeName->Length == Length * sizeof(WCHAR)) || (*Buffer == L'.')) + { + /* Yes they do */ + return TRUE; + } + + /* Strings don't match, return FALSE */ + return FALSE; +} + +BOOLEAN +WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PVOID DllBase, + IN PVOID ImageBase, + IN PIMAGE_THUNK_DATA ThunkData, + IN PIMAGE_EXPORT_DIRECTORY ExportDirectory, + IN ULONG ExportSize, + IN BOOLEAN ProcessForwards) +{ + ULONG Ordinal; + PULONG NameTable, FunctionTable; + PUSHORT OrdinalTable; + LONG High, Low, Middle, Result; + ULONG Hint; + + //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): DllBase 0x%X, ImageBase 0x%X, ThunkData 0x%X, ExportDirectory 0x%X, ExportSize %d, ProcessForwards 0x%X\n", + // DllBase, ImageBase, ThunkData, ExportDirectory, ExportSize, ProcessForwards)); + + /* Check passed DllBase param */ + if(DllBase == NULL) + { + DbgPrint((DPRINT_WINDOWS, "WARNING: DllBase == NULL!\n")); + return FALSE; + } + + /* Convert all non-critical pointers to PA from VA */ + ThunkData = VaToPa(ThunkData); + + /* Is the reference by ordinal? */ + if (IMAGE_SNAP_BY_ORDINAL(ThunkData->u1.Ordinal) && !ProcessForwards) + { + /* Yes, calculate the ordinal */ + Ordinal = (ULONG)(IMAGE_ORDINAL(ThunkData->u1.Ordinal) - (UINT32)ExportDirectory->Base); + //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal)); + } + else + { + /* It's reference by name, we have to look it up in the export directory */ + if (!ProcessForwards) + { + /* AddressOfData in thunk entry will become a virtual address (from relative) */ + //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD was %p\n", ThunkData->u1.AddressOfData)); + ThunkData->u1.AddressOfData = + (ULONG)RVA(ImageBase, ThunkData->u1.AddressOfData); + //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD became %p\n", ThunkData->u1.AddressOfData)); + } + + /* Get pointers to Name and Ordinal tables (RVA -> VA) */ + NameTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNames)); + OrdinalTable = (PUSHORT)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNameOrdinals)); + + //DbgPrint((DPRINT_WINDOWS, "NameTable 0x%X, OrdinalTable 0x%X, ED->AddressOfNames 0x%X, ED->AOFO 0x%X\n", + // NameTable, OrdinalTable, ExportDirectory->AddressOfNames, ExportDirectory->AddressOfNameOrdinals)); + + /* Get the hint, convert it to a physical pointer */ + Hint = ((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Hint; + //DbgPrint((DPRINT_WINDOWS, "HintIndex %d\n", Hint)); + + /* If Hint is less than total number of entries in the export directory, + and import name == export name, then we can just get it from the OrdinalTable */ + if ( + (Hint < ExportDirectory->NumberOfNames) && + ( + strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]), + (PCHAR)VaToPa( RVA(DllBase, NameTable[Hint])) ) == 0 + ) + ) + { + Ordinal = OrdinalTable[Hint]; + //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal)); + } + else + { + /* It's not the easy way, we have to lookup import name in the name table. + Let's use a binary search for this task. */ + + //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() looking up the import name using binary search...\n")); + + /* Low boundary is set to 0, and high boundary to the maximum index */ + Low = 0; + High = ExportDirectory->NumberOfNames - 1; + + /* Perform a binary-search loop */ + while (High >= Low) + { + /* Divide by 2 by shifting to the right once */ + Middle = (Low + High) >> 1; + + /* Compare the names */ + Result = strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]), + (PCHAR)VaToPa(RVA(DllBase, NameTable[Middle]))); + + /*DbgPrint((DPRINT_WINDOWS, "Binary search: comparing Import '__', Export '%s'\n",*/ + /*VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name[0]),*/ + /*(PCHAR)VaToPa(RVA(DllBase, NameTable[Middle]))));*/ + + /*DbgPrint((DPRINT_WINDOWS, "TE->u1.AOD %p, fulladdr %p\n", + ThunkData->u1.AddressOfData, + ((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name ));*/ + + + /* Depending on result of strcmp, perform different actions */ + if (Result < 0) + { + /* Adjust top boundary */ + High = Middle - 1; + } + else if (Result > 0) + { + /* Adjust bottom boundary */ + Low = Middle + 1; + } + else + { + /* Yay, found it! */ + break; + } + } + + /* If high boundary is less than low boundary, then no result found */ + if (High < Low) + { + //Print(L"Error in binary search\n"); + DbgPrint((DPRINT_WINDOWS, "Error in binary search!\n")); + return FALSE; + } + + /* Everything allright, get the ordinal */ + Ordinal = OrdinalTable[Middle]; + + //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() found Ordinal %d\n", Ordinal)); + } + } + + /* Check ordinal number for validity! */ + if (Ordinal >= ExportDirectory->NumberOfFunctions) + { + DbgPrint((DPRINT_WINDOWS, "Ordinal number is invalid!\n")); + return FALSE; + } + + /* Get a pointer to the function table */ + FunctionTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfFunctions)); + + /* Save a pointer to the function */ + ThunkData->u1.Function = (ULONG)RVA(DllBase, FunctionTable[Ordinal]); + + /* Is it a forwarder? (function pointer isn't within the export directory) */ + if (((ULONG)VaToPa((PVOID)ThunkData->u1.Function) > (ULONG)ExportDirectory) && + ((ULONG)VaToPa((PVOID)ThunkData->u1.Function) < ((ULONG)ExportDirectory + ExportSize))) + { + PLDR_DATA_TABLE_ENTRY DataTableEntry; + CHAR ForwardDllName[255]; + PIMAGE_EXPORT_DIRECTORY RefExportDirectory; + ULONG RefExportSize; + + /* Save the name of the forward dll */ + RtlCopyMemory(ForwardDllName, (PCHAR)VaToPa((PVOID)ThunkData->u1.Function), sizeof(ForwardDllName)); + + /* Strip out its extension */ + *strchr(ForwardDllName,'.') = '\0'; + + DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ForwardDllName %s\n", ForwardDllName)); + if (!WinLdrCheckForLoadedDll(WinLdrBlock, ForwardDllName, &DataTableEntry)) + { + /* We can't continue if DLL couldn't be loaded, so bomb out with an error */ + //Print(L"Error loading DLL!\n"); + DbgPrint((DPRINT_WINDOWS, "Error loading DLL!\n")); + return FALSE; + } + + /* Get pointer to the export directory of loaded DLL */ + RefExportDirectory = (PIMAGE_EXPORT_DIRECTORY) + RtlImageDirectoryEntryToData(VaToPa(DataTableEntry->DllBase), + TRUE, + IMAGE_DIRECTORY_ENTRY_EXPORT, + &RefExportSize); + + /* Fail if it's NULL */ + if (RefExportDirectory) + { + UCHAR Buffer[128]; + IMAGE_THUNK_DATA RefThunkData; + PIMAGE_IMPORT_BY_NAME ImportByName; + PCHAR ImportName; + BOOLEAN Status; + + /* Get pointer to the import name */ + ImportName = strchr((PCHAR)VaToPa((PVOID)ThunkData->u1.Function), '.') + 1; + + /* Create a IMAGE_IMPORT_BY_NAME structure, pointing to the local Buffer */ + ImportByName = (PIMAGE_IMPORT_BY_NAME)Buffer; + + /* Fill the name with the import name */ + RtlCopyMemory(ImportByName->Name, ImportName, strlen(ImportName)+1); + + /* Set Hint to 0 */ + ImportByName->Hint = 0; + + /* And finally point ThunkData's AddressOfData to that structure */ + RefThunkData.u1.AddressOfData = (ULONG)ImportByName; + + /* And recursively call ourselves */ + Status = WinLdrpBindImportName( + WinLdrBlock, + DataTableEntry->DllBase, + ImageBase, + &RefThunkData, + RefExportDirectory, + RefExportSize, + TRUE); + + /* Fill out the ThunkData with data from RefThunkData */ + ThunkData->u1 = RefThunkData.u1; + + /* Return what we got from the recursive call */ + return Status; + } + else + { + /* Fail if ExportDirectory is NULL */ + return FALSE; + } + } + + /* Success! */ + return TRUE; +} + +BOOLEAN +WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock, + PCCH DirectoryPath, + PCH ImportName, + PLDR_DATA_TABLE_ENTRY *DataTableEntry) +{ + CHAR FullDllName[256]; + BOOLEAN Status; + PVOID BasePA; + + /* Prepare the full path to the file to be loaded */ + strcpy(FullDllName, DirectoryPath); + strcat(FullDllName, ImportName); + + DbgPrint((DPRINT_WINDOWS, "Loading referenced DLL: %s\n", FullDllName)); + //Print(L"Loading referenced DLL: %s\n", FullDllName); + + /* Load the image */ + Status = WinLdrLoadImage(FullDllName, LoaderHalCode, &BasePA); + + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage() failed\n")); + return Status; + } + + /* Allocate DTE for newly loaded DLL */ + Status = WinLdrAllocateDataTableEntry(WinLdrBlock, + ImportName, + FullDllName, + BasePA, + DataTableEntry); + + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, + "WinLdrAllocateDataTableEntry() failed with Status=0x%X\n", Status)); + return Status; + } + + /* Scan its dependencies too */ + DbgPrint((DPRINT_WINDOWS, + "WinLdrScanImportDescriptorTable() calling ourselves for %S\n", + VaToPa((*DataTableEntry)->BaseDllName.Buffer))); + Status = WinLdrScanImportDescriptorTable(WinLdrBlock, DirectoryPath, *DataTableEntry); + + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, + "WinLdrScanImportDescriptorTable() failed with Status=0x%X\n", Status)); + return Status; + } + + return TRUE; +} + +BOOLEAN +WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PVOID DllBase, + IN PVOID ImageBase, + IN PIMAGE_THUNK_DATA ThunkData) +{ + PIMAGE_EXPORT_DIRECTORY ExportDirectory = NULL; + BOOLEAN Status; + ULONG ExportSize; + + DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): DllBase 0x%X, " + "ImageBase 0x%X, ThunkData 0x%X\n", DllBase, ImageBase, ThunkData)); + + /* Obtain the export table from the DLL's base */ + if (DllBase == NULL) + { + //Print(L"Error, DllBase == NULL!\n"); + return FALSE; + } + else + { + ExportDirectory = + (PIMAGE_EXPORT_DIRECTORY)RtlImageDirectoryEntryToData(VaToPa(DllBase), + TRUE, + IMAGE_DIRECTORY_ENTRY_EXPORT, + &ExportSize); + } + + DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): ExportDirectory 0x%X\n", ExportDirectory)); + + /* If pointer to Export Directory is */ + if (ExportDirectory == NULL) + return FALSE; + + /* Go through each entry in the thunk table and bind it */ + while (((PIMAGE_THUNK_DATA)VaToPa(ThunkData))->u1.AddressOfData != 0) + { + /* Bind it */ + Status = WinLdrpBindImportName( + WinLdrBlock, + DllBase, + ImageBase, + ThunkData, + ExportDirectory, + ExportSize, + FALSE); + + /* Move to the next entry */ + ThunkData++; + + /* Return error if binding was unsuccessful */ + if (!Status) + return Status; + } + + /* Return success */ + return TRUE; +} Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c Mon Feb 4 13:45:55 2008 @@ -30,6 +30,7 @@ extern char reactos_arc_strings[32][256]; extern BOOLEAN UseRealHeap; +extern ULONG LoaderPagesSpanned; BOOLEAN WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, @@ -186,12 +187,11 @@ } RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION)); - /* Save size and version information */ + /* Fill LPB extension */ Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION); Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8; Extension->MinorVersion = VersionToBoot & 0xFF; - Extension->LoaderPagesSpanned = LOADER_HIGH_ZONE; - + Extension->Profile.Status = 2; LoaderBlock->Extension = PaToVa(Extension); } @@ -208,8 +208,8 @@ ULONG_PTR Tss = 0; ULONG BlockSize, NumPages; - LoaderBlock->u.I386.CommonDataArea = NULL;//CommonDataArea; - //LoaderBlock->u.I386.MachineType = MachineType; //FIXME: MachineType? + LoaderBlock->u.I386.CommonDataArea = NULL; //CommonDataArea; + LoaderBlock->u.I386.MachineType = 0; // ntldr sets this to 0 /* Allocate 2 pages for PCR */ Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage); @@ -483,11 +483,11 @@ Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath); DbgPrint((DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status)); + /* Alloc PCR, TSS, do magic things with the GDT/IDT */ + WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage); + /* Initialize Phase 1 - no drivers loading anymore */ WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemPath, OperatingSystemVersion); - - /* Alloc PCR, TSS, do magic things with the GDT/IDT */ - WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage); /* Save entry-point pointer and Loader block VAs */ KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint; @@ -506,6 +506,9 @@ /* Turn on paging mode of CPU*/ WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt); + /* Save final value of LoaderPagesSpanned */ + LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned; + DbgPrint((DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n", KiSystemStartup, LoaderBlockVA)); Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c Mon Feb 4 13:45:55 2008 @@ -14,6 +14,7 @@ #include <debug.h> extern ULONG TotalNLSSize; +extern ULONG LoaderPagesSpanned; // This is needed because headers define wrong one for ReactOS #undef KIP0PCRADDRESS @@ -131,13 +132,13 @@ // PDE, HAL mapping page table, physical mapping, kernel mapping TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE; + // PDE+HAL+KernelPTEs == MemoryData + Buffer = MmAllocateMemoryWithType( + TotalSize - NumPageTables*MM_PAGE_SIZE, LoaderMemoryData); + // Physical PTEs = FirmwareTemporary PhysicalPageTablesBuffer = MmAllocateMemoryWithType( NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary); - - // PDE+HAL+KernelPTEs == MemoryData - Buffer = MmAllocateMemoryWithType( - TotalSize - NumPageTables*MM_PAGE_SIZE, LoaderMemoryData); if (Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) != PhysicalPageTablesBuffer) @@ -290,23 +291,22 @@ if (Mad[i].MemoryType == LoaderFirmwarePermanent || Mad[i].MemoryType == LoaderSpecialMemory || Mad[i].MemoryType == LoaderFree || - (Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LOADER_HIGH_ZONE) || + (Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LoaderPagesSpanned) || Mad[i].MemoryType == LoaderOsloaderStack || Mad[i].MemoryType == LoaderLoadedProgram) { - // // But, the first megabyte of memory always stays! // And, to tell the truth, we don't care about what's higher - // than LOADER_HIGH_ZONE + // than LoaderPagesSpanned if (Mad[i].MemoryType == LoaderFirmwarePermanent || Mad[i].MemoryType == LoaderSpecialMemory) { if (StartPage < 0x100) StartPage = 0x100; - if (EndPage > LOADER_HIGH_ZONE) - EndPage = LOADER_HIGH_ZONE; + if (EndPage > LoaderPagesSpanned) + EndPage = LoaderPagesSpanned; } for (Page = StartPage; Page < EndPage; Page++) @@ -330,7 +330,6 @@ } } - VOID MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, ULONG BasePage, @@ -361,7 +360,7 @@ // Check if it's more than the allowed for OS loader // if yes - don't map the pages, just add as FirmwareTemporary // - if (BasePage + PageCount > LOADER_HIGH_ZONE) + if (BasePage + PageCount > LoaderPagesSpanned) { if (Mad[MadCount].MemoryType != LoaderSpecialMemory && Mad[MadCount].MemoryType != LoaderFirmwarePermanent &&
16 years, 10 months
1
0
0
0
← Newer
1
...
39
40
41
42
43
44
45
46
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Results per page:
10
25
50
100
200