From 794ae4203f24953367c98c83c8c3a97bcb7938d7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 5 Aug 2011 02:25:05 +0000 Subject: [PATCH] - Fix the stupid mess we created when making this from the cmake branch - Part 1 of 2 svn path=/branches/GSoC_2011/TcpIpDriver/; revision=53074 --- PreLoad.cmake | 20 +- base/applications/rapps/lang/bg-BG.rc | 2 - base/applications/rapps/lang/cs-CZ.rc | 2 - base/applications/rapps/lang/de-DE.rc | 2 - base/applications/rapps/lang/en-US.rc | 2 - base/applications/rapps/lang/es-ES.rc | 2 - base/applications/rapps/lang/fr-FR.rc | 2 - base/applications/rapps/lang/it-IT.rc | 2 - base/applications/rapps/lang/ja-JP.rc | 2 - base/applications/rapps/lang/no-NO.rc | 2 - base/applications/rapps/lang/pl-PL.rc | 2 - base/applications/rapps/lang/ru-RU.rc | 2 - base/applications/rapps/lang/sk-SK.rc | 2 - base/applications/rapps/lang/uk-UA.rc | 2 - boot/freeldr/freeldr/arch/i386/fathelp.S | 4 +- boot/freeldr/freeldr/arch/i386/realmode.S | 72 - boot/freeldr/freeldr/freeldr.c | 11 - cmake/CMakeMacros.cmake | 482 +++---- cmake/Platform/Windows-cl.cmake | 552 ++++---- cmake/Platform/Windows.cmake | 72 +- cmake/config-amd64.cmake | 86 +- cmake/config-arm.cmake | 92 +- cmake/config.cmake | 114 +- dll/directx/ksproxy/datatype.cpp | 2 - dll/directx/ksproxy/input_pin.cpp | 6 +- dll/directx/ksproxy/interface.cpp | 2 - dll/directx/ksproxy/ksproxy.cpp | 3 +- dll/directx/ksproxy/output_pin.cpp | 5 +- dll/directx/wine/d3dx9_24/d3dx9_24.spec | 8 +- dll/directx/wine/d3dx9_36/d3dx9_36.spec | 382 ++--- dll/directx/wine/d3dx9_36/d3dx9_36_main.c | 4 - dll/directx/wine/wined3d/state.c | 2 +- dll/ntdll/ldr/ldrinit.c | 4 +- dll/win32/kernel32/client/dllmain.c | 14 +- dll/win32/kernel32/client/file/find.c | 24 +- dll/win32/kernel32/client/handle.c | 360 +++-- dll/win32/kernel32/client/heapmem.c | 654 +++++---- dll/win32/kernel32/include/baseheap.h | 6 - dll/win32/kernel32/include/kernel32.h | 13 +- dll/win32/shlwapi/shlwapi_Hu.rc | 8 +- dll/win32/shlwapi/shlwapi_Pt.rc | 8 +- dll/win32/wsock32/wsock32.spec | 6 +- drivers/network/ndis/ndis/miniport.c | 1 - drivers/network/tcpip/include/debug.h | 4 +- drivers/storage/ide/uniata/id_sata.cpp | 3 +- drivers/usb/usbehci/usbehci.h | 3 +- hal/halx86/mp/i386/mps.S | 4 +- include/psdk/winefs.h | 5 + include/reactos/buildno.h.cmake | 36 +- include/reactos/mc/neteventmsg.mc | 420 +++++- include/reactos/version.h.cmake | 62 +- include/reactos/wine/alloca.h | 6 + include/reactos/wine/port.h | 6 +- include/reactos/wine/test.h | 12 +- include/reactos/wine/typeof.h | 2 +- lib/drivers/ip/network/routines.c | 51 + lib/rossym/compat.h | 2 - lib/rossym/delete.c | 8 +- lib/rossym/dwarf.h | 56 +- lib/rossym/dwarfabbrev.c | 174 ++- lib/rossym/dwarfaranges.c | 98 +- lib/rossym/dwarfcfa.c | 143 +- lib/rossym/dwarfget.c | 4 +- lib/rossym/dwarfinfo.c | 1384 +++++++------------ lib/rossym/dwarfopen.c | 4 +- lib/rossym/dwarfpc.c | 702 +++++----- lib/rossym/find.c | 163 ++- lib/rossym/fromfile.c | 220 ++- lib/rossym/frommem.c | 203 +-- lib/rossym/initkm.c | 4 +- lib/rossym/initum.c | 17 +- lib/rossym/pe.c | 4 + lib/rossym/pe.h | 30 + lib/rossym/rossympriv.h | 8 +- lib/rossym/zwfile.c | 14 +- lib/sdk/crt/string/atol.c | 7 +- media/inf/syssetup.inf | 2 + ntoskrnl/ex/sysinfo.c | 12 +- ntoskrnl/kdbg/kdb_symbols.c | 275 +--- ntoskrnl/mm/ARM3/vadnode.c | 7 +- ntoskrnl/ntoskrnl.spec | 2 +- subsystems/win32/csrss/csrsrv/api/process.c | 2 +- subsystems/win32/csrss/csrsrv/api/wapi.c | 3 - subsystems/win32/csrss/csrsrv/init.c | 9 +- subsystems/win32/csrss/csrsrv/srv.h | 4 + subsystems/win32/csrss/win32csr/console.c | 2 +- toolchain-msvc.cmake | 46 +- tools/rsym/rsym.c | 985 +++++++++++++ 88 files changed, 4483 insertions(+), 3768 deletions(-) create mode 100644 tools/rsym/rsym.c diff --git a/PreLoad.cmake b/PreLoad.cmake index 0cc34014272..e74b5d9df1d 100644 --- a/PreLoad.cmake +++ b/PreLoad.cmake @@ -1,10 +1,10 @@ - -# small trick to get the real source directory at this stage -STRING(REPLACE "/PreLoad.cmake" "" REACTOS_HOME_DIR ${CMAKE_CURRENT_LIST_FILE}) - -#message("/PreLoad.cmake ... ${REACTOS_HOME_DIR}") - -SET(CMAKE_MODULE_PATH "${REACTOS_HOME_DIR}/cmake" CACHE INTERNAL "") - -#message("CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}") - + +# small trick to get the real source directory at this stage +STRING(REPLACE "/PreLoad.cmake" "" REACTOS_HOME_DIR ${CMAKE_CURRENT_LIST_FILE}) + +#message("/PreLoad.cmake ... ${REACTOS_HOME_DIR}") + +SET(CMAKE_MODULE_PATH "${REACTOS_HOME_DIR}/cmake" CACHE INTERNAL "") + +#message("CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}") + diff --git a/base/applications/rapps/lang/bg-BG.rc b/base/applications/rapps/lang/bg-BG.rc index 35057a8b612..0d140c6db58 100644 --- a/base/applications/rapps/lang/bg-BG.rc +++ b/base/applications/rapps/lang/bg-BG.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_BULGARIAN, SUBLANG_DEFAULT IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/cs-CZ.rc b/base/applications/rapps/lang/cs-CZ.rc index efd5f987699..95dda7517bb 100644 --- a/base/applications/rapps/lang/cs-CZ.rc +++ b/base/applications/rapps/lang/cs-CZ.rc @@ -3,8 +3,6 @@ * UPDATED: 2010-12-12 */ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_CZECH, SUBLANG_DEFAULT IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/de-DE.rc b/base/applications/rapps/lang/de-DE.rc index b7ddda33631..8c05ad738cc 100644 --- a/base/applications/rapps/lang/de-DE.rc +++ b/base/applications/rapps/lang/de-DE.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_GERMAN, SUBLANG_GERMAN IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/en-US.rc b/base/applications/rapps/lang/en-US.rc index c5e674e4e30..677ca86c13b 100644 --- a/base/applications/rapps/lang/en-US.rc +++ b/base/applications/rapps/lang/en-US.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/es-ES.rc b/base/applications/rapps/lang/es-ES.rc index 1af56cfc79a..3ade82df580 100644 --- a/base/applications/rapps/lang/es-ES.rc +++ b/base/applications/rapps/lang/es-ES.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_SPANISH, SUBLANG_NEUTRAL IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/fr-FR.rc b/base/applications/rapps/lang/fr-FR.rc index 8b25bc87b6f..2376d97179a 100644 --- a/base/applications/rapps/lang/fr-FR.rc +++ b/base/applications/rapps/lang/fr-FR.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_FRENCH, SUBLANG_NEUTRAL IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/it-IT.rc b/base/applications/rapps/lang/it-IT.rc index 5bec94bbcad..adfb35a1381 100644 --- a/base/applications/rapps/lang/it-IT.rc +++ b/base/applications/rapps/lang/it-IT.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_ITALIAN, SUBLANG_NEUTRAL IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/ja-JP.rc b/base/applications/rapps/lang/ja-JP.rc index 59c06704a67..365c4ef9f2f 100644 --- a/base/applications/rapps/lang/ja-JP.rc +++ b/base/applications/rapps/lang/ja-JP.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/no-NO.rc b/base/applications/rapps/lang/no-NO.rc index eeea0911c2e..29343218dc5 100644 --- a/base/applications/rapps/lang/no-NO.rc +++ b/base/applications/rapps/lang/no-NO.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_NORWEGIAN, SUBLANG_NEUTRAL IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/pl-PL.rc b/base/applications/rapps/lang/pl-PL.rc index 67d908d67e5..ddb209394e5 100644 --- a/base/applications/rapps/lang/pl-PL.rc +++ b/base/applications/rapps/lang/pl-PL.rc @@ -6,8 +6,6 @@ * IRC: irc.freenode.net #reactos-pl; */ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_POLISH, SUBLANG_DEFAULT IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/ru-RU.rc b/base/applications/rapps/lang/ru-RU.rc index 2b39ed56f81..5c2ae8ab315 100644 --- a/base/applications/rapps/lang/ru-RU.rc +++ b/base/applications/rapps/lang/ru-RU.rc @@ -1,5 +1,3 @@ -#pragma code_page(65001) /* UTF-8 */ - LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/sk-SK.rc b/base/applications/rapps/lang/sk-SK.rc index f4032f524a8..a4873c6e3ce 100644 --- a/base/applications/rapps/lang/sk-SK.rc +++ b/base/applications/rapps/lang/sk-SK.rc @@ -3,8 +3,6 @@ * LAST CHANGE: 26-07-2010 */ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_SLOVAK, SUBLANG_DEFAULT IDR_MAINMENU MENU diff --git a/base/applications/rapps/lang/uk-UA.rc b/base/applications/rapps/lang/uk-UA.rc index 339f985a1c7..c133e9776cb 100644 --- a/base/applications/rapps/lang/uk-UA.rc +++ b/base/applications/rapps/lang/uk-UA.rc @@ -6,8 +6,6 @@ * TRANSLATOR: Sakara Yevhen, Igor Paliychuk */ -#pragma code_page(65001) // UTF-8 - LANGUAGE LANG_UKRAINIAN, SUBLANG_DEFAULT IDR_MAINMENU MENU diff --git a/boot/freeldr/freeldr/arch/i386/fathelp.S b/boot/freeldr/freeldr/arch/i386/fathelp.S index 7bd7fb33d95..4403aa55c6c 100644 --- a/boot/freeldr/freeldr/arch/i386/fathelp.S +++ b/boot/freeldr/freeldr/arch/i386/fathelp.S @@ -56,6 +56,7 @@ PUBLIC _mainCRTStartup // For Mingw32 builds where the linker looks for this sym _mainCRTStartup: PUBLIC start start: +#if 0 .byte HEX(e9) .byte HEX(fd) .byte HEX(01) @@ -134,7 +135,7 @@ LoadFile_Done: // Reads the entire FAT into memory at 7000:0000 ReadFatIntoMemory: - mov ax, [bp+HiddenSectors] + mov ax, [bp+HiddenSectors] mov dx, [bp+HiddenSectors+2] add ax, [bp+ReservedSectors] adc dx, 0 @@ -233,6 +234,7 @@ msgLoading: .asciz "Loading FreeLoader...\r\n" .org HEX(1fe) // Pad to 510 bytes .word HEX(0aa55) // BootSector signature +#endif .endcode16 diff --git a/boot/freeldr/freeldr/arch/i386/realmode.S b/boot/freeldr/freeldr/arch/i386/realmode.S index 4464a17ad70..0a146c573e4 100644 --- a/boot/freeldr/freeldr/arch/i386/realmode.S +++ b/boot/freeldr/freeldr/arch/i386/realmode.S @@ -2,79 +2,7 @@ #include -.code16 -PUBLIC _mainCRTStartup -_mainCRTStartup: -_LoaderEntry: - ret - -.endcode16 - .code32 -// globals -PUBLIC _BootPartition -_BootPartition: -PUBLIC _BootDrive -_BootDrive: - -PUBLIC _PageDirectoryStart -_PageDirectoryStart: -PUBLIC _PageDirectoryEnd -_PageDirectoryEnd: - -PUBLIC _startup_pagedirectory -_startup_pagedirectory: -PUBLIC _apic_pagetable -_apic_pagetable: -PUBLIC _kernel_pagetable -_kernel_pagetable: -PUBLIC _lowmem_pagetable -_lowmem_pagetable: - - -PUBLIC RealEntryPoint -RealEntryPoint: - -PUBLIC _EnableA20 -_EnableA20: - -PUBLIC _ChainLoadBiosBootSectorCode -_ChainLoadBiosBootSectorCode: - -PUBLIC _BootOldLinuxKernel -_BootOldLinuxKernel: - -PUBLIC _BootNewLinuxKernel -_BootNewLinuxKernel: - -PUBLIC _SoftReboot -_SoftReboot: - -PUBLIC _DriveMapOldInt13HandlerAddress -_DriveMapOldInt13HandlerAddress: - -PUBLIC _DriveMapInt13HandlerStart -_DriveMapInt13HandlerStart: - -PUBLIC _DriveMapInt13HandlerEnd -_DriveMapInt13HandlerEnd: - -PUBLIC _DriveMapInt13HandlerMapList -_DriveMapInt13HandlerMapList: - -PUBLIC _PnpBiosGetDeviceNode -_PnpBiosGetDeviceNode: - -PUBLIC _PnpBiosGetDeviceNodeCount -_PnpBiosGetDeviceNodeCount: - -PUBLIC _PnpBiosSupported -_PnpBiosSupported: - -PUBLIC _Int386 -_Int386: - - END diff --git a/boot/freeldr/freeldr/freeldr.c b/boot/freeldr/freeldr/freeldr.c index 3a9ca85dba0..9ad6bd1c34a 100644 --- a/boot/freeldr/freeldr/freeldr.c +++ b/boot/freeldr/freeldr/freeldr.c @@ -54,17 +54,6 @@ VOID BootMain(LPSTR CmdLine) RunLoader(); } -#ifdef _MSC_VER -long _ftol2(double f) -{ - return _ftol(f); -} -long _ftol2_sse(double f) -{ - return _ftol(f); -} -#endif - // We need to emulate these, because the original ones don't work in freeldr int __cdecl wctomb(char *mbchar, wchar_t wchar) { diff --git a/cmake/CMakeMacros.cmake b/cmake/CMakeMacros.cmake index ef64eebd6e1..09ea187aa6b 100644 --- a/cmake/CMakeMacros.cmake +++ b/cmake/CMakeMacros.cmake @@ -1,241 +1,241 @@ - -macro(set_cpp) - include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport) - set(IS_CPP 1) - add_definitions( - -DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++ - -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt) -endmacro() - -macro(add_dependency_node _node) - if(GENERATE_DEPENDENCY_GRAPH) - get_target_property(_type ${_node} TYPE) - if(_type MATCHES SHARED_LIBRARY OR ${_node} MATCHES ntoskrnl) - file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " \n") - endif() - endif() -endmacro() - -macro(add_dependency_edge _source _target) - if(GENERATE_DEPENDENCY_GRAPH) - get_target_property(_type ${_source} TYPE) - if(_type MATCHES SHARED_LIBRARY) - file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " \n") - endif() - endif() -endmacro() - -macro(add_dependency_header) - file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "\n\n \n") -endmacro() - -macro(add_dependency_footer) - add_dependency_node(ntdll) - file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " \n\n") -endmacro() - -macro(add_message_headers) - foreach(_in_FILE ${ARGN}) - get_filename_component(FILE ${_in_FILE} NAME_WE) - macro_mc(${FILE}) - add_custom_command( - OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h - COMMAND ${COMMAND_MC} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc) - set_source_files_properties( - ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc - PROPERTIES GENERATED TRUE) - add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc) - endforeach() -endmacro() - -macro(dir_to_num dir var) - if(${dir} STREQUAL reactos/system32) - set(${var} 1) - elseif(${dir} STREQUAL reactos/system32/drivers) - set(${var} 2) - elseif(${dir} STREQUAL reactos/Fonts) - set(${var} 3) - elseif(${dir} STREQUAL reactos) - set(${var} 4) - elseif(${dir} STREQUAL reactos/system32/drivers/etc) - set(${var} 5) - elseif(${dir} STREQUAL reactos/inf) - set(${var} 6) - elseif(${dir} STREQUAL reactos/bin) - set(${var} 7) - elseif(${dir} STREQUAL reactos/media) - set(${var} 8) - else() - message(ERROR "Wrong destination: ${dir}") - endif() -endmacro() - -function(add_cd_file) - cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN}) - if(NOT (_CD_TARGET OR _CD_FILE)) - message(FATAL_ERROR "You must provide a target or a file to install!") - endif() - - if(NOT _CD_DESTINATION) - message(FATAL_ERROR "You must provide a destination") - elseif(${_CD_DESTINATION} STREQUAL root) - set(_CD_DESTINATION "") - endif() - - if(NOT _CD_FOR) - message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!") - endif() - - #get file if we need to - if(NOT _CD_FILE) - get_target_property(_CD_FILE ${_CD_TARGET} LOCATION) - endif() - - #do we add it to all CDs? - if(_CD_FOR STREQUAL all) - set(_CD_FOR "bootcd;livecd;regtest") - endif() - - #do we add it to bootcd? - list(FIND _CD_FOR bootcd __cd) - if(NOT __cd EQUAL -1) - #whether or not we should put it in reactos.cab or directly on cd - if(_CD_NO_CAB) - #directly on cd - foreach(item ${_CD_FILE}) - file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n") - endforeach() - if(_CD_NAME_ON_CD) - get_filename_component(__file ${_CD_FILE} NAME) - #rename it in the cd tree - file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n") - endif() - if(_CD_TARGET) - #manage dependency - add_dependencies(bootcd ${_CD_TARGET}) - endif() - else() - #add it in reactos.cab - dir_to_num(${_CD_DESTINATION} _num) - if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows) - file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n") - else() - file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${_CD_FILE}\" ${_num}\n") - endif() - if(_CD_TARGET) - #manage dependency - add_dependencies(reactos_cab ${_CD_TARGET}) - endif() - endif() - endif() #end bootcd - - #do we add it to livecd? - list(FIND _CD_FOR livecd __cd) - if(NOT __cd EQUAL -1) - #manage dependency - if(_CD_TARGET) - add_dependencies(livecd ${_CD_TARGET}) - endif() - foreach(item ${_CD_FILE}) - file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n") - endforeach() - if(_CD_NAME_ON_CD) - get_filename_component(__file ${_CD_FILE} NAME) - #rename it in the cd tree - file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n") - endif() - endif() #end livecd - - #do we add it to regtest? - list(FIND _CD_FOR regtest __cd) - if(NOT __cd EQUAL -1) - #whether or not we should put it in reactos.cab or directly on cd - if(_CD_NO_CAB) - #directly on cd - foreach(item ${_CD_FILE}) - file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n") - endforeach() - if(_CD_NAME_ON_CD) - get_filename_component(__file ${_CD_FILE} NAME) - #rename it in the cd tree - file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n") - endif() - if(_CD_TARGET) - #manage dependency - add_dependencies(bootcdregtest ${_CD_TARGET}) - endif() - else() - #add it in reactos.cab - #dir_to_num(${_CD_DESTINATION} _num) - #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n") - #if(_CD_TARGET) - # #manage dependency - # add_dependencies(reactos_cab ${_CD_TARGET}) - #endif() - endif() - endif() #end bootcd -endfunction() - -# Create module_clean targets -function(add_clean_target target) - if(CMAKE_GENERATOR MATCHES "Unix Makefiles" OR CMAKE_GENERATOR MATCHES "MinGW Makefiles") - set(CLEAN_COMMAND make clean) - elseif(CMAKE_GENERATOR MATCHES "NMake Makefiles") - set(CLEAN_COMMAND nmake clean) - endif() - add_custom_target(${target}_clean - COMMAND ${CLEAN_COMMAND} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Cleaning ${target}") -endfunction() - -if(NOT MSVC_IDE) - function(add_library name) - _add_library(${name} ${ARGN}) - add_clean_target(${name}) - endfunction() - - function(add_executable name) - _add_executable(${name} ${ARGN}) - add_clean_target(${name}) - endfunction() -endif() - -if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows) - macro(to_win_path _cmake_path _native_path) - string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}") - endmacro() - - macro(concatenate_files _file1 _file2 _output) - to_win_path("${_file1}" _real_file1) - to_win_path("${_file2}" _real_file2) - to_win_path("${_output}" _real_output) - add_custom_command( - OUTPUT ${_output} - COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul" - DEPENDS ${_file1} - DEPENDS ${_file2}) - endmacro() -else() - macro(concatenate_files _file1 _file2 _output) - add_custom_command( - OUTPUT ${_output} - COMMAND cat ${_file1} ${_file2} > ${_output} - DEPENDS ${_file1} - DEPENDS ${_file2}) - endmacro() -endif() - -macro(add_importlibs MODULE) - add_dependency_node(${MODULE}) - foreach(LIB ${ARGN}) - if ("${LIB}" MATCHES "msvcrt") - add_definitions(-D_DLL -D__USE_CRTIMP) - target_link_libraries(${MODULE} msvcrtex) - endif() - target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}) - add_dependencies(${MODULE} lib${LIB}) - add_dependency_edge(${MODULE} ${LIB}) - endforeach() -endmacro() + +macro(set_cpp) + include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport) + set(IS_CPP 1) + add_definitions( + -DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++ + -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt) +endmacro() + +macro(add_dependency_node _node) + if(GENERATE_DEPENDENCY_GRAPH) + get_target_property(_type ${_node} TYPE) + if(_type MATCHES SHARED_LIBRARY OR ${_node} MATCHES ntoskrnl) + file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " \n") + endif() + endif() +endmacro() + +macro(add_dependency_edge _source _target) + if(GENERATE_DEPENDENCY_GRAPH) + get_target_property(_type ${_source} TYPE) + if(_type MATCHES SHARED_LIBRARY) + file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " \n") + endif() + endif() +endmacro() + +macro(add_dependency_header) + file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "\n\n \n") +endmacro() + +macro(add_dependency_footer) + add_dependency_node(ntdll) + file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " \n\n") +endmacro() + +macro(add_message_headers) + foreach(_in_FILE ${ARGN}) + get_filename_component(FILE ${_in_FILE} NAME_WE) + macro_mc(${FILE}) + add_custom_command( + OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h + COMMAND ${COMMAND_MC} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc) + set_source_files_properties( + ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc + PROPERTIES GENERATED TRUE) + add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc) + endforeach() +endmacro() + +macro(dir_to_num dir var) + if(${dir} STREQUAL reactos/system32) + set(${var} 1) + elseif(${dir} STREQUAL reactos/system32/drivers) + set(${var} 2) + elseif(${dir} STREQUAL reactos/Fonts) + set(${var} 3) + elseif(${dir} STREQUAL reactos) + set(${var} 4) + elseif(${dir} STREQUAL reactos/system32/drivers/etc) + set(${var} 5) + elseif(${dir} STREQUAL reactos/inf) + set(${var} 6) + elseif(${dir} STREQUAL reactos/bin) + set(${var} 7) + elseif(${dir} STREQUAL reactos/media) + set(${var} 8) + else() + message(ERROR "Wrong destination: ${dir}") + endif() +endmacro() + +function(add_cd_file) + cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN}) + if(NOT (_CD_TARGET OR _CD_FILE)) + message(FATAL_ERROR "You must provide a target or a file to install!") + endif() + + if(NOT _CD_DESTINATION) + message(FATAL_ERROR "You must provide a destination") + elseif(${_CD_DESTINATION} STREQUAL root) + set(_CD_DESTINATION "") + endif() + + if(NOT _CD_FOR) + message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!") + endif() + + #get file if we need to + if(NOT _CD_FILE) + get_target_property(_CD_FILE ${_CD_TARGET} LOCATION) + endif() + + #do we add it to all CDs? + if(_CD_FOR STREQUAL all) + set(_CD_FOR "bootcd;livecd;regtest") + endif() + + #do we add it to bootcd? + list(FIND _CD_FOR bootcd __cd) + if(NOT __cd EQUAL -1) + #whether or not we should put it in reactos.cab or directly on cd + if(_CD_NO_CAB) + #directly on cd + foreach(item ${_CD_FILE}) + file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n") + endforeach() + if(_CD_NAME_ON_CD) + get_filename_component(__file ${_CD_FILE} NAME) + #rename it in the cd tree + file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n") + endif() + if(_CD_TARGET) + #manage dependency + add_dependencies(bootcd ${_CD_TARGET}) + endif() + else() + #add it in reactos.cab + dir_to_num(${_CD_DESTINATION} _num) + if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows) + file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n") + else() + file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${_CD_FILE}\" ${_num}\n") + endif() + if(_CD_TARGET) + #manage dependency + add_dependencies(reactos_cab ${_CD_TARGET}) + endif() + endif() + endif() #end bootcd + + #do we add it to livecd? + list(FIND _CD_FOR livecd __cd) + if(NOT __cd EQUAL -1) + #manage dependency + if(_CD_TARGET) + add_dependencies(livecd ${_CD_TARGET}) + endif() + foreach(item ${_CD_FILE}) + file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n") + endforeach() + if(_CD_NAME_ON_CD) + get_filename_component(__file ${_CD_FILE} NAME) + #rename it in the cd tree + file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n") + endif() + endif() #end livecd + + #do we add it to regtest? + list(FIND _CD_FOR regtest __cd) + if(NOT __cd EQUAL -1) + #whether or not we should put it in reactos.cab or directly on cd + if(_CD_NO_CAB) + #directly on cd + foreach(item ${_CD_FILE}) + file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n") + endforeach() + if(_CD_NAME_ON_CD) + get_filename_component(__file ${_CD_FILE} NAME) + #rename it in the cd tree + file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n") + endif() + if(_CD_TARGET) + #manage dependency + add_dependencies(bootcdregtest ${_CD_TARGET}) + endif() + else() + #add it in reactos.cab + #dir_to_num(${_CD_DESTINATION} _num) + #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n") + #if(_CD_TARGET) + # #manage dependency + # add_dependencies(reactos_cab ${_CD_TARGET}) + #endif() + endif() + endif() #end bootcd +endfunction() + +# Create module_clean targets +function(add_clean_target target) + if(CMAKE_GENERATOR MATCHES "Unix Makefiles" OR CMAKE_GENERATOR MATCHES "MinGW Makefiles") + set(CLEAN_COMMAND make clean) + elseif(CMAKE_GENERATOR MATCHES "NMake Makefiles") + set(CLEAN_COMMAND nmake clean) + endif() + add_custom_target(${target}_clean + COMMAND ${CLEAN_COMMAND} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Cleaning ${target}") +endfunction() + +if(NOT MSVC_IDE) + function(add_library name) + _add_library(${name} ${ARGN}) + add_clean_target(${name}) + endfunction() + + function(add_executable name) + _add_executable(${name} ${ARGN}) + add_clean_target(${name}) + endfunction() +endif() + +if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows) + macro(to_win_path _cmake_path _native_path) + string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}") + endmacro() + + macro(concatenate_files _file1 _file2 _output) + to_win_path("${_file1}" _real_file1) + to_win_path("${_file2}" _real_file2) + to_win_path("${_output}" _real_output) + add_custom_command( + OUTPUT ${_output} + COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul" + DEPENDS ${_file1} + DEPENDS ${_file2}) + endmacro() +else() + macro(concatenate_files _file1 _file2 _output) + add_custom_command( + OUTPUT ${_output} + COMMAND cat ${_file1} ${_file2} > ${_output} + DEPENDS ${_file1} + DEPENDS ${_file2}) + endmacro() +endif() + +macro(add_importlibs MODULE) + add_dependency_node(${MODULE}) + foreach(LIB ${ARGN}) + if ("${LIB}" MATCHES "msvcrt") + add_definitions(-D_DLL -D__USE_CRTIMP) + target_link_libraries(${MODULE} msvcrtex) + endif() + target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}) + add_dependencies(${MODULE} lib${LIB}) + add_dependency_edge(${MODULE} ${LIB}) + endforeach() +endmacro() diff --git a/cmake/Platform/Windows-cl.cmake b/cmake/Platform/Windows-cl.cmake index 57518617eb1..76c1f6fb983 100644 --- a/cmake/Platform/Windows-cl.cmake +++ b/cmake/Platform/Windows-cl.cmake @@ -1,276 +1,276 @@ -# try to load any previously computed information for C on this platform -INCLUDE( ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake OPTIONAL) -# try to load any previously computed information for CXX on this platform -INCLUDE( ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake OPTIONAL) - -SET(WIN32 1) - -INCLUDE(Platform/cl) - -############ -# Detect WDK build environment -IF($ENV{DDKBUILDENV} MATCHES "chk") - MESSAGE(STATUS "DDK/WDK checked build environment detected.") - SET(CMAKE_USE_WDK_ENV 1) -ENDIF() - -IF($ENV{DDKBUILDENV} MATCHES "fre") - MESSAGE(STATUS "DDK/WDK free build environment detected.") - SET(CMAKE_USE_WDK_ENV 1) -ENDIF() - -if(CMAKE_USE_WDK_ENV) - - # Detect output architecture - if(NOT ARCH) - if($ENV{AMD64} MATCHES 1) - set(ARCH amd64) - set(MSVC_C_ARCHITECTURE_ID 64) - else() - set(ARCH i386) - endif() - endif() - - # Add library directories - STRING(REPLACE * ${ARCH} ATL_LIB_PATH $ENV{ATL_LIB_PATH}) - STRING(REPLACE * ${ARCH} CRT_LIB_PATH $ENV{CRT_LIB_PATH}) - STRING(REPLACE * ${ARCH} DDK_LIB_PATH $ENV{DDK_LIB_PATH}) - STRING(REPLACE * ${ARCH} KMDF_LIB_PATH $ENV{KMDF_LIB_PATH}) - STRING(REPLACE * ${ARCH} MFC_LIB_PATH $ENV{MFC_LIB_PATH}) - STRING(REPLACE * ${ARCH} SDK_LIB_PATH $ENV{SDK_LIB_PATH}) - LINK_DIRECTORIES(${ATL_LIB_PATH} - ${CRT_LIB_PATH} - ${DDK_LIB_PATH} - ${IFSKIT_LIB_PATH} - ${KMDF_LIB_PATH} - ${MFC_LIB_PATH} - ${SDK_LIB_PATH}) - - # Add environment variables - if(NOT CMAKE_CROSSCOMPILING) - set(ENV{INCLUDE} "$ENV{CRT_INC_PATH};$ENV{SDK_INC_PATH};$ENV{SDK_INC_PATH}\\crt\\stl60") - include_directories($ENV{INCLUDE}) - set(ENV{LIBPATH} "${CRT_LIB_PATH};${SDK_LIB_PATH}") - set(ENV{USE_MSVCRT} 1) - set(ENV{USE_STL} 1) - set(ENV{STL_VER} 60) - endif() -endif() - -############ - -SET(CMAKE_CREATE_WIN32_EXE /subsystem:windows) -SET(CMAKE_CREATE_CONSOLE_EXE /subsystem:console) - -IF(CMAKE_GENERATOR MATCHES "Visual Studio 6") - SET (CMAKE_NO_BUILD_TYPE 1) -ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 6") -IF(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio") - SET (CMAKE_NO_BUILD_TYPE 1) - SET (CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING - "Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored.") - MARK_AS_ADVANCED(CMAKE_CONFIGURATION_TYPES) -ENDIF(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio") -# does the compiler support pdbtype and is it the newer compiler -IF(CMAKE_GENERATOR MATCHES "Visual Studio 8") - SET(CMAKE_COMPILER_2005 1) -ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 8") - -# make sure to enable languages after setting configuration types -ENABLE_LANGUAGE(RC) -SET(CMAKE_COMPILE_RESOURCE "rc /fo ") - -# for nmake we need to compute some information about the compiler -# that is being used. -# the compiler may be free command line, 6, 7, or 71, and -# each have properties that must be determined. -# to avoid running these tests with each cmake run, the -# test results are saved in CMakeCPlatform.cmake, a file -# that is automatically copied into try_compile directories -# by the global generator. -SET(MSVC_IDE 1) -IF(CMAKE_GENERATOR MATCHES "Makefiles") - SET(MSVC_IDE 0) - IF(NOT CMAKE_VC_COMPILER_TESTS_RUN) - SET(CMAKE_VC_COMPILER_TESTS 1) - SET(testNmakeCLVersionFile - "${CMAKE_ROOT}/Modules/CMakeTestNMakeCLVersion.c") - STRING(REGEX REPLACE "/" "\\\\" testNmakeCLVersionFile "${testNmakeCLVersionFile}") - MESSAGE(STATUS "Check for CL compiler version") - SET(CMAKE_TEST_COMPILER ${CMAKE_C_COMPILER}) - IF (NOT CMAKE_C_COMPILER) - SET(CMAKE_TEST_COMPILER ${CMAKE_CXX_COMPILER}) - ENDIF(NOT CMAKE_C_COMPILER) - EXEC_PROGRAM(${CMAKE_TEST_COMPILER} - ARGS /nologo -EP \"${testNmakeCLVersionFile}\" - OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT - RETURN_VALUE CMAKE_COMPILER_RETURN - ) - IF(NOT CMAKE_COMPILER_RETURN) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining the version of compiler passed with the following output:\n" - "${CMAKE_COMPILER_OUTPUT}\n\n") - STRING(REGEX REPLACE "\n" " " compilerVersion "${CMAKE_COMPILER_OUTPUT}") - STRING(REGEX REPLACE ".*VERSION=(.*)" "\\1" - compilerVersion "${compilerVersion}") - MESSAGE(STATUS "Check for CL compiler version - ${compilerVersion}") - SET(MSVC60) - SET(MSVC70) - SET(MSVC71) - SET(MSVC80) - SET(CMAKE_COMPILER_2005) - IF("${compilerVersion}" LESS 1300) - SET(MSVC60 1) - SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 1) - ENDIF("${compilerVersion}" LESS 1300) - IF("${compilerVersion}" EQUAL 1300) - SET(MSVC70 1) - SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 0) - ENDIF("${compilerVersion}" EQUAL 1300) - IF("${compilerVersion}" EQUAL 1310) - SET(MSVC71 1) - SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 0) - ENDIF("${compilerVersion}" EQUAL 1310) - IF("${compilerVersion}" EQUAL 1400) - SET(MSVC80 1) - SET(CMAKE_COMPILER_2005 1) - ENDIF("${compilerVersion}" EQUAL 1400) - IF("${compilerVersion}" EQUAL 1500) - SET(MSVC90 1) - ENDIF("${compilerVersion}" EQUAL 1500) - IF("${compilerVersion}" EQUAL 1600) - SET(MSVC10 1) - ENDIF("${compilerVersion}" EQUAL 1600) - SET(MSVC_VERSION "${compilerVersion}") - ELSE(NOT CMAKE_COMPILER_RETURN) - MESSAGE(STATUS "Check for CL compiler version - failed") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining the version of compiler failed with the following output:\n" - "${CMAKE_COMPILER_OUTPUT}\n\n") - ENDIF(NOT CMAKE_COMPILER_RETURN) - # try to figure out if we are running the free command line - # tools from Microsoft. These tools do not provide debug libraries, - # so the link flags used have to be different. - MAKE_DIRECTORY("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp2") - SET(testForFreeVCFile - "${CMAKE_ROOT}/Modules/CMakeTestForFreeVC.cxx") - STRING(REGEX REPLACE "/" "\\\\" testForFreeVCFile "${testForFreeVCFile}") - MESSAGE(STATUS "Check if this is a free VC compiler") - EXEC_PROGRAM(${CMAKE_TEST_COMPILER} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp2 - ARGS /nologo /EHsc - \"${testForFreeVCFile}\" - OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT - RETURN_VALUE CMAKE_COMPILER_RETURN - ) - IF(CMAKE_COMPILER_RETURN) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if this is a free VC compiler failed with the following output:\n" - "${CMAKE_COMPILER_OUTPUT}\n\n") - MESSAGE(STATUS "Check if this is a free VC compiler - yes") - SET(CMAKE_USING_VC_FREE_TOOLS 1) - ELSE(CMAKE_COMPILER_RETURN) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if this is a free VC compiler passed with the following output:\n" - "${CMAKE_COMPILER_OUTPUT}\n\n") - MESSAGE(STATUS "Check if this is a free VC compiler - no") - SET(CMAKE_USING_VC_FREE_TOOLS 0) - ENDIF(CMAKE_COMPILER_RETURN) - MAKE_DIRECTORY("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp3") - ENDIF(NOT CMAKE_VC_COMPILER_TESTS_RUN) -ENDIF(CMAKE_GENERATOR MATCHES "Makefiles") - -IF(MSVC_C_ARCHITECTURE_ID MATCHES 64) - SET(CMAKE_CL_64 1) -ELSE(MSVC_C_ARCHITECTURE_ID MATCHES 64) - SET(CMAKE_CL_64 0) -ENDIF(MSVC_C_ARCHITECTURE_ID MATCHES 64) -IF(CMAKE_FORCE_WIN64) - SET(CMAKE_CL_64 1) -ENDIF(CMAKE_FORCE_WIN64) - -#IF("${MSVC_VERSION}" GREATER 1599) -# SET(MSVC_INCREMENTAL_DEFAULT ON) -#ENDIF() - -# No support for old versions -if(MSVC_VERSION LESS 1310) -message(FATAL_ERROR "Your compiler is too old. Get a newer version!") -endif() - -# for 2005 make sure the manifest is put in the dll with mt -#SET(CMAKE_CXX_CREATE_SHARED_LIBRARY " -E vs_link_dll ${CMAKE_CXX_CREATE_SHARED_LIBRARY}") -#SET(CMAKE_CXX_CREATE_SHARED_MODULE " -E vs_link_dll ${CMAKE_CXX_CREATE_SHARED_MODULE}") -# create a C shared library -#SET(CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}") -# create a C shared module just copy the shared library rule -#SET(CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE}") -#SET(CMAKE_CXX_LINK_EXECUTABLE " -E vs_link_exe ${CMAKE_CXX_LINK_EXECUTABLE}") -#SET(CMAKE_C_LINK_EXECUTABLE " -E vs_link_exe ${CMAKE_C_LINK_EXECUTABLE}") - -SET(CMAKE_BUILD_TYPE_INIT Debug) -SET(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /Zi /Ob0 /Od") -SET(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /Zi /Ob0 /Od") -SET(CMAKE_CXX_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000 /EHsc") -SET(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG") -SET(CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG") -SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1") -SET(CMAKE_C_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000") -SET(CMAKE_C_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG") -SET(CMAKE_C_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG") -SET(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1") -SET(CMAKE_C_STANDARD_LIBRARIES_INIT "") -SET(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT}") -SET(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") - -# executable linker flags -SET (CMAKE_LINK_DEF_FILE_FLAG "/DEF:") -# set the stack size and the machine type -SET(_MACHINE_ARCH_FLAG ${MSVC_C_ARCHITECTURE_ID}) -IF(NOT _MACHINE_ARCH_FLAG) - SET(_MACHINE_ARCH_FLAG ${MSVC_CXX_ARCHITECTURE_ID}) -ENDIF(NOT _MACHINE_ARCH_FLAG) -SET (CMAKE_EXE_LINKER_FLAGS_INIT - "${CMAKE_EXE_LINKER_FLAGS_INIT} /STACK:10000000 /machine:${_MACHINE_ARCH_FLAG}") - -# add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype -# on versions that support it -SET( MSVC_INCREMENTAL_YES_FLAG "") -IF(NOT MSVC_INCREMENTAL_DEFAULT) - SET( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES") -ENDIF() - -IF (CMAKE_COMPILER_SUPPORTS_PDBTYPE) - SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept") - SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") -ELSE (CMAKE_COMPILER_SUPPORTS_PDBTYPE) - SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug") - SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") -ENDIF (CMAKE_COMPILER_SUPPORTS_PDBTYPE) -# for release and minsize release default to no incremental linking -SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO") -SET(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO") - -# copy the EXE_LINKER flags to SHARED and MODULE linker flags -# shared linker flags -SET (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT}) -SET (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT}) -SET (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT}) -SET (CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT}) -SET (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT}) -# module linker flags -SET (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT}) -SET (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}) -SET (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT}) -SET (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT}) -SET (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT}) - -# save computed information for this platform -IF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake") - CONFIGURE_FILE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake.in - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCPlatform.cmake IMMEDIATE) -ENDIF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake") - -IF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake") - CONFIGURE_FILE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake.in - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXPlatform.cmake IMMEDIATE) -ENDIF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake") +# try to load any previously computed information for C on this platform +INCLUDE( ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake OPTIONAL) +# try to load any previously computed information for CXX on this platform +INCLUDE( ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake OPTIONAL) + +SET(WIN32 1) + +INCLUDE(Platform/cl) + +############ +# Detect WDK build environment +IF($ENV{DDKBUILDENV} MATCHES "chk") + MESSAGE(STATUS "DDK/WDK checked build environment detected.") + SET(CMAKE_USE_WDK_ENV 1) +ENDIF() + +IF($ENV{DDKBUILDENV} MATCHES "fre") + MESSAGE(STATUS "DDK/WDK free build environment detected.") + SET(CMAKE_USE_WDK_ENV 1) +ENDIF() + +if(CMAKE_USE_WDK_ENV) + + # Detect output architecture + if(NOT ARCH) + if($ENV{AMD64} MATCHES 1) + set(ARCH amd64) + set(MSVC_C_ARCHITECTURE_ID 64) + else() + set(ARCH i386) + endif() + endif() + + # Add library directories + STRING(REPLACE * ${ARCH} ATL_LIB_PATH $ENV{ATL_LIB_PATH}) + STRING(REPLACE * ${ARCH} CRT_LIB_PATH $ENV{CRT_LIB_PATH}) + STRING(REPLACE * ${ARCH} DDK_LIB_PATH $ENV{DDK_LIB_PATH}) + STRING(REPLACE * ${ARCH} KMDF_LIB_PATH $ENV{KMDF_LIB_PATH}) + STRING(REPLACE * ${ARCH} MFC_LIB_PATH $ENV{MFC_LIB_PATH}) + STRING(REPLACE * ${ARCH} SDK_LIB_PATH $ENV{SDK_LIB_PATH}) + LINK_DIRECTORIES(${ATL_LIB_PATH} + ${CRT_LIB_PATH} + ${DDK_LIB_PATH} + ${IFSKIT_LIB_PATH} + ${KMDF_LIB_PATH} + ${MFC_LIB_PATH} + ${SDK_LIB_PATH}) + + # Add environment variables + if(NOT CMAKE_CROSSCOMPILING) + set(ENV{INCLUDE} "$ENV{CRT_INC_PATH};$ENV{SDK_INC_PATH};$ENV{SDK_INC_PATH}\\crt\\stl60") + include_directories($ENV{INCLUDE}) + set(ENV{LIBPATH} "${CRT_LIB_PATH};${SDK_LIB_PATH}") + set(ENV{USE_MSVCRT} 1) + set(ENV{USE_STL} 1) + set(ENV{STL_VER} 60) + endif() +endif() + +############ + +SET(CMAKE_CREATE_WIN32_EXE /subsystem:windows) +SET(CMAKE_CREATE_CONSOLE_EXE /subsystem:console) + +IF(CMAKE_GENERATOR MATCHES "Visual Studio 6") + SET (CMAKE_NO_BUILD_TYPE 1) +ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 6") +IF(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio") + SET (CMAKE_NO_BUILD_TYPE 1) + SET (CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING + "Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored.") + MARK_AS_ADVANCED(CMAKE_CONFIGURATION_TYPES) +ENDIF(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio") +# does the compiler support pdbtype and is it the newer compiler +IF(CMAKE_GENERATOR MATCHES "Visual Studio 8") + SET(CMAKE_COMPILER_2005 1) +ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 8") + +# make sure to enable languages after setting configuration types +ENABLE_LANGUAGE(RC) +SET(CMAKE_COMPILE_RESOURCE "rc /fo ") + +# for nmake we need to compute some information about the compiler +# that is being used. +# the compiler may be free command line, 6, 7, or 71, and +# each have properties that must be determined. +# to avoid running these tests with each cmake run, the +# test results are saved in CMakeCPlatform.cmake, a file +# that is automatically copied into try_compile directories +# by the global generator. +SET(MSVC_IDE 1) +IF(CMAKE_GENERATOR MATCHES "Makefiles") + SET(MSVC_IDE 0) + IF(NOT CMAKE_VC_COMPILER_TESTS_RUN) + SET(CMAKE_VC_COMPILER_TESTS 1) + SET(testNmakeCLVersionFile + "${CMAKE_ROOT}/Modules/CMakeTestNMakeCLVersion.c") + STRING(REGEX REPLACE "/" "\\\\" testNmakeCLVersionFile "${testNmakeCLVersionFile}") + MESSAGE(STATUS "Check for CL compiler version") + SET(CMAKE_TEST_COMPILER ${CMAKE_C_COMPILER}) + IF (NOT CMAKE_C_COMPILER) + SET(CMAKE_TEST_COMPILER ${CMAKE_CXX_COMPILER}) + ENDIF(NOT CMAKE_C_COMPILER) + EXEC_PROGRAM(${CMAKE_TEST_COMPILER} + ARGS /nologo -EP \"${testNmakeCLVersionFile}\" + OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT + RETURN_VALUE CMAKE_COMPILER_RETURN + ) + IF(NOT CMAKE_COMPILER_RETURN) + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining the version of compiler passed with the following output:\n" + "${CMAKE_COMPILER_OUTPUT}\n\n") + STRING(REGEX REPLACE "\n" " " compilerVersion "${CMAKE_COMPILER_OUTPUT}") + STRING(REGEX REPLACE ".*VERSION=(.*)" "\\1" + compilerVersion "${compilerVersion}") + MESSAGE(STATUS "Check for CL compiler version - ${compilerVersion}") + SET(MSVC60) + SET(MSVC70) + SET(MSVC71) + SET(MSVC80) + SET(CMAKE_COMPILER_2005) + IF("${compilerVersion}" LESS 1300) + SET(MSVC60 1) + SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 1) + ENDIF("${compilerVersion}" LESS 1300) + IF("${compilerVersion}" EQUAL 1300) + SET(MSVC70 1) + SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 0) + ENDIF("${compilerVersion}" EQUAL 1300) + IF("${compilerVersion}" EQUAL 1310) + SET(MSVC71 1) + SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 0) + ENDIF("${compilerVersion}" EQUAL 1310) + IF("${compilerVersion}" EQUAL 1400) + SET(MSVC80 1) + SET(CMAKE_COMPILER_2005 1) + ENDIF("${compilerVersion}" EQUAL 1400) + IF("${compilerVersion}" EQUAL 1500) + SET(MSVC90 1) + ENDIF("${compilerVersion}" EQUAL 1500) + IF("${compilerVersion}" EQUAL 1600) + SET(MSVC10 1) + ENDIF("${compilerVersion}" EQUAL 1600) + SET(MSVC_VERSION "${compilerVersion}") + ELSE(NOT CMAKE_COMPILER_RETURN) + MESSAGE(STATUS "Check for CL compiler version - failed") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining the version of compiler failed with the following output:\n" + "${CMAKE_COMPILER_OUTPUT}\n\n") + ENDIF(NOT CMAKE_COMPILER_RETURN) + # try to figure out if we are running the free command line + # tools from Microsoft. These tools do not provide debug libraries, + # so the link flags used have to be different. + MAKE_DIRECTORY("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp2") + SET(testForFreeVCFile + "${CMAKE_ROOT}/Modules/CMakeTestForFreeVC.cxx") + STRING(REGEX REPLACE "/" "\\\\" testForFreeVCFile "${testForFreeVCFile}") + MESSAGE(STATUS "Check if this is a free VC compiler") + EXEC_PROGRAM(${CMAKE_TEST_COMPILER} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp2 + ARGS /nologo /EHsc + \"${testForFreeVCFile}\" + OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT + RETURN_VALUE CMAKE_COMPILER_RETURN + ) + IF(CMAKE_COMPILER_RETURN) + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if this is a free VC compiler failed with the following output:\n" + "${CMAKE_COMPILER_OUTPUT}\n\n") + MESSAGE(STATUS "Check if this is a free VC compiler - yes") + SET(CMAKE_USING_VC_FREE_TOOLS 1) + ELSE(CMAKE_COMPILER_RETURN) + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if this is a free VC compiler passed with the following output:\n" + "${CMAKE_COMPILER_OUTPUT}\n\n") + MESSAGE(STATUS "Check if this is a free VC compiler - no") + SET(CMAKE_USING_VC_FREE_TOOLS 0) + ENDIF(CMAKE_COMPILER_RETURN) + MAKE_DIRECTORY("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp3") + ENDIF(NOT CMAKE_VC_COMPILER_TESTS_RUN) +ENDIF(CMAKE_GENERATOR MATCHES "Makefiles") + +IF(MSVC_C_ARCHITECTURE_ID MATCHES 64) + SET(CMAKE_CL_64 1) +ELSE(MSVC_C_ARCHITECTURE_ID MATCHES 64) + SET(CMAKE_CL_64 0) +ENDIF(MSVC_C_ARCHITECTURE_ID MATCHES 64) +IF(CMAKE_FORCE_WIN64) + SET(CMAKE_CL_64 1) +ENDIF(CMAKE_FORCE_WIN64) + +#IF("${MSVC_VERSION}" GREATER 1599) +# SET(MSVC_INCREMENTAL_DEFAULT ON) +#ENDIF() + +# No support for old versions +if(MSVC_VERSION LESS 1310) +message(FATAL_ERROR "Your compiler is too old. Get a newer version!") +endif() + +# for 2005 make sure the manifest is put in the dll with mt +#SET(CMAKE_CXX_CREATE_SHARED_LIBRARY " -E vs_link_dll ${CMAKE_CXX_CREATE_SHARED_LIBRARY}") +#SET(CMAKE_CXX_CREATE_SHARED_MODULE " -E vs_link_dll ${CMAKE_CXX_CREATE_SHARED_MODULE}") +# create a C shared library +#SET(CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}") +# create a C shared module just copy the shared library rule +#SET(CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE}") +#SET(CMAKE_CXX_LINK_EXECUTABLE " -E vs_link_exe ${CMAKE_CXX_LINK_EXECUTABLE}") +#SET(CMAKE_C_LINK_EXECUTABLE " -E vs_link_exe ${CMAKE_C_LINK_EXECUTABLE}") + +SET(CMAKE_BUILD_TYPE_INIT Debug) +SET(CMAKE_CXX_FLAGS_DEBUG_INIT "/Zi /Ob0 /Od") +SET(CMAKE_C_FLAGS_DEBUG_INIT "/Zi /Ob0 /Od") +SET(CMAKE_CXX_FLAGS_INIT "") +SET(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG") +SET(CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG") +SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1") +SET(CMAKE_C_FLAGS_INIT "") +SET(CMAKE_C_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG") +SET(CMAKE_C_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG") +SET(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1") +SET(CMAKE_C_STANDARD_LIBRARIES_INIT "") +SET(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT}") +SET(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") + +# executable linker flags +SET (CMAKE_LINK_DEF_FILE_FLAG "/DEF:") +# set the stack size and the machine type +SET(_MACHINE_ARCH_FLAG ${MSVC_C_ARCHITECTURE_ID}) +IF(NOT _MACHINE_ARCH_FLAG) + SET(_MACHINE_ARCH_FLAG ${MSVC_CXX_ARCHITECTURE_ID}) +ENDIF(NOT _MACHINE_ARCH_FLAG) +SET (CMAKE_EXE_LINKER_FLAGS_INIT + "${CMAKE_EXE_LINKER_FLAGS_INIT} /STACK:10000000 /machine:${_MACHINE_ARCH_FLAG}") + +# add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype +# on versions that support it +SET( MSVC_INCREMENTAL_YES_FLAG "") +IF(NOT MSVC_INCREMENTAL_DEFAULT) + SET( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES") +ENDIF() + +IF (CMAKE_COMPILER_SUPPORTS_PDBTYPE) + SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept") + SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") +ELSE (CMAKE_COMPILER_SUPPORTS_PDBTYPE) + SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug") + SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") +ENDIF (CMAKE_COMPILER_SUPPORTS_PDBTYPE) +# for release and minsize release default to no incremental linking +SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO") +SET(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO") + +# copy the EXE_LINKER flags to SHARED and MODULE linker flags +# shared linker flags +SET (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT}) +SET (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT}) +SET (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT}) +SET (CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT}) +SET (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT}) +# module linker flags +SET (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT}) +SET (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}) +SET (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT}) +SET (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT}) +SET (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT}) + +# save computed information for this platform +IF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake") + CONFIGURE_FILE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake.in + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCPlatform.cmake IMMEDIATE) +ENDIF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake") + +IF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake") + CONFIGURE_FILE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake.in + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXPlatform.cmake IMMEDIATE) +ENDIF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake") diff --git a/cmake/Platform/Windows.cmake b/cmake/Platform/Windows.cmake index a6988d4ce8a..a858e0c939f 100644 --- a/cmake/Platform/Windows.cmake +++ b/cmake/Platform/Windows.cmake @@ -1,36 +1,36 @@ -SET(WIN32 1) - -SET(CMAKE_STATIC_LIBRARY_PREFIX "") -SET(CMAKE_STATIC_LIBRARY_SUFFIX ".lib") -SET(CMAKE_SHARED_LIBRARY_PREFIX "") # lib -SET(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") # .so -SET(CMAKE_IMPORT_LIBRARY_PREFIX "") -SET(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib") -SET(CMAKE_EXECUTABLE_SUFFIX ".exe") # .exe -SET(CMAKE_LINK_LIBRARY_SUFFIX ".lib") -SET(CMAKE_DL_LIBS "") - -SET(CMAKE_FIND_LIBRARY_PREFIXES "") -SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") - -# for borland make long command lines are redirected to a file -# with the following syntax, see Windows-bcc32.cmake for use -IF(CMAKE_GENERATOR MATCHES "Borland") - SET(CMAKE_START_TEMP_FILE "@&&|\n") - SET(CMAKE_END_TEMP_FILE "\n|") -ENDIF(CMAKE_GENERATOR MATCHES "Borland") - -# for nmake make long command lines are redirected to a file -# with the following syntax, see Windows-bcc32.cmake for use -IF(CMAKE_GENERATOR MATCHES "NMake") -# SET(CMAKE_START_TEMP_FILE "@<<\n") -# SET(CMAKE_END_TEMP_FILE "\n<<") -ENDIF(CMAKE_GENERATOR MATCHES "NMake") - -INCLUDE(Platform/WindowsPaths) - -# uncomment these out to debug nmake and borland makefiles -SET(CMAKE_START_TEMP_FILE "") -SET(CMAKE_END_TEMP_FILE "") -#SET(CMAKE_VERBOSE_MAKEFILE 1) - +SET(WIN32 1) + +SET(CMAKE_STATIC_LIBRARY_PREFIX "") +SET(CMAKE_STATIC_LIBRARY_SUFFIX ".lib") +SET(CMAKE_SHARED_LIBRARY_PREFIX "") # lib +SET(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") # .so +SET(CMAKE_IMPORT_LIBRARY_PREFIX "") +SET(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib") +SET(CMAKE_EXECUTABLE_SUFFIX ".exe") # .exe +SET(CMAKE_LINK_LIBRARY_SUFFIX ".lib") +SET(CMAKE_DL_LIBS "") + +SET(CMAKE_FIND_LIBRARY_PREFIXES "") +SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") + +# for borland make long command lines are redirected to a file +# with the following syntax, see Windows-bcc32.cmake for use +IF(CMAKE_GENERATOR MATCHES "Borland") + SET(CMAKE_START_TEMP_FILE "@&&|\n") + SET(CMAKE_END_TEMP_FILE "\n|") +ENDIF(CMAKE_GENERATOR MATCHES "Borland") + +# for nmake make long command lines are redirected to a file +# with the following syntax, see Windows-bcc32.cmake for use +IF(CMAKE_GENERATOR MATCHES "NMake") +# SET(CMAKE_START_TEMP_FILE "@<<\n") +# SET(CMAKE_END_TEMP_FILE "\n<<") +ENDIF(CMAKE_GENERATOR MATCHES "NMake") + +INCLUDE(Platform/WindowsPaths) + +# uncomment these out to debug nmake and borland makefiles +SET(CMAKE_START_TEMP_FILE "") +SET(CMAKE_END_TEMP_FILE "") +#SET(CMAKE_VERBOSE_MAKEFILE 1) + diff --git a/cmake/config-amd64.cmake b/cmake/config-amd64.cmake index 31b0609b82c..d4d5a444bac 100644 --- a/cmake/config-amd64.cmake +++ b/cmake/config-amd64.cmake @@ -1,43 +1,43 @@ - -set(SARCH "" CACHE STRING -"Sub-architecture to build for.") - -set(OARCH "athlon64" CACHE STRING -"Generate instructions for this CPU type. Specify one of: - k8 opteron athlon64 athlon-fx") - -set (OPTIMIZE "1" CACHE STRING -"What level of optimisation to use. - 0 = off - 1 = Default option, optimize for size (-Os) with some additional options - 2 = -Os - 3 = -O1 - 4 = -O2 - 5 = -O3") - -set(DBG TRUE CACHE BOOL -"Whether to compile for debugging.") - -set(KDBG FALSE CACHE BOOL -"Whether to compile in the integrated kernel debugger.") - -set(GDB FALSE CACHE BOOL -"Whether to compile for debugging with GDB. -If you don't use GDB, don't enable this.") - -set(_WINKD_ TRUE CACHE BOOL -"Whether to compile with the KD protocol.") - -set(_ELF_ FALSE CACHE BOOL -"Whether to compile support for ELF files. -Do not enable unless you know what you're doing.") - -set(NSWPAT FALSE CACHE BOOL -"Whether to compile apps/libs with features covered software patents or not. -If you live in a country where software patents are valid/apply, don't -enable this (except they/you purchased a license from the patent owner). -This settings is disabled (0) by default.") - -set(USERMODE TRUE CACHE BOOL -"Whether to compile any usermode parts. This is while kernel mode is under - heavy development and usermode part not relevant for bootcd.") + +set(SARCH "" CACHE STRING +"Sub-architecture to build for.") + +set(OARCH "athlon64" CACHE STRING +"Generate instructions for this CPU type. Specify one of: + k8 opteron athlon64 athlon-fx") + +set (OPTIMIZE "1" CACHE STRING +"What level of optimisation to use. + 0 = off + 1 = Default option, optimize for size (-Os) with some additional options + 2 = -Os + 3 = -O1 + 4 = -O2 + 5 = -O3") + +set(DBG TRUE CACHE BOOL +"Whether to compile for debugging.") + +set(KDBG FALSE CACHE BOOL +"Whether to compile in the integrated kernel debugger.") + +set(GDB FALSE CACHE BOOL +"Whether to compile for debugging with GDB. +If you don't use GDB, don't enable this.") + +set(_WINKD_ TRUE CACHE BOOL +"Whether to compile with the KD protocol.") + +set(_ELF_ FALSE CACHE BOOL +"Whether to compile support for ELF files. +Do not enable unless you know what you're doing.") + +set(NSWPAT FALSE CACHE BOOL +"Whether to compile apps/libs with features covered software patents or not. +If you live in a country where software patents are valid/apply, don't +enable this (except they/you purchased a license from the patent owner). +This settings is disabled (0) by default.") + +set(USERMODE TRUE CACHE BOOL +"Whether to compile any usermode parts. This is while kernel mode is under + heavy development and usermode part not relevant for bootcd.") diff --git a/cmake/config-arm.cmake b/cmake/config-arm.cmake index 02ae1497e36..79f4ae58b8c 100644 --- a/cmake/config-arm.cmake +++ b/cmake/config-arm.cmake @@ -1,46 +1,46 @@ - -set(SARCH "omap3-zoom2" CACHE STRING -"Sub-architecture (board) to build for. Specify one of: - kurobox versatile omap3-zoom2 omap3-beagle") - -set(OARCH "armv7-a" CACHE STRING -"Generate instructions for this CPU type. Specify one of: - armv5te armv7-a") - -set (OPTIMIZE "1" CACHE STRING -"What level of optimisation to use. - 0 = off - 1 = Default option, optimize for size (-Os) with some additional options - 2 = -Os - 3 = -O1 - 4 = -O2 - 5 = -O3") - -set(DBG TRUE CACHE BOOL -"Whether to compile for debugging.") - -set(KDBG FALSE CACHE BOOL -"Whether to compile in the integrated kernel debugger.") - -set(GDB FALSE CACHE BOOL -"Whether to compile for debugging with GDB. -If you don't use GDB, don't enable this.") - -set(_WINKD_ TRUE CACHE BOOL -"Whether to compile with the KD protocol.") - -set(_ELF_ FALSE CACHE BOOL -"Whether to compile support for ELF files. -Do not enable unless you know what you're doing.") - -set(NSWPAT FALSE CACHE BOOL -"Whether to compile apps/libs with features covered software patents or not. -If you live in a country where software patents are valid/apply, don't -enable this (except they/you purchased a license from the patent owner). -This settings is disabled (0) by default.") - -set(BUILD_MP TRUE CACHE BOOL -"Whether to compile the multi processor versions for ntoskrnl and hal.") - -set(NEWSPRINTF FALSE CACHE BOOL -"Whether to compile the new sprintf.") + +set(SARCH "omap3-zoom2" CACHE STRING +"Sub-architecture (board) to build for. Specify one of: + kurobox versatile omap3-zoom2 omap3-beagle") + +set(OARCH "armv7-a" CACHE STRING +"Generate instructions for this CPU type. Specify one of: + armv5te armv7-a") + +set (OPTIMIZE "1" CACHE STRING +"What level of optimisation to use. + 0 = off + 1 = Default option, optimize for size (-Os) with some additional options + 2 = -Os + 3 = -O1 + 4 = -O2 + 5 = -O3") + +set(DBG TRUE CACHE BOOL +"Whether to compile for debugging.") + +set(KDBG FALSE CACHE BOOL +"Whether to compile in the integrated kernel debugger.") + +set(GDB FALSE CACHE BOOL +"Whether to compile for debugging with GDB. +If you don't use GDB, don't enable this.") + +set(_WINKD_ TRUE CACHE BOOL +"Whether to compile with the KD protocol.") + +set(_ELF_ FALSE CACHE BOOL +"Whether to compile support for ELF files. +Do not enable unless you know what you're doing.") + +set(NSWPAT FALSE CACHE BOOL +"Whether to compile apps/libs with features covered software patents or not. +If you live in a country where software patents are valid/apply, don't +enable this (except they/you purchased a license from the patent owner). +This settings is disabled (0) by default.") + +set(BUILD_MP TRUE CACHE BOOL +"Whether to compile the multi processor versions for ntoskrnl and hal.") + +set(NEWSPRINTF FALSE CACHE BOOL +"Whether to compile the new sprintf.") diff --git a/cmake/config.cmake b/cmake/config.cmake index dbcc85a6a27..aabef676321 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -1,57 +1,57 @@ - -set(SARCH "pc" CACHE STRING -"Sub-architecture to build for. Specify one of: xbox") - -set(OARCH "pentium" CACHE STRING -"Generate instructions for this CPU type. Specify one of: - native, i386, i486, pentium, pentium-mmx, pentiumpro, i686, - pentium2, pentium3, pentium-m, pentium4, prescott, nocona, - core2, k6, k6-2, athlon, athlon-xp, opteron, opteron-sse3, - barcelona, winchip-c6, winchip2, c3, c3-2, geode") - -set(TUNE "i686" CACHE STRING -"Which CPU ReactOS should be optimized for.") - -set(OPTIMIZE "1" CACHE STRING -"What level of optimisation to use. - 0 = off - 1 = Default option, optimize for size (-Os) with some additional options - 2 = -Os - 3 = -O1 - 4 = -O2 - 5 = -O3") - -set(GDB FALSE CACHE BOOL -"Whether to compile for debugging with GDB. -If you don't use GDB, don't enable this.") - -set(DBG TRUE CACHE BOOL -"Whether to compile for debugging.") - -if(MSVC) - set(KDBG FALSE CACHE BOOL -"Whether to compile in the integrated kernel debugger.") - set(_WINKD_ TRUE CACHE BOOL -"Whether to compile with the KD protocol.") -else() - set(KDBG TRUE CACHE BOOL -"Whether to compile in the integrated kernel debugger.") - set(_WINKD_ FALSE CACHE BOOL -"Whether to compile with the KD protocol.") -endif() - -set(_ELF_ FALSE CACHE BOOL -"Whether to compile support for ELF files. -Do not enable unless you know what you're doing.") - -set(NSWPAT FALSE CACHE BOOL -"Whether to compile apps/libs with features covered software patents or not. -If you live in a country where software patents are valid/apply, don't -enable this (except they/you purchased a license from the patent owner). -This settings is disabled (0) by default.") - -set(BUILD_MP TRUE CACHE BOOL -"Whether to compile the multi processor versions for ntoskrnl and hal.") - -set(GENERATE_DEPENDENCY_GRAPH FALSE CACHE BOOL -"Whether to create a graphml dependency of dlls.") + +set(SARCH "pc" CACHE STRING +"Sub-architecture to build for. Specify one of: xbox") + +set(OARCH "pentium" CACHE STRING +"Generate instructions for this CPU type. Specify one of: + native, i386, i486, pentium, pentium-mmx, pentiumpro, i686, + pentium2, pentium3, pentium-m, pentium4, prescott, nocona, + core2, k6, k6-2, athlon, athlon-xp, opteron, opteron-sse3, + barcelona, winchip-c6, winchip2, c3, c3-2, geode") + +set(TUNE "i686" CACHE STRING +"Which CPU ReactOS should be optimized for.") + +set(OPTIMIZE "1" CACHE STRING +"What level of optimisation to use. + 0 = off + 1 = Default option, optimize for size (-Os) with some additional options + 2 = -Os + 3 = -O1 + 4 = -O2 + 5 = -O3") + +set(GDB FALSE CACHE BOOL +"Whether to compile for debugging with GDB. +If you don't use GDB, don't enable this.") + +set(DBG TRUE CACHE BOOL +"Whether to compile for debugging.") + +if(MSVC) + set(KDBG FALSE CACHE BOOL +"Whether to compile in the integrated kernel debugger.") + set(_WINKD_ TRUE CACHE BOOL +"Whether to compile with the KD protocol.") +else() + set(KDBG TRUE CACHE BOOL +"Whether to compile in the integrated kernel debugger.") + set(_WINKD_ FALSE CACHE BOOL +"Whether to compile with the KD protocol.") +endif() + +set(_ELF_ FALSE CACHE BOOL +"Whether to compile support for ELF files. +Do not enable unless you know what you're doing.") + +set(NSWPAT FALSE CACHE BOOL +"Whether to compile apps/libs with features covered software patents or not. +If you live in a country where software patents are valid/apply, don't +enable this (except they/you purchased a license from the patent owner). +This settings is disabled (0) by default.") + +set(BUILD_MP TRUE CACHE BOOL +"Whether to compile the multi processor versions for ntoskrnl and hal.") + +set(GENERATE_DEPENDENCY_GRAPH FALSE CACHE BOOL +"Whether to create a graphml dependency of dlls.") diff --git a/dll/directx/ksproxy/datatype.cpp b/dll/directx/ksproxy/datatype.cpp index 8ad71a5ca8d..965e847b55b 100644 --- a/dll/directx/ksproxy/datatype.cpp +++ b/dll/directx/ksproxy/datatype.cpp @@ -11,8 +11,6 @@ /* FIXME guid mess */ #ifndef _MSC_VER const GUID IID_IUnknown = {0x00000000, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; -#else -const GUID IID_IKsDataTypeHandler = {0x5FFBAA02L, 0x49A3, 0x11D0, {0x9F, 0x36, 0x00, 0xAA, 0x00, 0xA2, 0x16, 0xA1}}; #endif const GUID IID_IClassFactory = {0x00000001, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; diff --git a/dll/directx/ksproxy/input_pin.cpp b/dll/directx/ksproxy/input_pin.cpp index d6b5b5a2fca..e56eacb938c 100644 --- a/dll/directx/ksproxy/input_pin.cpp +++ b/dll/directx/ksproxy/input_pin.cpp @@ -10,10 +10,8 @@ const GUID IID_IKsPinPipe = {0xe539cd90, 0xa8b4, 0x11d1, {0x81, 0x89, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02}}; const GUID IID_IKsPinEx = {0x7bb38260L, 0xd19c, 0x11d2, {0xb3, 0x8a, 0x00, 0xa0, 0xc9, 0x5e, 0xc2, 0x2e}}; -#ifdef _MSC_VER -const GUID IID_IKsPin = {0xb61178d1L, 0xa2d9, 0x11cf, {0x9e, 0x53, 0x00, 0xaa, 0x00, 0xa2, 0x16, 0xa1}}; -const GUID IID_IKsInterfaceHandler = {0xD3ABC7E0L, 0x9A61, 0x11D0, {0xA4, 0x0D, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}}; -#endif + + #ifndef _MSC_VER const GUID KSPROPSETID_Connection = {0x1D58C920L, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}; diff --git a/dll/directx/ksproxy/interface.cpp b/dll/directx/ksproxy/interface.cpp index 67196fbe60f..7eb0fd284d5 100644 --- a/dll/directx/ksproxy/interface.cpp +++ b/dll/directx/ksproxy/interface.cpp @@ -10,8 +10,6 @@ const GUID IID_IKsObject = {0x423c13a2, 0x2070, 0x11d0, {0x9e, 0xf7, 0x00, 0xaa, 0x00, 0xa2, 0x16, 0xa1}}; -extern const GUID IID_IKsInterfaceHandler; - class CKsInterfaceHandler : public IKsInterfaceHandler { public: diff --git a/dll/directx/ksproxy/ksproxy.cpp b/dll/directx/ksproxy/ksproxy.cpp index 545af53154d..7baa7e30496 100644 --- a/dll/directx/ksproxy/ksproxy.cpp +++ b/dll/directx/ksproxy/ksproxy.cpp @@ -16,13 +16,12 @@ const GUID CLSID_KsQualityForwarder = {0xe05592e4, 0xc0b5, 0x11d0, {0 #ifndef _MSC_VER +const GUID CLSID_KsIBasicAudioInterfaceHandler = {0xb9f8ac3e, 0x0f71, 0x11d2, {0xb7, 0x2c, 0x00, 0xc0, 0x4f, 0xb6, 0xbd, 0x3d}}; const GUID KSPROPSETID_Pin = {0x8C134960, 0x51AD, 0x11CF, {0x87, 0x8A, 0x94, 0xF8, 0x01, 0xC1, 0x00, 0x00}}; const GUID KSINTERFACESETID_Standard = {STATIC_KSINTERFACESETID_Standard}; const GUID CLSID_Proxy = {0x17CCA71B, 0xECD7, 0x11D0, {0xB9, 0x08, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}}; #endif -const GUID CLSID_KsIBasicAudioInterfaceHandler = {0xb9f8ac3e, 0x0f71, 0x11d2, {0xb7, 0x2c, 0x00, 0xc0, 0x4f, 0xb6, 0xbd, 0x3d}}; - static INTERFACE_TABLE InterfaceTable[] = { {&MEDIATYPE_Audio, CKsDataTypeHandler_Constructor}, diff --git a/dll/directx/ksproxy/output_pin.cpp b/dll/directx/ksproxy/output_pin.cpp index c096ab4ea54..2bf85c8a06b 100644 --- a/dll/directx/ksproxy/output_pin.cpp +++ b/dll/directx/ksproxy/output_pin.cpp @@ -8,9 +8,6 @@ */ #include "precomp.h" -extern const GUID IID_IKsPin; -extern const GUID IID_IKsInterfaceHandler; - class COutputPin : public IPin, public IKsObject, public IKsPropertySet, @@ -1684,7 +1681,7 @@ COutputPin::Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) if (GetSupportedSets(&pGuid, &NumGuids)) { // load all proxy plugins - if (FAILED(LoadProxyPlugins(pGuid, NumGuids))) + if (FAILED(LoadProxyPlugins(pGuid, NumGuids))); { #ifdef KSPROXY_TRACE OutputDebugStringW(L"COutputPin::Connect LoadProxyPlugins failed\n"); diff --git a/dll/directx/wine/d3dx9_24/d3dx9_24.spec b/dll/directx/wine/d3dx9_24/d3dx9_24.spec index 6f86ff0d57c..3a7e007e873 100644 --- a/dll/directx/wine/d3dx9_24/d3dx9_24.spec +++ b/dll/directx/wine/d3dx9_24/d3dx9_24.spec @@ -26,7 +26,7 @@ @ stdcall D3DXConcatenateMeshes(ptr long long ptr ptr ptr ptr ptr) d3dx9_36.D3DXConcatenateMeshes @ stdcall D3DXConvertMeshSubsetToSingleStrip(ptr long long ptr ptr) d3dx9_36.D3DXConvertMeshSubsetToSingleStrip @ stdcall D3DXConvertMeshSubsetToStrips(ptr long long ptr ptr ptr ptr) d3dx9_36.D3DXConvertMeshSubsetToStrips -@ stdcall -stub D3DXCpuOptimizations(long) +@ stub D3DXCpuOptimizations @ stdcall D3DXCreateAnimationController(long long long long ptr) d3dx9_36.D3DXCreateAnimationController @ stdcall D3DXCreateBox(ptr long long long ptr ptr) d3dx9_36.D3DXCreateBox @ stdcall D3DXCreateBuffer(long ptr) d3dx9_36.D3DXCreateBuffer @@ -159,8 +159,8 @@ @ stdcall D3DXGetShaderSamplers(ptr ptr ptr) d3dx9_36.D3DXGetShaderSamplers @ stdcall D3DXGetShaderSize(ptr) d3dx9_36.D3DXGetShaderSize @ stdcall D3DXGetShaderVersion(ptr) d3dx9_36.D3DXGetShaderVersion -@ stdcall -stub D3DXGetTargetDescByName(long long long) -@ stdcall -stub D3DXGetTargetDescByVersion(long long long) +@ stub D3DXGetTargetDescByName +@ stub D3DXGetTargetDescByVersion @ stdcall D3DXGetVertexShaderProfile(ptr) d3dx9_36.D3DXGetVertexShaderProfile @ stdcall D3DXIntersect(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) d3dx9_36.D3DXIntersect @ stdcall D3DXIntersectSubset(ptr long ptr ptr ptr ptr ptr ptr ptr ptr ptr) d3dx9_36.D3DXIntersectSubset @@ -185,7 +185,7 @@ @ stdcall D3DXLoadSurfaceFromMemory(ptr ptr ptr ptr long long ptr ptr long long) d3dx9_36.D3DXLoadSurfaceFromMemory @ stdcall D3DXLoadSurfaceFromResourceA(ptr ptr ptr long ptr ptr long long ptr) d3dx9_36.D3DXLoadSurfaceFromResourceA @ stdcall D3DXLoadSurfaceFromResourceW(ptr ptr ptr long ptr ptr long long ptr) d3dx9_36.D3DXLoadSurfaceFromResourceW -@ stdcall D3DXLoadSurfaceFromSurface(ptr ptr ptr ptr ptr ptr long long) d3dx9_36.D3DXLoadSurfaceFromSurface +@ stdcall D3DXLoadSurfaceFromSurface(ptr ptr ptr ptr ptr ptr long) d3dx9_36.D3DXLoadSurfaceFromSurface @ stdcall D3DXLoadVolumeFromFileA(ptr ptr ptr ptr ptr long long ptr) d3dx9_36.D3DXLoadVolumeFromFileA @ stdcall D3DXLoadVolumeFromFileInMemory(ptr ptr ptr ptr long ptr long long ptr) d3dx9_36.D3DXLoadVolumeFromFileInMemory @ stdcall D3DXLoadVolumeFromFileW(ptr ptr ptr ptr ptr long long ptr) d3dx9_36.D3DXLoadVolumeFromFileW diff --git a/dll/directx/wine/d3dx9_36/d3dx9_36.spec b/dll/directx/wine/d3dx9_36/d3dx9_36.spec index 94b29bcfd02..792408194d2 100644 --- a/dll/directx/wine/d3dx9_36/d3dx9_36.spec +++ b/dll/directx/wine/d3dx9_36/d3dx9_36.spec @@ -4,150 +4,150 @@ @ stdcall D3DXAssembleShaderFromResourceA(long str ptr ptr long ptr ptr) @ stdcall D3DXAssembleShaderFromResourceW(long wstr ptr ptr long ptr ptr) @ stdcall D3DXBoxBoundProbe(ptr ptr ptr ptr) -@ stdcall -stub D3DXCheckCubeTextureRequirements(ptr ptr ptr long ptr long) -@ stdcall -stub D3DXCheckTextureRequirements(ptr ptr ptr ptr long ptr long) +@ stub D3DXCheckCubeTextureRequirements +@ stub D3DXCheckTextureRequirements @ stdcall D3DXCheckVersion(long long) -@ stdcall -stub D3DXCheckVolumeTextureRequirements(ptr ptr ptr ptr ptr long ptr long) -@ stdcall -stub D3DXCleanMesh(ptr ptr ptr ptr ptr) +@ stub D3DXCheckVolumeTextureRequirements +@ stub D3DXCleanMesh @ stdcall D3DXColorAdjustContrast(ptr ptr long) @ stdcall D3DXColorAdjustSaturation(ptr ptr long) @ stdcall D3DXCompileShader(ptr long ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCompileShaderFromFileA(ptr ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCompileShaderFromFileW(ptr ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCompileShaderFromResourceA(long ptr ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCompileShaderFromResourceW(long ptr ptr ptr ptr ptr long ptr ptr ptr) +@ stub D3DXCompileShaderFromFileA +@ stub D3DXCompileShaderFromFileW +@ stub D3DXCompileShaderFromResourceA +@ stub D3DXCompileShaderFromResourceW @ stdcall D3DXComputeBoundingBox(ptr long long ptr ptr) @ stdcall D3DXComputeBoundingSphere(ptr long long ptr ptr) @ stub D3DXComputeIMTFromPerTexelSignal @ stub D3DXComputeIMTFromPerVertexSignal @ stub D3DXComputeIMTFromSignal @ stub D3DXComputeIMTFromTexture -@ stdcall -stub D3DXComputeNormalMap(ptr ptr ptr long long long) -@ stdcall -stub D3DXComputeNormals(ptr ptr) -@ stdcall -stub D3DXComputeTangent(ptr long long long long ptr) -@ stdcall -stub D3DXComputeTangentFrame(ptr long) -@ stdcall -stub D3DXComputeTangentFrameEx(ptr long long long long long long long long long ptr long long long ptr ptr) -@ stdcall -stub D3DXConcatenateMeshes(ptr long long ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXConvertMeshSubsetToSingleStrip(ptr long long ptr ptr) -@ stdcall -stub D3DXConvertMeshSubsetToStrips(ptr long long ptr ptr ptr ptr) -@ stdcall -stub D3DXCreateAnimationController(long long long long ptr) -@ stdcall -stub D3DXCreateBox(ptr long long long ptr ptr) +@ stub D3DXComputeNormalMap +@ stub D3DXComputeNormals +@ stub D3DXComputeTangent +@ stub D3DXComputeTangentFrame +@ stub D3DXComputeTangentFrameEx +@ stub D3DXConcatenateMeshes +@ stub D3DXConvertMeshSubsetToSingleStrip +@ stub D3DXConvertMeshSubsetToStrips +@ stub D3DXCreateAnimationController +@ stub D3DXCreateBox @ stdcall D3DXCreateBuffer(long ptr) -@ stdcall -stub D3DXCreateCompressedAnimationSet(ptr long long ptr long ptr ptr) -@ stdcall -stub D3DXCreateCubeTexture(ptr long long long long long ptr) -@ stdcall -stub D3DXCreateCubeTextureFromFileA(ptr ptr ptr) -@ stdcall -stub D3DXCreateCubeTextureFromFileExA(ptr ptr long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateCubeTextureFromFileExW(ptr ptr long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateCubeTextureFromFileInMemory(ptr ptr long ptr) -@ stdcall -stub D3DXCreateCubeTextureFromFileInMemoryEx(ptr ptr long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateCubeTextureFromFileW(ptr ptr ptr) -@ stdcall -stub D3DXCreateCubeTextureFromResourceA(ptr long ptr ptr) d3dx9_36.D3DXCreateCubeTextureFromResourceA -@ stdcall -stub D3DXCreateCubeTextureFromResourceExA(ptr long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateCubeTextureFromResourceExW(ptr long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateCubeTextureFromResourceW(ptr long ptr ptr) -@ stdcall -stub D3DXCreateCylinder(ptr long long long long long ptr ptr) -@ stdcall -stub D3DXCreateEffect(ptr ptr long ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectCompiler(ptr long ptr ptr long ptr ptr) -@ stdcall -stub D3DXCreateEffectCompilerFromFileA(ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXCreateEffectCompilerFromFileW(ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXCreateEffectCompilerFromResourceA(long ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXCreateEffectCompilerFromResourceW(long ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXCreateEffectEx(ptr ptr long ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromFileA(ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromFileExA(ptr ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromFileExW(ptr ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromFileW(ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromResourceA(ptr long ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromResourceExA(ptr long ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromResourceExW(ptr long ptr ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectFromResourceW(ptr long ptr ptr ptr long ptr ptr ptr) -@ stdcall -stub D3DXCreateEffectPool(ptr) +@ stub D3DXCreateCompressedAnimationSet +@ stub D3DXCreateCubeTexture +@ stub D3DXCreateCubeTextureFromFileA +@ stub D3DXCreateCubeTextureFromFileExA +@ stub D3DXCreateCubeTextureFromFileExW +@ stub D3DXCreateCubeTextureFromFileInMemory +@ stub D3DXCreateCubeTextureFromFileInMemoryEx +@ stub D3DXCreateCubeTextureFromFileW +@ stub D3DXCreateCubeTextureFromResourceA +@ stub D3DXCreateCubeTextureFromResourceExA +@ stub D3DXCreateCubeTextureFromResourceExW +@ stub D3DXCreateCubeTextureFromResourceW +@ stub D3DXCreateCylinder +@ stub D3DXCreateEffect +@ stub D3DXCreateEffectCompiler +@ stub D3DXCreateEffectCompilerFromFileA +@ stub D3DXCreateEffectCompilerFromFileW +@ stub D3DXCreateEffectCompilerFromResourceA +@ stub D3DXCreateEffectCompilerFromResourceW +@ stub D3DXCreateEffectEx +@ stub D3DXCreateEffectFromFileA +@ stub D3DXCreateEffectFromFileExA +@ stub D3DXCreateEffectFromFileExW +@ stub D3DXCreateEffectFromFileW +@ stub D3DXCreateEffectFromResourceA +@ stub D3DXCreateEffectFromResourceExA +@ stub D3DXCreateEffectFromResourceExW +@ stub D3DXCreateEffectFromResourceW +@ stub D3DXCreateEffectPool @ stdcall D3DXCreateFontA(ptr long long long long long long long long long str ptr) @ stdcall D3DXCreateFontIndirectA(ptr ptr ptr) @ stdcall D3DXCreateFontIndirectW(ptr ptr ptr) @ stdcall D3DXCreateFontW(ptr long long long long long long long long long wstr ptr) -@ stdcall -stub D3DXCreateFragmentLinker(ptr long ptr) +@ stub D3DXCreateFragmentLinker @ stub D3DXCreateFragmentLinkerEx -@ stdcall -stub D3DXCreateKeyframedAnimationSet(ptr long long long long ptr ptr) -@ stdcall -stub D3DXCreateLine(ptr ptr) +@ stub D3DXCreateKeyframedAnimationSet +@ stub D3DXCreateLine @ stdcall D3DXCreateMatrixStack(long ptr) -@ stdcall -stub D3DXCreateMesh(long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateMeshFVF(long long long long ptr ptr) -@ stdcall -stub D3DXCreateNPatchMesh(ptr ptr) -@ stdcall -stub D3DXCreatePMeshFromStream(ptr long ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXCreatePatchMesh(ptr long long long ptr ptr ptr) -@ stdcall -stub D3DXCreatePolygon(ptr long long ptr ptr) -@ stdcall -stub D3DXCreatePRTBuffer(long long long ptr) -@ stdcall -stub D3DXCreatePRTBufferTex(long long long long ptr) -@ stdcall -stub D3DXCreatePRTCompBuffer(long long long ptr ptr ptr ptr) -@ stdcall -stub D3DXCreatePRTEngine(ptr ptr long ptr ptr) -@ stdcall -stub D3DXCreateRenderToEnvMap(ptr long long long long long ptr) -@ stdcall -stub D3DXCreateRenderToSurface(ptr long long long long long ptr) -@ stdcall -stub D3DXCreateSPMesh(ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXCreateSkinInfo(long ptr long ptr) -@ stdcall -stub D3DXCreateSkinInfoFromBlendedMesh(ptr long ptr ptr) -@ stdcall -stub D3DXCreateSkinInfoFVF(long long long ptr) -@ stdcall -stub D3DXCreateSphere(ptr long long long ptr ptr) +@ stub D3DXCreateMesh +@ stub D3DXCreateMeshFVF +@ stub D3DXCreateNPatchMesh +@ stub D3DXCreatePMeshFromStream +@ stub D3DXCreatePatchMesh +@ stub D3DXCreatePolygon +@ stub D3DXCreatePRTBuffer +@ stub D3DXCreatePRTBufferTex +@ stub D3DXCreatePRTCompBuffer +@ stub D3DXCreatePRTEngine +@ stub D3DXCreateRenderToEnvMap +@ stub D3DXCreateRenderToSurface +@ stub D3DXCreateSPMesh +@ stub D3DXCreateSkinInfo +@ stub D3DXCreateSkinInfoFromBlendedMesh +@ stub D3DXCreateSkinInfoFVF +@ stub D3DXCreateSphere @ stdcall D3DXCreateSprite(ptr ptr) -@ stdcall -stub D3DXCreateTeapot(ptr ptr ptr) -@ stdcall -stub D3DXCreateTextA(ptr long ptr long long ptr ptr ptr) -@ stdcall -stub D3DXCreateTextW(ptr long ptr long long ptr ptr ptr) +@ stub D3DXCreateTeapot +@ stub D3DXCreateTextA +@ stub D3DXCreateTextW @ stdcall D3DXCreateTexture(ptr long long long long long long ptr) -@ stdcall -stub D3DXCreateTextureFromFileA(ptr ptr ptr) -@ stdcall -stub D3DXCreateTextureFromFileExA(ptr ptr long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateTextureFromFileExW(ptr ptr long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateTextureFromFileInMemory(ptr ptr long ptr) -@ stdcall -stub D3DXCreateTextureFromFileInMemoryEx(ptr ptr long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateTextureFromFileW(ptr ptr ptr) -@ stdcall -stub D3DXCreateTextureFromResourceA(ptr long ptr ptr) -@ stdcall -stub D3DXCreateTextureFromResourceExA(ptr long ptr long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateTextureFromResourceExW(ptr long ptr long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateTextureFromResourceW(ptr long ptr ptr) -@ stdcall -stub D3DXCreateTextureGutterHelper(long long ptr long ptr) -@ stdcall -stub D3DXCreateTextureShader(ptr ptr) -@ stdcall -stub D3DXCreateTorus(ptr long long long long ptr ptr) -@ stdcall -stub D3DXCreateVolumeTexture(ptr long long long long long long long ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromFileA(ptr ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromFileExA(ptr ptr long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromFileExW(ptr ptr long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromFileInMemory(ptr ptr long ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromFileInMemoryEx(ptr ptr long long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromFileW(ptr ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromResourceA(ptr long ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromResourceExA(ptr long ptr long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromResourceExW(ptr long ptr long long long long long long long long long long ptr ptr ptr) -@ stdcall -stub D3DXCreateVolumeTextureFromResourceW(ptr long ptr ptr) +@ stub D3DXCreateTextureFromFileA +@ stub D3DXCreateTextureFromFileExA +@ stub D3DXCreateTextureFromFileExW +@ stub D3DXCreateTextureFromFileInMemory +@ stub D3DXCreateTextureFromFileInMemoryEx +@ stub D3DXCreateTextureFromFileW +@ stub D3DXCreateTextureFromResourceA +@ stub D3DXCreateTextureFromResourceExA +@ stub D3DXCreateTextureFromResourceExW +@ stub D3DXCreateTextureFromResourceW +@ stub D3DXCreateTextureGutterHelper +@ stub D3DXCreateTextureShader +@ stub D3DXCreateTorus +@ stub D3DXCreateVolumeTexture +@ stub D3DXCreateVolumeTextureFromFileA +@ stub D3DXCreateVolumeTextureFromFileExA +@ stub D3DXCreateVolumeTextureFromFileExW +@ stub D3DXCreateVolumeTextureFromFileInMemory +@ stub D3DXCreateVolumeTextureFromFileInMemoryEx +@ stub D3DXCreateVolumeTextureFromFileW +@ stub D3DXCreateVolumeTextureFromResourceA +@ stub D3DXCreateVolumeTextureFromResourceExA +@ stub D3DXCreateVolumeTextureFromResourceExW +@ stub D3DXCreateVolumeTextureFromResourceW @ stdcall D3DXDebugMute(long) -@ stdcall -stub D3DXDeclaratorFromFVF(long ptr) -@ stdcall -stub D3DXDisassembleEffect(ptr long ptr) -@ stdcall -stub D3DXDisassembleShader(ptr long ptr ptr) -@ stdcall -stub D3DXFileCreate(ptr) -@ stdcall -stub D3DXFillCubeTexture(ptr ptr ptr) -@ stdcall -stub D3DXFillCubeTextureTX(ptr ptr)TX -@ stdcall -stub D3DXFillTexture(ptr ptr ptr) -@ stdcall -stub D3DXFillTextureTX(ptr ptr) -@ stdcall -stub D3DXFillVolumeTexture(ptr ptr ptr) -@ stdcall -stub D3DXFillVolumeTextureTX(ptr ptr) -@ stdcall -stub D3DXFilterTexture(ptr ptr long long) +@ stub D3DXDeclaratorFromFVF +@ stub D3DXDisassembleEffect +@ stub D3DXDisassembleShader +@ stub D3DXFileCreate +@ stub D3DXFillCubeTexture +@ stub D3DXFillCubeTextureTX +@ stub D3DXFillTexture +@ stub D3DXFillTextureTX +@ stub D3DXFillVolumeTexture +@ stub D3DXFillVolumeTextureTX +@ stub D3DXFilterTexture @ stdcall D3DXFindShaderComment(ptr long ptr ptr) -@ stdcall -stub D3DXFloat16To32Array(ptr ptr long) -@ stdcall -stub D3DXFloat32To16Array(ptr ptr long) -@ stdcall -stub D3DXFrameAppendChild(ptr ptr) -@ stdcall -stub D3DXFrameCalculateBoundingSphere(ptr ptr ptr) -@ stdcall -stub D3DXFrameDestroy(ptr ptr) -@ stdcall -stub D3DXFrameFind(ptr ptr) -@ stdcall -stub D3DXFrameNumNamedMatrices(ptr) -@ stdcall -stub D3DXFrameRegisterNamedMatrices(ptr ptr) +@ stub D3DXFloat16To32Array +@ stub D3DXFloat32To16Array +@ stub D3DXFrameAppendChild +@ stub D3DXFrameCalculateBoundingSphere +@ stub D3DXFrameDestroy +@ stub D3DXFrameFind +@ stub D3DXFrameNumNamedMatrices +@ stub D3DXFrameRegisterNamedMatrices @ stdcall D3DXFresnelTerm(long long) -@ stdcall -stub D3DXFVFFromDeclarator(ptr ptr) -@ stdcall -stub D3DXGatherFragments(ptr long ptr ptr long ptr ptr) -@ stdcall -stub D3DXGatherFragmentsFromFileA(ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXGatherFragmentsFromFileW(ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXGatherFragmentsFromResourceA(long ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXGatherFragmentsFromResourceW(long ptr ptr ptr long ptr ptr) -@ stdcall -stub D3DXGenerateOutputDecl(ptr ptr) -@ stdcall -stub D3DXGeneratePMesh(ptr ptr ptr ptr long long ptr) -@ stdcall -stub D3DXGetDeclLength(ptr) +@ stub D3DXFVFFromDeclarator +@ stub D3DXGatherFragments +@ stub D3DXGatherFragmentsFromFileA +@ stub D3DXGatherFragmentsFromFileW +@ stub D3DXGatherFragmentsFromResourceA +@ stub D3DXGatherFragmentsFromResourceW +@ stub D3DXGenerateOutputDecl +@ stub D3DXGeneratePMesh +@ stub D3DXGetDeclLength @ stdcall D3DXGetDeclVertexSize(ptr long) @ stdcall D3DXGetDriverLevel(ptr) @ stdcall D3DXGetFVFVertexSize(long) @@ -159,29 +159,29 @@ @ stdcall D3DXGetPixelShaderProfile(ptr) @ stdcall D3DXGetShaderConstantTable(ptr ptr) @ stdcall D3DXGetShaderConstantTableEx(ptr long ptr) -@ stdcall -stub D3DXGetShaderInputSemantics(ptr ptr ptr) -@ stdcall -stub D3DXGetShaderOutputSemantics(ptr ptr ptr) -@ stdcall -stub D3DXGetShaderSamplers(ptr ptr ptr) +@ stub D3DXGetShaderInputSemantics +@ stub D3DXGetShaderOutputSemantics +@ stub D3DXGetShaderSamplers @ stdcall D3DXGetShaderSize(ptr) @ stdcall D3DXGetShaderVersion(ptr) @ stdcall D3DXGetVertexShaderProfile(ptr) -@ stdcall -stub D3DXIntersect(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXIntersectSubset(ptr long ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ stub D3DXIntersect +@ stub D3DXIntersectSubset @ stdcall D3DXIntersectTri(ptr ptr ptr ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshFromXA(ptr long ptr ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshFromXInMemory(ptr long long ptr ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshFromXResource(long ptr ptr long ptr ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshFromXW(ptr long ptr ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshFromXof(ptr long ptr ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshHierarchyFromXA(ptr long ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshHierarchyFromXInMemory(ptr long long ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadMeshHierarchyFromXW(ptr long ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXLoadPatchMeshFromXof(ptr long ptr ptr ptr long ptr) -@ stdcall -stub D3DXLoadPRTBufferFromFileA(ptr ptr) -@ stdcall -stub D3DXLoadPRTBufferFromFileW(ptr ptr) -@ stdcall -stub D3DXLoadPRTCompBufferFromFileA(ptr ptr) -@ stdcall -stub D3DXLoadPRTCompBufferFromFileW(ptr ptr) -@ stdcall -stub D3DXLoadSkinMeshFromXof(ptr long ptr ptr ptr ptr ptr ptr ptr) +@ stub D3DXLoadMeshFromXA +@ stub D3DXLoadMeshFromXInMemory +@ stub D3DXLoadMeshFromXResource +@ stub D3DXLoadMeshFromXW +@ stub D3DXLoadMeshFromXof +@ stub D3DXLoadMeshHierarchyFromXA +@ stub D3DXLoadMeshHierarchyFromXInMemory +@ stub D3DXLoadMeshHierarchyFromXW +@ stub D3DXLoadPatchMeshFromXof +@ stub D3DXLoadPRTBufferFromFileA +@ stub D3DXLoadPRTBufferFromFileW +@ stub D3DXLoadPRTCompBufferFromFileA +@ stub D3DXLoadPRTCompBufferFromFileW +@ stub D3DXLoadSkinMeshFromXof @ stdcall D3DXLoadSurfaceFromFileA(ptr ptr ptr str ptr long long ptr) @ stdcall D3DXLoadSurfaceFromFileInMemory(ptr ptr ptr ptr long ptr long long ptr) @ stdcall D3DXLoadSurfaceFromFileW(ptr ptr ptr wstr ptr long long ptr) @@ -189,13 +189,13 @@ @ stdcall D3DXLoadSurfaceFromResourceA(ptr ptr ptr ptr str ptr long long ptr) @ stdcall D3DXLoadSurfaceFromResourceW(ptr ptr ptr ptr wstr ptr long long ptr) @ stdcall D3DXLoadSurfaceFromSurface(ptr ptr ptr ptr ptr ptr long long) -@ stdcall -stub D3DXLoadVolumeFromFileA(ptr ptr ptr ptr ptr long long ptr) -@ stdcall -stub D3DXLoadVolumeFromFileInMemory(ptr ptr ptr ptr long ptr long long ptr) -@ stdcall -stub D3DXLoadVolumeFromFileW(ptr ptr ptr ptr ptr long long ptr) -@ stdcall -stub D3DXLoadVolumeFromMemory(ptr ptr ptr ptr long long long ptr ptr long long) -@ stdcall -stub D3DXLoadVolumeFromResourceA(ptr ptr ptr long ptr ptr long long ptr) -@ stdcall -stub D3DXLoadVolumeFromResourceW(ptr ptr ptr long ptr ptr long long ptr) -@ stdcall -stub D3DXLoadVolumeFromVolume(ptr ptr ptr ptr ptr ptr long long) +@ stub D3DXLoadVolumeFromFileA +@ stub D3DXLoadVolumeFromFileInMemory +@ stub D3DXLoadVolumeFromFileW +@ stub D3DXLoadVolumeFromMemory +@ stub D3DXLoadVolumeFromResourceA +@ stub D3DXLoadVolumeFromResourceW +@ stub D3DXLoadVolumeFromVolume @ stdcall D3DXMatrixAffineTransformation(ptr long ptr ptr ptr) @ stdcall D3DXMatrixAffineTransformation2D(ptr long ptr long ptr) @ stdcall D3DXMatrixDecompose(ptr ptr ptr ptr) @@ -228,8 +228,8 @@ @ stdcall D3DXMatrixTransformation2D(ptr ptr long ptr ptr long ptr) @ stdcall D3DXMatrixTranslation(ptr long long long) @ stdcall D3DXMatrixTranspose(ptr ptr) -@ stdcall -stub D3DXOptimizeFaces(ptr long long long ptr) -@ stdcall -stub D3DXOptimizeVertices(ptr long long long ptr) +@ stub D3DXOptimizeFaces +@ stub D3DXOptimizeVertices @ stdcall D3DXPlaneFromPointNormal(ptr ptr ptr) @ stdcall D3DXPlaneFromPoints(ptr ptr ptr ptr) @ stdcall D3DXPlaneIntersectLine(ptr ptr ptr ptr) @@ -252,56 +252,56 @@ @ stdcall D3DXQuaternionRotationYawPitchRoll(ptr long long long) @ stdcall D3DXQuaternionSlerp(ptr ptr ptr long) @ stdcall D3DXQuaternionSquad(ptr ptr ptr ptr ptr long) -@ stdcall -stub D3DXQuaternionSquadSetup(ptr ptr ptr ptr ptr ptr ptr) +@ stub D3DXQuaternionSquadSetup @ stdcall D3DXQuaternionToAxisAngle(ptr ptr ptr) -@ stdcall -stub D3DXRectPatchSize(ptr ptr ptr) -@ stdcall -stub D3DXSaveMeshHierarchyToFileA(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSaveMeshHierarchyToFileW(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSaveMeshToXA(ptr ptr ptr ptr ptr long long) -@ stdcall -stub D3DXSaveMeshToXW(ptr ptr ptr ptr ptr long long) -@ stdcall -stub D3DXSavePRTBufferToFileA(ptr ptr) -@ stdcall -stub D3DXSavePRTBufferToFileW(ptr ptr) -@ stdcall -stub D3DXSavePRTCompBufferToFileA(ptr ptr) -@ stdcall -stub D3DXSavePRTCompBufferToFileW(ptr ptr) -@ stdcall -stub D3DXSaveSurfaceToFileA(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSaveSurfaceToFileInMemory(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSaveSurfaceToFileW(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSaveTextureToFileA(ptr long ptr ptr) -@ stdcall -stub D3DXSaveTextureToFileInMemory(ptr long ptr ptr) -@ stdcall -stub D3DXSaveTextureToFileW(ptr long ptr ptr) -@ stdcall -stub D3DXSaveVolumeToFileA(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSaveVolumeToFileInMemory(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSaveVolumeToFileW(ptr long ptr ptr ptr) -@ stdcall -stub D3DXSHAdd(ptr long ptr ptr) -@ stdcall -stub D3DXSHDot(long ptr ptr) -@ stdcall -stub D3DXSHEvalConeLight(long ptr long long long long ptr ptr ptr) -@ stdcall -stub D3DXSHEvalDirection(ptr long ptr) -@ stdcall -stub D3DXSHEvalDirectionalLight(long ptr long long long long ptr ptr ptr) -@ stdcall -stub D3DXSHEvalHemisphereLight(long ptr long long ptr ptr ptr) -@ stdcall -stub D3DXSHEvalSphericalLight(long ptr long long long long ptr ptr ptr) +@ stub D3DXRectPatchSize +@ stub D3DXSaveMeshHierarchyToFileA +@ stub D3DXSaveMeshHierarchyToFileW +@ stub D3DXSaveMeshToXA +@ stub D3DXSaveMeshToXW +@ stub D3DXSavePRTBufferToFileA +@ stub D3DXSavePRTBufferToFileW +@ stub D3DXSavePRTCompBufferToFileA +@ stub D3DXSavePRTCompBufferToFileW +@ stub D3DXSaveSurfaceToFileA +@ stub D3DXSaveSurfaceToFileInMemory +@ stub D3DXSaveSurfaceToFileW +@ stub D3DXSaveTextureToFileA +@ stub D3DXSaveTextureToFileInMemory +@ stub D3DXSaveTextureToFileW +@ stub D3DXSaveVolumeToFileA +@ stub D3DXSaveVolumeToFileInMemory +@ stub D3DXSaveVolumeToFileW +@ stub D3DXSHAdd +@ stub D3DXSHDot +@ stub D3DXSHEvalConeLight +@ stub D3DXSHEvalDirection +@ stub D3DXSHEvalDirectionalLight +@ stub D3DXSHEvalHemisphereLight +@ stub D3DXSHEvalSphericalLight @ stub D3DXSHMultiply2 @ stub D3DXSHMultiply3 @ stub D3DXSHMultiply4 @ stub D3DXSHMultiply5 @ stub D3DXSHMultiply6 -@ stdcall -stub D3DXSHProjectCubeMap(long ptr ptr ptr ptr) -@ stdcall -stub D3DXSHPRTCompSplitMeshSC(ptr long long ptr long ptr long long ptr ptr long ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXSHPRTCompSuperCluster(ptr ptr long long ptr ptr) -@ stdcall -stub D3DXSHRotate(ptr long ptr ptr) -@ stdcall -stub D3DXSHRotateZ(ptr long long ptr) -@ stdcall -stub D3DXSHScale(ptr long ptr ptr) -@ stdcall -stub D3DXSimplifyMesh(ptr ptr ptr ptr long long ptr) +@ stub D3DXSHProjectCubeMap +@ stub D3DXSHPRTCompSplitMeshSC +@ stub D3DXSHPRTCompSuperCluster +@ stub D3DXSHRotate +@ stub D3DXSHRotateZ +@ stub D3DXSHScale +@ stub D3DXSimplifyMesh @ stdcall D3DXSphereBoundProbe(ptr long ptr ptr) -@ stdcall -stub D3DXSplitMesh(ptr ptr long long ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXTessellateNPatches(ptr ptr long long ptr ptr) -@ stdcall -stub D3DXTessellateRectPatch(ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXTessellateTriPatch(ptr ptr ptr ptr ptr) -@ stdcall -stub D3DXTriPatchSize(ptr ptr ptr) +@ stub D3DXSplitMesh +@ stub D3DXTessellateNPatches +@ stub D3DXTessellateRectPatch +@ stub D3DXTessellateTriPatch +@ stub D3DXTriPatchSize @ stub D3DXUVAtlasCreate @ stub D3DXUVAtlasPack @ stub D3DXUVAtlasPartition -@ stdcall -stub D3DXValidMesh(ptr ptr ptr) -@ stdcall -stub D3DXValidPatchMesh(ptr ptr ptr ptr) +@ stub D3DXValidMesh +@ stub D3DXValidPatchMesh @ stdcall D3DXVec2BaryCentric(ptr ptr ptr ptr long long) @ stdcall D3DXVec2CatmullRom(ptr ptr ptr ptr ptr long) @ stdcall D3DXVec2Hermite(ptr ptr ptr ptr ptr long) @@ -333,4 +333,4 @@ @ stdcall D3DXVec4Normalize(ptr ptr) @ stdcall D3DXVec4Transform(ptr ptr ptr) @ stdcall D3DXVec4TransformArray(ptr long ptr long ptr long) -@ stdcall -stub D3DXWeldVertices(ptr long ptr ptr ptr ptr ptr) +@ stub D3DXWeldVertices diff --git a/dll/directx/wine/d3dx9_36/d3dx9_36_main.c b/dll/directx/wine/d3dx9_36/d3dx9_36_main.c index ffd5361c457..e9c700444ef 100644 --- a/dll/directx/wine/d3dx9_36/d3dx9_36_main.c +++ b/dll/directx/wine/d3dx9_36/d3dx9_36_main.c @@ -33,10 +33,6 @@ #include "d3dx9.h" -#ifdef _MSC_VER -DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); -#endif - /*********************************************************************** * DllMain. */ diff --git a/dll/directx/wine/wined3d/state.c b/dll/directx/wine/wined3d/state.c index 378e0f96827..a43cc383ca1 100644 --- a/dll/directx/wine/wined3d/state.c +++ b/dll/directx/wine/wined3d/state.c @@ -1,4 +1,4 @@ -/* +/* * Direct3D state management * * Copyright 2002 Lionel Ulmer diff --git a/dll/ntdll/ldr/ldrinit.c b/dll/ntdll/ldr/ldrinit.c index 8bb2e40d219..da065c4b973 100644 --- a/dll/ntdll/ldr/ldrinit.c +++ b/dll/ntdll/ldr/ldrinit.c @@ -1996,9 +1996,11 @@ NTAPI LdrpInitFailure(NTSTATUS Status) { ULONG Response; + PPEB Peb = NtCurrentPeb(); /* Print a debug message */ - DPRINT1("LDR: Process initialization failure; NTSTATUS = %08lx\n", Status); + DPRINT1("LDR: Process initialization failure for %wZ; NTSTATUS = %08lx\n", + &Peb->ProcessParameters->ImagePathName, Status); /* Raise a hard error */ if (!LdrpFatalHardErrorCount) diff --git a/dll/win32/kernel32/client/dllmain.c b/dll/win32/kernel32/client/dllmain.c index 61677f0e4ca..cc4c07360cb 100644 --- a/dll/win32/kernel32/client/dllmain.c +++ b/dll/win32/kernel32/client/dllmain.c @@ -29,7 +29,6 @@ BOOLEAN BaseRunningInServerProcess; WCHAR BaseDefaultPathBuffer[6140]; HANDLE BaseNamedObjectDirectory; -HANDLE hProcessHeap = NULL; HMODULE hCurrentModule = NULL; HMODULE kernel32_handle = NULL; HANDLE hBaseDir = NULL; @@ -58,13 +57,6 @@ extern BOOL FASTCALL NlsInit(VOID); extern VOID FASTCALL NlsUninit(VOID); BOOLEAN InWindows = FALSE; -HANDLE -WINAPI -DuplicateConsoleHandle(HANDLE hConsole, - DWORD dwDesiredAccess, - BOOL bInheritHandle, - DWORD dwOptions); - #define WIN_OBJ_DIR L"\\Windows" #define SESSION_DIR L"\\Sessions" @@ -323,11 +315,7 @@ DllMain(HANDLE hDll, } /* Initialize heap handle table */ - hProcessHeap = RtlGetProcessHeap(); - RtlInitializeHandleTable(0xFFFF, - sizeof(BASE_HEAP_HANDLE_ENTRY), - &BaseHeapHandleTable); - DPRINT("Heap: %p\n", hProcessHeap); + BaseDllInitializeMemoryManager(); /* Set HMODULE for our DLL */ kernel32_handle = hCurrentModule = hDll; diff --git a/dll/win32/kernel32/client/file/find.c b/dll/win32/kernel32/client/file/find.c index 91fc17a422d..e726ecaa30f 100644 --- a/dll/win32/kernel32/client/file/find.c +++ b/dll/win32/kernel32/client/file/find.c @@ -364,7 +364,7 @@ InternalFindFirstFile ( if (!NT_SUCCESS(Status)) { - RtlFreeHeap (hProcessHeap, + RtlFreeHeap (RtlGetProcessHeap(), 0, NtPathBuffer); @@ -387,20 +387,20 @@ InternalFindFirstFile ( { /* No file part?! */ NtClose(hDirectory); - RtlFreeHeap (hProcessHeap, + RtlFreeHeap (RtlGetProcessHeap(), 0, NtPathBuffer); SetLastError(ERROR_FILE_NOT_FOUND); return INVALID_HANDLE_VALUE; } - IHeader = RtlAllocateHeap (hProcessHeap, + IHeader = RtlAllocateHeap (RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(KERNEL32_FIND_DATA_HEADER) + sizeof(KERNEL32_FIND_FILE_DATA) + FIND_DATA_SIZE); if (NULL == IHeader) { - RtlFreeHeap (hProcessHeap, + RtlFreeHeap (RtlGetProcessHeap(), 0, NtPathBuffer); NtClose(hDirectory); @@ -431,7 +431,7 @@ InternalFindFirstFile ( &PathFileName, lpFindFileData); - RtlFreeHeap (hProcessHeap, + RtlFreeHeap (RtlGetProcessHeap(), 0, NtPathBuffer); @@ -596,7 +596,7 @@ FindClose ( PKERNEL32_FIND_STREAM_DATA IData = (PKERNEL32_FIND_STREAM_DATA)(IHeader + 1); if (IData->pFileStreamInfo != NULL) { - RtlFreeHeap (hProcessHeap, 0, IData->pFileStreamInfo); + RtlFreeHeap (RtlGetProcessHeap(), 0, IData->pFileStreamInfo); } break; } @@ -606,7 +606,7 @@ FindClose ( return FALSE; } - RtlFreeHeap (hProcessHeap, 0, IHeader); + RtlFreeHeap (RtlGetProcessHeap(), 0, IHeader); return TRUE; } @@ -835,7 +835,7 @@ FindFirstStreamW(IN LPCWSTR lpFileName, } /* create the search context */ - IHeader = RtlAllocateHeap(hProcessHeap, + IHeader = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(KERNEL32_FIND_DATA_HEADER) + sizeof(KERNEL32_FIND_STREAM_DATA)); @@ -859,7 +859,7 @@ FindFirstStreamW(IN LPCWSTR lpFileName, if (IData->pFileStreamInfo == NULL) { - IData->pFileStreamInfo = RtlAllocateHeap(hProcessHeap, + IData->pFileStreamInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize); if (IData->pFileStreamInfo == NULL) @@ -872,7 +872,7 @@ FindFirstStreamW(IN LPCWSTR lpFileName, { PFILE_STREAM_INFORMATION pfsi; - pfsi = RtlReAllocateHeap(hProcessHeap, + pfsi = RtlReAllocateHeap(RtlGetProcessHeap(), 0, IData->pFileStreamInfo, BufferSize); @@ -923,12 +923,12 @@ Cleanup: { if (IData->pFileStreamInfo != NULL) { - RtlFreeHeap(hProcessHeap, + RtlFreeHeap(RtlGetProcessHeap(), 0, IData->pFileStreamInfo); } - RtlFreeHeap(hProcessHeap, + RtlFreeHeap(RtlGetProcessHeap(), 0, IHeader); } diff --git a/dll/win32/kernel32/client/handle.c b/dll/win32/kernel32/client/handle.c index 3f5eef262f7..8c18a87be31 100644 --- a/dll/win32/kernel32/client/handle.c +++ b/dll/win32/kernel32/client/handle.c @@ -1,209 +1,206 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/kernel32/misc/handle.c - * PURPOSE: Object functions - * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) - * UPDATE HISTORY: - * Created 01/11/98 +/* + * PROJECT: ReactOS Win32 Base API + * LICENSE: See COPYING in the top level directory + * FILE: dll/win32/kernel32/client/handle.c + * PURPOSE: Object Handle Functions + * PROGRAMMERS: Ariadne ( ariadne@xs4all.nl) */ -/* INCLUDES ******************************************************************/ +/* INCLUDES *******************************************************************/ #include #define NDEBUG #include -/* GLOBALS *******************************************************************/ +/* PRIVATE FUNCTIONS **********************************************************/ -HANDLE WINAPI -DuplicateConsoleHandle (HANDLE hConsole, - DWORD dwDesiredAccess, - BOOL bInheritHandle, - DWORD dwOptions); - -/* FUNCTIONS *****************************************************************/ - -HANDLE FASTCALL -TranslateStdHandle(HANDLE hHandle) +HANDLE +FASTCALL +TranslateStdHandle(IN HANDLE hHandle) { - PRTL_USER_PROCESS_PARAMETERS Ppb = NtCurrentPeb()->ProcessParameters; + PRTL_USER_PROCESS_PARAMETERS Ppb = NtCurrentPeb()->ProcessParameters; - switch ((ULONG)hHandle) + switch ((ULONG)hHandle) { - case STD_INPUT_HANDLE: return Ppb->StandardInput; - case STD_OUTPUT_HANDLE: return Ppb->StandardOutput; - case STD_ERROR_HANDLE: return Ppb->StandardError; + case STD_INPUT_HANDLE: return Ppb->StandardInput; + case STD_OUTPUT_HANDLE: return Ppb->StandardOutput; + case STD_ERROR_HANDLE: return Ppb->StandardError; } - return hHandle; + return hHandle; } +/* PUBLIC FUNCTIONS ***********************************************************/ + /* * @implemented */ -BOOL WINAPI -GetHandleInformation (HANDLE hObject, - LPDWORD lpdwFlags) +BOOL +WINAPI +GetHandleInformation(IN HANDLE hObject, + OUT LPDWORD lpdwFlags) { - OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo; - ULONG BytesWritten; - NTSTATUS Status; - DWORD Flags; + OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo; + ULONG BytesWritten; + NTSTATUS Status; + DWORD Flags; - hObject = TranslateStdHandle(hObject); + hObject = TranslateStdHandle(hObject); - Status = NtQueryObject (hObject, - ObjectHandleFlagInformation, - &HandleInfo, - sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION), - &BytesWritten); - if (NT_SUCCESS(Status)) - { - Flags = 0; - if (HandleInfo.Inherit) - Flags |= HANDLE_FLAG_INHERIT; - if (HandleInfo.ProtectFromClose) - Flags |= HANDLE_FLAG_PROTECT_FROM_CLOSE; - - *lpdwFlags = Flags; - - return TRUE; - } - else - { - BaseSetLastNTError (Status); - return FALSE; - } -} - - -/* - * @implemented - */ -BOOL WINAPI -SetHandleInformation (HANDLE hObject, - DWORD dwMask, - DWORD dwFlags) -{ - OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo; - ULONG BytesWritten; - NTSTATUS Status; - - hObject = TranslateStdHandle(hObject); - - Status = NtQueryObject (hObject, - ObjectHandleFlagInformation, - &HandleInfo, - sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION), - &BytesWritten); - if (NT_SUCCESS(Status)) - { - if (dwMask & HANDLE_FLAG_INHERIT) - HandleInfo.Inherit = (dwFlags & HANDLE_FLAG_INHERIT) != 0; - if (dwMask & HANDLE_FLAG_PROTECT_FROM_CLOSE) - HandleInfo.ProtectFromClose = (dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE) != 0; - - Status = NtSetInformationObject (hObject, - ObjectHandleFlagInformation, - &HandleInfo, - sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION)); - if(!NT_SUCCESS(Status)) + if (IsConsoleHandle(hObject)) { - BaseSetLastNTError (Status); - return FALSE; - } - - return TRUE; - } - else - { - BaseSetLastNTError (Status); - return FALSE; - } -} - - -/* - * @implemented - */ -BOOL WINAPI CloseHandle(HANDLE hObject) -/* - * FUNCTION: Closes an open object handle - * PARAMETERS: - * hObject = Identifies an open object handle - * RETURNS: If the function succeeds, the return value is nonzero - * If the function fails, the return value is zero - */ -{ - NTSTATUS Status; - - hObject = TranslateStdHandle(hObject); - - if (IsConsoleHandle(hObject)) - { - return(CloseConsoleHandle(hObject)); - } - - Status = NtClose(hObject); - if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError (Status); - return FALSE; - } - - return TRUE; -} - - -/* - * @implemented - */ -BOOL WINAPI DuplicateHandle(HANDLE hSourceProcessHandle, - HANDLE hSourceHandle, - HANDLE hTargetProcessHandle, - LPHANDLE lpTargetHandle, - DWORD dwDesiredAccess, - BOOL bInheritHandle, - DWORD dwOptions) -{ - DWORD SourceProcessId, TargetProcessId; - NTSTATUS Status; - - hSourceHandle = TranslateStdHandle(hSourceHandle); - - if (IsConsoleHandle(hSourceHandle)) - { - SourceProcessId = GetProcessId(hSourceProcessHandle); - TargetProcessId = GetProcessId(hTargetProcessHandle); - if (!SourceProcessId || !TargetProcessId || - SourceProcessId != TargetProcessId || - SourceProcessId != GetCurrentProcessId()) - { - SetLastError(ERROR_INVALID_PARAMETER); + /* FIXME: GetConsoleHandleInformation required */ + UNIMPLEMENTED; + BaseSetLastNTError(STATUS_NOT_IMPLEMENTED); return FALSE; - } + } - *lpTargetHandle = DuplicateConsoleHandle(hSourceHandle, dwDesiredAccess, bInheritHandle, dwOptions); - return *lpTargetHandle != INVALID_HANDLE_VALUE; - } + Status = NtQueryObject(hObject, + ObjectHandleFlagInformation, + &HandleInfo, + sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION), + &BytesWritten); + if (!NT_SUCCESS(Status)) + { + BaseSetLastNTError(Status); + return FALSE; + } - Status = NtDuplicateObject(hSourceProcessHandle, - hSourceHandle, - hTargetProcessHandle, - lpTargetHandle, - dwDesiredAccess, - bInheritHandle ? OBJ_INHERIT : 0, - dwOptions); - if (!NT_SUCCESS(Status)) - { - BaseSetLastNTError (Status); - return FALSE; - } + Flags = 0; + if (HandleInfo.Inherit) Flags |= HANDLE_FLAG_INHERIT; + if (HandleInfo.ProtectFromClose) Flags |= HANDLE_FLAG_PROTECT_FROM_CLOSE; + *lpdwFlags = Flags; + return TRUE; +} - return TRUE; +/* + * @implemented + */ +BOOL +WINAPI +SetHandleInformation(IN HANDLE hObject, + IN DWORD dwMask, + IN DWORD dwFlags) +{ + OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo; + ULONG BytesWritten; + NTSTATUS Status; + + hObject = TranslateStdHandle(hObject); + + if (IsConsoleHandle(hObject)) + { + /* FIXME: SetConsoleHandleInformation required */ + UNIMPLEMENTED; + BaseSetLastNTError(STATUS_NOT_IMPLEMENTED); + return FALSE; + } + + Status = NtQueryObject(hObject, + ObjectHandleFlagInformation, + &HandleInfo, + sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION), + &BytesWritten); + if (!NT_SUCCESS(Status)) + { + BaseSetLastNTError(Status); + return FALSE; + } + + if (dwMask & HANDLE_FLAG_INHERIT) + { + HandleInfo.Inherit = (dwFlags & HANDLE_FLAG_INHERIT) != 0; + } + + if (dwMask & HANDLE_FLAG_PROTECT_FROM_CLOSE) + { + HandleInfo.ProtectFromClose = (dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE) != 0; + } + + Status = NtSetInformationObject(hObject, + ObjectHandleFlagInformation, + &HandleInfo, + sizeof(HandleInfo)); + if (NT_SUCCESS(Status)) return TRUE; + + BaseSetLastNTError(Status); + return FALSE; +} + +/* + * @implemented + */ +BOOL +WINAPI +CloseHandle(IN HANDLE hObject) +{ + NTSTATUS Status; + + hObject = TranslateStdHandle(hObject); + + if (IsConsoleHandle(hObject)) return CloseConsoleHandle(hObject); + + Status = NtClose(hObject); + if (NT_SUCCESS(Status)) return TRUE; + + BaseSetLastNTError(Status); + return FALSE; +} + +/* + * @implemented + */ +BOOL +WINAPI +DuplicateHandle(IN HANDLE hSourceProcessHandle, + IN HANDLE hSourceHandle, + IN HANDLE hTargetProcessHandle, + OUT LPHANDLE lpTargetHandle, + IN DWORD dwDesiredAccess, + IN BOOL bInheritHandle, + IN DWORD dwOptions) +{ + NTSTATUS Status; + HANDLE hTargetHandle; + + hSourceHandle = TranslateStdHandle(hSourceHandle); + + if ((IsConsoleHandle(hSourceHandle)) && + ((hSourceHandle != NtCurrentProcess()) && + (hSourceHandle != NtCurrentThread()))) + { + if ((hSourceProcessHandle != NtCurrentProcess()) && + (hTargetProcessHandle != NtCurrentProcess())) + { + BaseSetLastNTError(STATUS_INVALID_PARAMETER); + return FALSE; + } + + hTargetHandle = DuplicateConsoleHandle(hSourceHandle, + dwDesiredAccess, + bInheritHandle, + dwOptions); + if (hTargetHandle != INVALID_HANDLE_VALUE) + { + if (lpTargetHandle) *lpTargetHandle = hTargetHandle; + return TRUE; + } + + return FALSE; + } + + Status = NtDuplicateObject(hSourceProcessHandle, + hSourceHandle, + hTargetProcessHandle, + lpTargetHandle, + dwDesiredAccess, + bInheritHandle ? OBJ_INHERIT : 0, + dwOptions); + if (NT_SUCCESS(Status)) return TRUE; + + BaseSetLastNTError(Status); + return FALSE; } /* @@ -211,9 +208,9 @@ BOOL WINAPI DuplicateHandle(HANDLE hSourceProcessHandle, */ UINT WINAPI -SetHandleCount(UINT nCount) +SetHandleCount(IN UINT nCount) { - return nCount; + return nCount; } /* @@ -240,7 +237,6 @@ CreateSocketHandle(VOID) DbgPrintEx(0, 0, "Unsupported API - kernel32!CreateSocketHandle() called\n"); SetLastError(ERROR_CALL_NOT_IMPLEMENTED); return FALSE; - } /* diff --git a/dll/win32/kernel32/client/heapmem.c b/dll/win32/kernel32/client/heapmem.c index 808e31b7fbf..58aa0599d1a 100644 --- a/dll/win32/kernel32/client/heapmem.c +++ b/dll/win32/kernel32/client/heapmem.c @@ -6,18 +6,36 @@ * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) */ -/* INCLUDES ******************************************************************/ +/* INCLUDES *******************************************************************/ #include #define NDEBUG #include -/* TYPES *********************************************************************/ +/* GLOBALS ********************************************************************/ RTL_HANDLE_TABLE BaseHeapHandleTable; +HANDLE BaseHeap; +ULONG_PTR SystemRangeStart; -/* FUNCTIONS ***************************************************************/ +/* PRIVATE FUNCTIONS **********************************************************/ + +VOID +NTAPI +BaseDllInitializeMemoryManager(VOID) +{ + BaseHeap = RtlGetProcessHeap(); + RtlInitializeHandleTable(0xFFFF, + sizeof(BASE_HEAP_HANDLE_ENTRY), + &BaseHeapHandleTable); + NtQuerySystemInformation(SystemRangeStartInformation, + &SystemRangeStart, + sizeof(SystemRangeStart), + NULL); +} + +/* PUBLIC FUNCTIONS ***********************************************************/ /* * @implemented @@ -275,6 +293,8 @@ HeapWalk(HANDLE hHeap, { NTSTATUS Status; + DPRINT1("Warning, HeapWalk is calling RtlWalkHeap with Win32 parameters\n"); + Status = RtlWalkHeap(hHeap, lpEntry); if (!NT_SUCCESS(Status)) @@ -353,7 +373,7 @@ GlobalAlloc(UINT uFlags, HANDLE hMemory; PBASE_HEAP_HANDLE_ENTRY HandleEntry; BASE_TRACE_ALLOC(dwBytes, uFlags); - ASSERT(hProcessHeap); + ASSERT(BaseHeap); /* Make sure the flags are valid */ if (uFlags & ~GMEM_VALID_FLAGS) @@ -374,13 +394,14 @@ GlobalAlloc(UINT uFlags, if (uFlags & GMEM_DDESHARE) Flags |= BASE_HEAP_ENTRY_FLAG_DDESHARE; /* Allocate heap for it */ - Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes); + Ptr = RtlAllocateHeap(BaseHeap, Flags, dwBytes ? dwBytes : 1); + if (!Ptr) SetLastError(ERROR_NOT_ENOUGH_MEMORY); BASE_TRACE_ALLOC2(Ptr); return Ptr; } /* This is heap based, so lock it in first */ - RtlLockHeap(hProcessHeap); + RtlLockHeap(BaseHeap); /* * Disable locking, enable custom flags, and write the @@ -398,35 +419,35 @@ GlobalAlloc(UINT uFlags, hMemory = NULL; SetLastError(ERROR_NOT_ENOUGH_MEMORY); BASE_TRACE_FAILURE(); - goto Quickie; } - - /* Get the object and make sure we have size */ - hMemory = &HandleEntry->Object; - if (dwBytes) + else { - /* Allocate the actual memory for it */ - Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes); - BASE_TRACE_PTR(HandleEntry, Ptr); - if (!Ptr) + /* Get the object and make sure we have size */ + hMemory = &HandleEntry->Object; + if (dwBytes) { - /* We failed, manually set the allocate flag and free the handle */ - HandleEntry->Flags = RTL_HANDLE_VALID; - BaseHeapFreeEntry(HandleEntry); + /* Allocate the actual memory for it */ + Ptr = RtlAllocateHeap(BaseHeap, Flags, dwBytes); + BASE_TRACE_PTR(HandleEntry, Ptr); + if (!Ptr) + { + /* We failed, manually set the allocate flag and free the handle */ + HandleEntry->Flags = RTL_HANDLE_VALID; + BaseHeapFreeEntry(HandleEntry); - /* For the cleanup case */ - HandleEntry = NULL; - } - else - { - /* All worked well, save our heap entry */ - RtlSetUserValueHeap(hProcessHeap, HEAP_NO_SERIALIZE, Ptr, hMemory); + /* For the cleanup case */ + HandleEntry = NULL; + } + else + { + /* All worked well, save our heap entry */ + RtlSetUserValueHeap(BaseHeap, HEAP_NO_SERIALIZE, Ptr, hMemory); + } } } -Quickie: /* Cleanup! First unlock the heap */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); /* Check if a handle was allocated */ if (HandleEntry) @@ -477,7 +498,7 @@ NTAPI GlobalCompact(DWORD dwMinFree) { /* Call the RTL Heap Manager */ - return RtlCompactHeap(hProcessHeap, 0); + return RtlCompactHeap(BaseHeap, 0); } /* @@ -504,71 +525,81 @@ GlobalFlags(HGLOBAL hMem) UINT uFlags = GMEM_INVALID_HANDLE; /* Start by locking the heap */ - RtlLockHeap(hProcessHeap); - - /* Check if this is a simple RTL Heap Managed block */ - if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)) + RtlLockHeap(BaseHeap); + _SEH2_TRY { - /* Then we'll query RTL Heap */ - RtlGetUserInfoHeap(hProcessHeap, Flags, hMem, &Handle, &Flags); - BASE_TRACE_PTR(Handle, hMem); + /* Check if this is a simple RTL Heap Managed block */ + if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)) + { + /* Then we'll query RTL Heap */ + RtlGetUserInfoHeap(BaseHeap, Flags, hMem, &Handle, &Flags); + BASE_TRACE_PTR(Handle, hMem); - /* - * Check if RTL Heap didn't find a handle associated with us or - * said that this heap isn't movable, which means something we're - * really not a handle-based heap. - */ - if (!(Handle) || !(Flags & BASE_HEAP_FLAG_MOVABLE)) - { - /* Then set the flags to 0 */ - uFlags = 0; + /* + * Check if RTL Heap didn't find a handle associated with us or + * said that this heap isn't movable, which means something we're + * really not a handle-based heap. + */ + if (!(Handle) || !(Flags & BASE_HEAP_FLAG_MOVABLE)) + { + /* Then set the flags to 0 */ + uFlags = 0; + } + else + { + /* Otherwise we're handle-based, so get the internal handle */ + hMem = Handle; + } } - else + + /* Check if the handle is actually an entry in our table */ + if ((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY) { - /* Otherwise we're handle-based, so get the internal handle */ - hMem = Handle; + /* Then get the entry */ + HandleEntry = BaseHeapGetEntry(hMem); + BASE_TRACE_HANDLE(HandleEntry, hMem); + + /* Make sure it's a valid handle */ + if (BaseHeapValidateEntry(HandleEntry)) + { + /* Get the lock count first */ + uFlags = HandleEntry->LockCount & GMEM_LOCKCOUNT; + + /* Now check if it's discardable */ + if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_REUSABLE) + { + /* Set the Win32 Flag */ + uFlags |= GMEM_DISCARDABLE; + } + + /* Check if it's DDE Shared */ + if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_DDESHARE) + { + /* Set the Win32 Flag */ + uFlags |= GMEM_DDESHARE; + } + + /* Now check if it's discarded */ + if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_REUSE) + { + /* Set the Win32 Flag */ + uFlags |= GMEM_DISCARDED; + } + } } + + /* Check if by now, we still haven't gotten any useful flags */ + if (uFlags == GMEM_INVALID_HANDLE) SetLastError(ERROR_INVALID_HANDLE); } - - /* Check if the handle is actually an entry in our table */ - if ((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY) + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - /* Then get the entry */ - HandleEntry = BaseHeapGetEntry(hMem); - BASE_TRACE_HANDLE(HandleEntry, hMem); - - /* Make sure it's a valid handle */ - if (BaseHeapValidateEntry(HandleEntry)) - { - /* Get the lock count first */ - uFlags = HandleEntry->LockCount & GMEM_LOCKCOUNT; - - /* Now check if it's discardable */ - if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_REUSABLE) - { - /* Set the Win32 Flag */ - uFlags |= GMEM_DISCARDABLE; - } - - /* Check if it's DDE Shared */ - if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_DDESHARE) - { - /* Set the Win32 Flag */ - uFlags |= GMEM_DDESHARE; - } - - /* Now check if it's discarded */ - if (HandleEntry->Flags & BASE_HEAP_ENTRY_FLAG_REUSE) - /* Set the Win32 Flag */ - uFlags |= GMEM_DISCARDED; - } + /* Set the exception code */ + BaseSetLastNTError(_SEH2_GetExceptionCode()); } - - /* Check if by now, we still haven't gotten any useful flags */ - if (uFlags == GMEM_INVALID_HANDLE) SetLastError(ERROR_INVALID_HANDLE); + _SEH2_END; /* All done! Unlock heap and return Win32 Flags */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return uFlags; } @@ -587,7 +618,7 @@ GlobalFree(HGLOBAL hMem) if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)) { /* Free it with the RTL Heap Manager */ - if (RtlFreeHeap(hProcessHeap, 0, hMem)) + if (RtlFreeHeap(BaseHeap, 0, hMem)) { /* Return NULL since there's no handle */ return NULL; @@ -602,51 +633,67 @@ GlobalFree(HGLOBAL hMem) } /* It's a handle probably, so lock the heap */ - RtlLockHeap(hProcessHeap); - - /* Make sure that this is an entry in our handle database */ - if ((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY) + RtlLockHeap(BaseHeap); + _SEH2_TRY { - /* Get the entry */ - HandleEntry = BaseHeapGetEntry(hMem); - BASE_TRACE_HANDLE(HandleEntry, hMem); - - /* Make sure the handle is valid */ - if (!BaseHeapValidateEntry(HandleEntry)) + /* Make sure that this is an entry in our handle database */ + if ((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY) { - /* It's not, fail */ - SetLastError(ERROR_INVALID_HANDLE); - Ptr = NULL; + /* Get the entry */ + HandleEntry = BaseHeapGetEntry(hMem); + BASE_TRACE_HANDLE(HandleEntry, hMem); + + /* Make sure the handle is valid */ + if (!BaseHeapValidateEntry(HandleEntry)) + { + /* It's not, fail */ + SetLastError(ERROR_INVALID_HANDLE); + Ptr = NULL; + } + else + { + /* It's valid, so get the pointer */ + Ptr = HandleEntry->Object; + + /* Free this handle */ + BaseHeapFreeEntry(HandleEntry); + + /* If the pointer is 0, then we don't have a handle either */ + if (!Ptr) hMem = NULL; + } } else { - /* It's valid, so get the pointer */ - Ptr = HandleEntry->Object; + /* Otherwise, reuse the handle as a pointer */ + BASE_TRACE_FAILURE(); + Ptr = hMem; + } - /* Free this handle */ - BaseHeapFreeEntry(HandleEntry); - - /* If the pointer is 0, then we don't have a handle either */ - if (!Ptr) hMem = NULL; + /* Check if we got here with a valid heap pointer */ + if (Ptr) + { + /* Free it with the RTL Heap Manager */ + if (RtlFreeHeap(BaseHeap, HEAP_NO_SERIALIZE, Ptr)) + { + /* Everything worked */ + hMem = NULL; + } + else + { + /* This wasn't a real heap handle */ + SetLastError(ERROR_INVALID_HANDLE); + } } } - else + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - /* Otherwise, reuse the handle as a pointer */ - BASE_TRACE_FAILURE(); - Ptr = hMem; - } - - /* Check if we got here with a valid heap pointer */ - if (Ptr) - { - /* Free it */ - RtlFreeHeap(hProcessHeap, HEAP_NO_SERIALIZE, Ptr); - hMem = NULL; + /* Set the exception code */ + BaseSetLastNTError(_SEH2_GetExceptionCode()); } + _SEH2_END; /* We're done, so unlock the heap and return the handle */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return hMem; } @@ -661,28 +708,42 @@ GlobalHandle(LPCVOID pMem) ULONG Flags; /* Lock the heap */ - RtlLockHeap(hProcessHeap); - - /* Query RTL Heap */ - RtlGetUserInfoHeap(hProcessHeap, - HEAP_NO_SERIALIZE, - (PVOID)pMem, - &Handle, - &Flags); - BASE_TRACE_PTR(Handle, pMem); - - /* - * Check if RTL Heap didn't find a handle for us or said that - * this heap isn't movable. - */ - if (!(Handle) || !(Flags & BASE_HEAP_FLAG_MOVABLE)) + RtlLockHeap(BaseHeap); + _SEH2_TRY { - /* We're actually handle-based, so the pointer is a handle */ - Handle = (HANDLE)pMem; + /* Query RTL Heap */ + if (!RtlGetUserInfoHeap(BaseHeap, + HEAP_NO_SERIALIZE, + (PVOID)pMem, + &Handle, + &Flags)) + { + /* RTL Heap Manager does not know about this heap */ + SetLastError(ERROR_INVALID_HANDLE); + } + else + { + /* + * Check if RTL Heap didn't find a handle for us or said that + * this heap isn't movable. + */ + BASE_TRACE_PTR(Handle, pMem); + if (!(Handle) || !(Flags & BASE_HEAP_FLAG_MOVABLE)) + { + /* We're actually handle-based, so the pointer is a handle */ + Handle = (HANDLE)pMem; + } + } } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + /* Set the exception code */ + BaseSetLastNTError(_SEH2_GetExceptionCode()); + } + _SEH2_END; /* All done, unlock the heap and return the handle */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return Handle; } @@ -699,13 +760,20 @@ GlobalLock(HGLOBAL hMem) /* Check if this was a simple allocated heap entry */ if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)) { - /* Verify and return the pointer */ - return IsBadReadPtr(hMem, 1) ? NULL : hMem; + /* Make sure it's not a kernel or invalid address */ + if ((hMem >= (HGLOBAL)SystemRangeStart) || (IsBadReadPtr(hMem, 1))) + { + /* Signal an error */ + SetLastError(ERROR_INVALID_HANDLE); + return NULL; + } + + /* It's all good */ + return hMem; } /* Otherwise, lock the heap */ - RtlLockHeap(hProcessHeap); - + RtlLockHeap(BaseHeap); _SEH2_TRY { /* Get the handle entry */ @@ -745,10 +813,10 @@ GlobalLock(HGLOBAL hMem) SetLastError(ERROR_INVALID_HANDLE); Ptr = NULL; } - _SEH2_END + _SEH2_END; /* All done. Unlock the heap and return the pointer */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return Ptr; } @@ -763,6 +831,20 @@ GlobalReAlloc(HGLOBAL hMem, LPVOID Ptr; ULONG Flags = 0; + /* Throw out invalid flags */ + if (uFlags & ~(GMEM_VALID_FLAGS | GMEM_MODIFY)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + + /* Throw out invalid combo */ + if ((uFlags & GMEM_DISCARDABLE) && !(uFlags & GMEM_MODIFY)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + /* Convert ZEROINIT */ if (uFlags & GMEM_ZEROINIT) Flags |= HEAP_ZERO_MEMORY; @@ -770,7 +852,7 @@ GlobalReAlloc(HGLOBAL hMem, if (!(uFlags & GMEM_MOVEABLE)) Flags |= HEAP_REALLOC_IN_PLACE_ONLY; /* Lock the heap and disable built-in locking in the RTL Heap funcitons */ - RtlLockHeap(hProcessHeap); + RtlLockHeap(BaseHeap); Flags |= HEAP_NO_SERIALIZE; /* Check if this is a simple handle-based block */ @@ -816,14 +898,15 @@ GlobalReAlloc(HGLOBAL hMem, if ((uFlags & GMEM_MOVEABLE) && !(HandleEntry->LockCount)) { /* Free the current heap */ - RtlFreeHeap(hProcessHeap, Flags, Ptr); + if (RtlFreeHeap(BaseHeap, Flags, Ptr)) + { + /* Free the handle */ + HandleEntry->Object = NULL; + HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSE; - /* Free the handle */ - HandleEntry->Object = NULL; - HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSE; - - /* Get the object pointer */ - hMem = &HandleEntry->Object; + /* Get the object pointer */ + hMem = &HandleEntry->Object; + } } } else @@ -839,12 +922,12 @@ GlobalReAlloc(HGLOBAL hMem, if (!Ptr) { /* We don't have a base, so allocate one */ - Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes); + Ptr = RtlAllocateHeap(BaseHeap, Flags, dwBytes); BASE_TRACE_ALLOC2(Ptr); if (Ptr) { /* Allocation succeeded, so save our entry */ - RtlSetUserValueHeap(hProcessHeap, + RtlSetUserValueHeap(BaseHeap, HEAP_NO_SERIALIZE, Ptr, hMem); @@ -867,18 +950,8 @@ GlobalReAlloc(HGLOBAL hMem, Flags &= ~HEAP_REALLOC_IN_PLACE_ONLY; } - /* And do the re-allocation */ - Ptr = RtlReAllocateHeap(hProcessHeap, Flags, Ptr, dwBytes); - - if (Ptr) - { - /* Allocation succeeded, so save our entry */ - RtlSetUserValueHeap(hProcessHeap, - HEAP_NO_SERIALIZE, - Ptr, - hMem); - } - + /* Do the re-allocation. No need to save the entry again */ + Ptr = RtlReAllocateHeap(BaseHeap, Flags, Ptr, dwBytes); } /* Make sure we have a pointer by now */ @@ -904,81 +977,87 @@ GlobalReAlloc(HGLOBAL hMem, { /* Get information on its current state */ Handle = hMem; - DPRINT1("h h %lx %lx\n", Handle, hMem); - RtlGetUserInfoHeap(hProcessHeap, - HEAP_NO_SERIALIZE, - hMem, - &Handle, - &Flags); - DPRINT1("h h %lx %lx\n", Handle, hMem); - - /* - * Check if the handle matches the pointer or if the moveable flag - * isn't there, which is what we expect since it currenly isn't. - */ - if (Handle == hMem || !(Flags & BASE_HEAP_FLAG_MOVABLE)) + if (RtlGetUserInfoHeap(BaseHeap, + HEAP_NO_SERIALIZE, + hMem, + &Handle, + NULL)) { - /* Allocate a handle for it */ - HandleEntry = BaseHeapAllocEntry(); - - /* Calculate the size of the current heap */ - dwBytes = RtlSizeHeap(hProcessHeap, HEAP_NO_SERIALIZE, hMem); - - /* Set the movable flag */ - Flags |= HEAP_SETTABLE_USER_VALUE | BASE_HEAP_FLAG_MOVABLE; - - /* Now allocate the actual heap for it */ - HandleEntry->Object = RtlAllocateHeap(hProcessHeap, - Flags, - dwBytes); - BASE_TRACE_PTR(HandleEntry->Object, HandleEntry); - if (!HandleEntry->Object) + /* + * Check if the handle matches the pointer or the moveable flag + * isn't there, which is what we expect since it currenly isn't. + */ + if ((Handle == hMem) || !(Flags & BASE_HEAP_FLAG_MOVABLE)) { - /* - * We failed, manually set the allocate flag and - * free the handle - */ - HandleEntry->Flags = RTL_HANDLE_VALID; - BaseHeapFreeEntry(HandleEntry); - - /* For the cleanup case */ - BASE_TRACE_FAILURE(); - HandleEntry = NULL; - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - } - else - { - /* Otherwise, copy the current heap and free the old one */ - RtlMoveMemory(HandleEntry->Object, hMem, dwBytes); - RtlFreeHeap(hProcessHeap, HEAP_NO_SERIALIZE, hMem); - - /* Select the heap pointer */ - hMem = (HANDLE)&HandleEntry->Object; - - /* Initialize the count and default flags */ - HandleEntry->LockCount = 0; - HandleEntry->Flags = RTL_HANDLE_VALID | - BASE_HEAP_ENTRY_FLAG_MOVABLE; - - /* Check if it's also discardable */ - if (uFlags & GMEM_DISCARDABLE) + /* Allocate a handle for it */ + HandleEntry = BaseHeapAllocEntry(); + if (!HandleEntry) { - /* Set the internal flag */ - HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSABLE; + /* No entry could be allocated */ + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + RtlUnlockHeap(BaseHeap); + return NULL; } - /* Check if it's also DDE Shared */ - if (uFlags & GMEM_DDESHARE) - { - /* Set the internal flag */ - HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_DDESHARE; - } + /* Calculate the size of the current heap */ + dwBytes = RtlSizeHeap(BaseHeap, HEAP_NO_SERIALIZE, hMem); - /* Allocation succeeded, so save our entry */ - RtlSetUserValueHeap(hProcessHeap, - HEAP_NO_SERIALIZE, - HandleEntry->Object, - hMem); + /* Set the movable flag */ + Flags |= HEAP_SETTABLE_USER_VALUE | BASE_HEAP_FLAG_MOVABLE; + + /* Now allocate the actual heap for it */ + HandleEntry->Object = RtlAllocateHeap(BaseHeap, + Flags, + dwBytes); + BASE_TRACE_PTR(HandleEntry->Object, HandleEntry); + if (!HandleEntry->Object) + { + /* + * We failed, manually set the allocate flag and + * free the handle + */ + HandleEntry->Flags = RTL_HANDLE_VALID; + BaseHeapFreeEntry(HandleEntry); + + /* For the cleanup case */ + BASE_TRACE_FAILURE(); + HandleEntry = NULL; + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + } + else + { + /* Otherwise, copy the new heap and free the old one */ + RtlMoveMemory(HandleEntry->Object, hMem, dwBytes); + RtlFreeHeap(BaseHeap, HEAP_NO_SERIALIZE, hMem); + + /* Select the heap pointer */ + hMem = (HANDLE)&HandleEntry->Object; + + /* Initialize the count and default flags */ + HandleEntry->LockCount = 0; + HandleEntry->Flags = RTL_HANDLE_VALID | + BASE_HEAP_ENTRY_FLAG_MOVABLE; + + /* Check if it's also discardable */ + if (uFlags & GMEM_DISCARDABLE) + { + /* Set the internal flag */ + HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_REUSABLE; + } + + /* Check if it's also DDE Shared */ + if (uFlags & GMEM_DDESHARE) + { + /* Set the internal flag */ + HandleEntry->Flags |= BASE_HEAP_ENTRY_FLAG_DDESHARE; + } + + /* Allocation succeeded, so save our entry */ + RtlSetUserValueHeap(BaseHeap, + HEAP_NO_SERIALIZE, + HandleEntry->Object, + hMem); + } } } } @@ -986,7 +1065,7 @@ GlobalReAlloc(HGLOBAL hMem, else { /* Otherwise, this is a simple RTL Managed Heap, so just call it */ - hMem = RtlReAllocateHeap(hProcessHeap, + hMem = RtlReAllocateHeap(BaseHeap, Flags | HEAP_NO_SERIALIZE, hMem, dwBytes); @@ -999,7 +1078,7 @@ GlobalReAlloc(HGLOBAL hMem, } /* All done, unlock the heap and return the pointer */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return hMem; } @@ -1016,30 +1095,30 @@ GlobalSize(HGLOBAL hMem) SIZE_T dwSize = MAXULONG_PTR; /* Lock the heap */ - RtlLockHeap(hProcessHeap); - + RtlLockHeap(BaseHeap); _SEH2_TRY { /* Check if this is a simple RTL Heap Managed block */ if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)) { /* Then we'll query RTL Heap */ - RtlGetUserInfoHeap(hProcessHeap, Flags, hMem, &Handle, &Flags); - BASE_TRACE_PTR(Handle, hMem); - - /* - * Check if RTL Heap didn't give us a handle or said that this heap - * isn't movable. - */ - if (!(Handle) || !(Flags & BASE_HEAP_FLAG_MOVABLE)) + if (RtlGetUserInfoHeap(BaseHeap, Flags, hMem, &Handle, &Flags)) { - /* This implies we're not a handle heap, so use the generic call */ - dwSize = RtlSizeHeap(hProcessHeap, HEAP_NO_SERIALIZE, hMem); - } - else - { - /* Otherwise we're a handle heap, so get the internal handle */ - hMem = Handle; + BASE_TRACE_PTR(Handle, hMem); + /* + * Check if RTL Heap didn't give us a handle or said that this + * heap isn't movable. + */ + if (!(Handle) || !(Flags & BASE_HEAP_FLAG_MOVABLE)) + { + /* We're not a handle heap, so use the generic call */ + dwSize = RtlSizeHeap(BaseHeap, HEAP_NO_SERIALIZE, hMem); + } + else + { + /* We're a handle heap so get the internal handle */ + hMem = Handle; + } } } @@ -1065,30 +1144,30 @@ GlobalSize(HGLOBAL hMem) else { /* Otherwise, query RTL about it */ - dwSize = RtlSizeHeap(hProcessHeap, + dwSize = RtlSizeHeap(BaseHeap, HEAP_NO_SERIALIZE, HandleEntry->Object); } } - - /* Check if by now, we still haven't gotten any useful size */ - if (dwSize == MAXULONG_PTR) - { - /* Fail */ - BASE_TRACE_FAILURE(); - SetLastError(ERROR_INVALID_HANDLE); - dwSize = 0; - } } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { + /* Set failure for later */ + dwSize = MAXULONG_PTR; + } + _SEH2_END; + + /* Check if by now, we still haven't gotten any useful size */ + if (dwSize == MAXULONG_PTR) + { + /* Fail */ + BASE_TRACE_FAILURE(); SetLastError(ERROR_INVALID_HANDLE); dwSize = 0; } - _SEH2_END /* All done! Unlock heap and return the size */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return dwSize; } @@ -1117,7 +1196,7 @@ GlobalUnlock(HGLOBAL hMem) if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)) return RetVal; /* Otherwise, lock the heap */ - RtlLockHeap(hProcessHeap); + RtlLockHeap(BaseHeap); /* Get the handle entry */ HandleEntry = BaseHeapGetEntry(hMem); @@ -1156,10 +1235,10 @@ GlobalUnlock(HGLOBAL hMem) SetLastError(ERROR_INVALID_PARAMETER); RetVal = FALSE; } - _SEH2_END + _SEH2_END; /* All done. Unlock the heap and return the pointer */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return RetVal; } @@ -1292,7 +1371,7 @@ LocalAlloc(UINT uFlags, HANDLE hMemory; PBASE_HEAP_HANDLE_ENTRY HandleEntry; BASE_TRACE_ALLOC(dwBytes, uFlags); - ASSERT(hProcessHeap); + ASSERT(BaseHeap); /* Make sure the flags are valid */ if (uFlags & ~LMEM_VALID_FLAGS) @@ -1310,13 +1389,13 @@ LocalAlloc(UINT uFlags, if (!(uFlags & LMEM_MOVEABLE)) { /* Allocate heap for it */ - Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes); + Ptr = RtlAllocateHeap(BaseHeap, Flags, dwBytes); BASE_TRACE_ALLOC2(Ptr); return Ptr; } /* This is heap based, so lock it in first */ - RtlLockHeap(hProcessHeap); + RtlLockHeap(BaseHeap); /* * Disable locking, enable custom flags, and write the @@ -1342,7 +1421,7 @@ LocalAlloc(UINT uFlags, if (dwBytes) { /* Allocate the actual memory for it */ - Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes); + Ptr = RtlAllocateHeap(BaseHeap, Flags, dwBytes); BASE_TRACE_PTR(HandleEntry, Ptr); if (!Ptr) { @@ -1356,13 +1435,13 @@ LocalAlloc(UINT uFlags, else { /* All worked well, save our heap entry */ - RtlSetUserValueHeap(hProcessHeap, HEAP_NO_SERIALIZE, Ptr, hMemory); + RtlSetUserValueHeap(BaseHeap, HEAP_NO_SERIALIZE, Ptr, hMemory); } } Quickie: /* Cleanup! First unlock the heap */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); /* Check if a handle was allocated */ if (HandleEntry) @@ -1406,7 +1485,7 @@ NTAPI LocalCompact(UINT dwMinFree) { /* Call the RTL Heap Manager */ - return RtlCompactHeap(hProcessHeap, 0); + return RtlCompactHeap(BaseHeap, 0); } /* @@ -1422,13 +1501,13 @@ LocalFlags(HLOCAL hMem) UINT uFlags = LMEM_INVALID_HANDLE; /* Start by locking the heap */ - RtlLockHeap(hProcessHeap); + RtlLockHeap(BaseHeap); /* Check if this is a simple RTL Heap Managed block */ if (!((ULONG_PTR)hMem & BASE_HEAP_IS_HANDLE_ENTRY)) { /* Then we'll query RTL Heap */ - RtlGetUserInfoHeap(hProcessHeap, Flags, hMem, &Handle, &Flags); + RtlGetUserInfoHeap(BaseHeap, Flags, hMem, &Handle, &Flags); BASE_TRACE_PTR(Handle, hMem); /* @@ -1479,7 +1558,7 @@ LocalFlags(HLOCAL hMem) if (uFlags == LMEM_INVALID_HANDLE) SetLastError(ERROR_INVALID_HANDLE); /* All done! Unlock heap and return Win32 Flags */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return uFlags; } @@ -1534,7 +1613,7 @@ LocalReAlloc(HLOCAL hMem, if (!(uFlags & LMEM_MOVEABLE)) Flags |= HEAP_REALLOC_IN_PLACE_ONLY; /* Lock the heap and disable built-in locking in the RTL Heap funcitons */ - RtlLockHeap(hProcessHeap); + RtlLockHeap(BaseHeap); Flags |= HEAP_NO_SERIALIZE; /* Check if this is a simple handle-based block */ @@ -1580,7 +1659,7 @@ LocalReAlloc(HLOCAL hMem, if ((uFlags & LMEM_MOVEABLE) && !(HandleEntry->LockCount)) { /* Free the current heap */ - RtlFreeHeap(hProcessHeap, Flags, Ptr); + RtlFreeHeap(BaseHeap, Flags, Ptr); /* Free the handle */ HandleEntry->Object = NULL; @@ -1603,12 +1682,12 @@ LocalReAlloc(HLOCAL hMem, if (!Ptr) { /* We don't have a base, so allocate one */ - Ptr = RtlAllocateHeap(hProcessHeap, Flags, dwBytes); + Ptr = RtlAllocateHeap(BaseHeap, Flags, dwBytes); BASE_TRACE_ALLOC2(Ptr); if (Ptr) { /* Allocation succeeded, so save our entry */ - RtlSetUserValueHeap(hProcessHeap, + RtlSetUserValueHeap(BaseHeap, HEAP_NO_SERIALIZE, Ptr, hMem); @@ -1632,7 +1711,7 @@ LocalReAlloc(HLOCAL hMem, } /* And do the re-allocation */ - Ptr = RtlReAllocateHeap(hProcessHeap, Flags, Ptr, dwBytes); + Ptr = RtlReAllocateHeap(BaseHeap, Flags, Ptr, dwBytes); } /* Make sure we have a pointer by now */ @@ -1654,7 +1733,7 @@ LocalReAlloc(HLOCAL hMem, else if (!(uFlags & LMEM_MODIFY)) { /* Otherwise, this is a simple RTL Managed Heap, so just call it */ - hMem = RtlReAllocateHeap(hProcessHeap, + hMem = RtlReAllocateHeap(BaseHeap, Flags | HEAP_NO_SERIALIZE, hMem, dwBytes); @@ -1667,7 +1746,7 @@ LocalReAlloc(HLOCAL hMem, } /* All done, unlock the heap and return the pointer */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return hMem; } @@ -1680,7 +1759,7 @@ LocalShrink(HLOCAL hMem, UINT cbNewSize) { /* Call RTL */ - return RtlCompactHeap(hProcessHeap, 0); + return RtlCompactHeap(BaseHeap, 0); } /* @@ -1713,12 +1792,11 @@ LocalUnlock(HLOCAL hMem) } /* Otherwise, lock the heap */ - RtlLockHeap(hProcessHeap); + RtlLockHeap(BaseHeap); /* Get the handle entry */ HandleEntry = BaseHeapGetEntry(hMem); BASE_TRACE_HANDLE(HandleEntry, hMem); - _SEH2_TRY { /* Make sure it's valid */ @@ -1752,10 +1830,10 @@ LocalUnlock(HLOCAL hMem) SetLastError(ERROR_INVALID_PARAMETER); RetVal = FALSE; } - _SEH2_END + _SEH2_END; /* All done. Unlock the heap and return the pointer */ - RtlUnlockHeap(hProcessHeap); + RtlUnlockHeap(BaseHeap); return RetVal; } diff --git a/dll/win32/kernel32/include/baseheap.h b/dll/win32/kernel32/include/baseheap.h index c2a05e323bf..8cb2a7391e4 100644 --- a/dll/win32/kernel32/include/baseheap.h +++ b/dll/win32/kernel32/include/baseheap.h @@ -33,12 +33,6 @@ // API for it (such as GlobalLock). // -// -// The Handle Table -// -extern RTL_HANDLE_TABLE BaseHeapHandleTable; - -// // Tracing Support // Define _BASE_HANDLE_TRACE for Traces // diff --git a/dll/win32/kernel32/include/kernel32.h b/dll/win32/kernel32/include/kernel32.h index ec4109f3551..008d77d40e0 100644 --- a/dll/win32/kernel32/include/kernel32.h +++ b/dll/win32/kernel32/include/kernel32.h @@ -91,7 +91,6 @@ DWORD /* GLOBAL VARIABLES **********************************************************/ extern BOOL bIsFileApiAnsi; -extern HANDLE hProcessHeap; extern HANDLE hBaseDir; extern HMODULE hCurrentModule; @@ -110,6 +109,10 @@ extern BOOLEAN BaseRunningInServerProcess; /* FUNCTION PROTOTYPES *******************************************************/ +VOID +NTAPI +BaseDllInitializeMemoryManager(VOID); + BOOL WINAPI VerifyConsoleIoHandle(HANDLE Handle); BOOL WINAPI CloseConsoleHandle(HANDLE Handle); @@ -249,3 +252,11 @@ BaseSetLastNTError(IN NTSTATUS Status); /* FIXME */ WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *); + +HANDLE +WINAPI +DuplicateConsoleHandle(HANDLE hConsole, + DWORD dwDesiredAccess, + BOOL bInheritHandle, + DWORD dwOptions); + diff --git a/dll/win32/shlwapi/shlwapi_Hu.rc b/dll/win32/shlwapi/shlwapi_Hu.rc index 94ce85e2e52..676b1d4c87d 100644 --- a/dll/win32/shlwapi/shlwapi_Hu.rc +++ b/dll/win32/shlwapi/shlwapi_Hu.rc @@ -33,10 +33,10 @@ FONT 8, "MS Shell Dlg" LTEXT "", IDS_ERR_USER_MSG2, 15, 5, 28, 20 LTEXT "", IDS_ERR_USER_MSG, 15, 5, 210, 8 CHECKBOX "Ne jelení&tse meg ezt az üzenetet mégegyszer", IDC_ERR_DONT_SHOW, 5, 20, 210, 10, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&OK", IDOK, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&Mégse", IDCANCEL, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&Igen", IDYES, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&Nem", IDNO, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&OK" IDOK, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Mégse" IDCANCEL, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Igen" IDYES, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Nem" IDNO, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP } STRINGTABLE diff --git a/dll/win32/shlwapi/shlwapi_Pt.rc b/dll/win32/shlwapi/shlwapi_Pt.rc index bd07373744d..2080fc5bcdc 100644 --- a/dll/win32/shlwapi/shlwapi_Pt.rc +++ b/dll/win32/shlwapi/shlwapi_Pt.rc @@ -34,10 +34,10 @@ FONT 8, "MS Shell Dlg" LTEXT "", IDS_ERR_USER_MSG2, 15, 5, 28, 20 LTEXT "", IDS_ERR_USER_MSG, 15, 5, 210, 8 CHECKBOX "Não &mostrar esta mensagem novamente", IDC_ERR_DONT_SHOW, 5, 20, 210, 10, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&OK", IDOK, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&Cancelar", IDCANCEL, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&Sim", IDYES, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP - PUSHBUTTON L"&Não", IDNO, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&OK" IDOK, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Cancelar" IDCANCEL, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Sim" IDYES, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Não" IDNO, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP } STRINGTABLE diff --git a/dll/win32/wsock32/wsock32.spec b/dll/win32/wsock32/wsock32.spec index 493d01ebd4d..4d8571a8faa 100644 --- a/dll/win32/wsock32/wsock32.spec +++ b/dll/win32/wsock32/wsock32.spec @@ -7,9 +7,9 @@ 7 stdcall getsockopt(long long long ptr ptr) ws2_32.getsockopt 8 stdcall htonl(long) ws2_32.htonl 9 stdcall htons(long) ws2_32.htons -10 stdcall ioctlsocket(long long ptr) ws2_32.ioctlsocket -11 stdcall inet_addr(str) ws2_32.inet_addr -12 stdcall inet_ntoa(ptr) ws2_32.inet_ntoa +10 stdcall inet_addr(str) ws2_32.inet_addr +11 stdcall inet_ntoa(ptr) ws2_32.inet_ntoa +12 stdcall ioctlsocket(long long ptr) ws2_32.ioctlsocket 13 stdcall listen(long long) ws2_32.listen 14 stdcall ntohl(long) ws2_32.ntohl 15 stdcall ntohs(long) ws2_32.ntohs diff --git a/drivers/network/ndis/ndis/miniport.c b/drivers/network/ndis/ndis/miniport.c index c5e9e6fb43c..3353f69518a 100644 --- a/drivers/network/ndis/ndis/miniport.c +++ b/drivers/network/ndis/ndis/miniport.c @@ -1877,7 +1877,6 @@ NdisIPnPStartDevice( { NDIS_DbgPrint(MIN_TRACE, ("Failed to open configuration key\n")); ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock ); - NdisCloseConfiguration(ConfigHandle); return NdisStatus; } diff --git a/drivers/network/tcpip/include/debug.h b/drivers/network/tcpip/include/debug.h index 0e3e409b28e..303d66a5556 100644 --- a/drivers/network/tcpip/include/debug.h +++ b/drivers/network/tcpip/include/debug.h @@ -33,15 +33,13 @@ #define DEBUG_INFO 0x02000000 #define DEBUG_ULTRA 0x7FFFFFFF -#define DBG 1 - #if DBG #define REMOVE_PARENS(...) __VA_ARGS__ #define TI_DbgPrint(_t_, _x_) \ DbgPrintEx(DPFLTR_TCPIP_ID, (_t_) | DPFLTR_MASK, "(%s:%d) ", __FILE__, __LINE__), \ DbgPrintEx(DPFLTR_TCPIP_ID, (_t_) | DPFLTR_MASK, REMOVE_PARENS _x_) - //DbgPrint(REMOVE_PARENS _x_) + #else /* DBG */ #define TI_DbgPrint(_t_, _x_) diff --git a/drivers/storage/ide/uniata/id_sata.cpp b/drivers/storage/ide/uniata/id_sata.cpp index 0a658224870..a48d6e0630b 100644 --- a/drivers/storage/ide/uniata/id_sata.cpp +++ b/drivers/storage/ide/uniata/id_sata.cpp @@ -242,8 +242,7 @@ UniataSataEvent( return FALSE; } // end UniataSataEvent() -ULONG -NTAPI +ULONG NTAPI UniataSataReadPort4( IN PHW_CHANNEL chan, diff --git a/drivers/usb/usbehci/usbehci.h b/drivers/usb/usbehci/usbehci.h index 903a01f541b..09e29479111 100644 --- a/drivers/usb/usbehci/usbehci.h +++ b/drivers/usb/usbehci/usbehci.h @@ -96,7 +96,8 @@ typedef struct _COMMON_DEVICE_EXTENSION typedef struct _FDO_DEVICE_EXTENSION { COMMON_DEVICE_EXTENSION Common; - + PDRIVER_OBJECT DriverObject; + PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT LowerDevice; PDEVICE_OBJECT Pdo; ULONG DeviceState; diff --git a/hal/halx86/mp/i386/mps.S b/hal/halx86/mp/i386/mps.S index 250ab9c7d97..094780f4826 100644 --- a/hal/halx86/mp/i386/mps.S +++ b/hal/halx86/mp/i386/mps.S @@ -11,9 +11,7 @@ /* INCLUDES ******************************************************************/ -#include - -#include +#include /* FUNCTIONS *****************************************************************/ diff --git a/include/psdk/winefs.h b/include/psdk/winefs.h index a46f7a50fbf..f4a2282f1e9 100644 --- a/include/psdk/winefs.h +++ b/include/psdk/winefs.h @@ -47,6 +47,11 @@ BOOL WINAPI EncryptionDisable ( BOOL ); +BOOL WINAPI FileEncryptionStatus ( + LPCTSTR, + LPDWORD + ); + DWORD WINAPI QueryUsersOnEncryptedFile ( LPCWSTR, PENCRYPTION_CERTIFICATE_HASH_LIST* diff --git a/include/reactos/buildno.h.cmake b/include/reactos/buildno.h.cmake index ac47278617c..6e5e34534a8 100644 --- a/include/reactos/buildno.h.cmake +++ b/include/reactos/buildno.h.cmake @@ -1,18 +1,18 @@ -/* Do not edit - Machine generated */ -#ifndef _INC_REACTOS_BUILDNO -#define _INC_REACTOS_BUILDNO -#define KERNEL_VERSION_BUILD @KERNEL_VERSION_BUILD@ -#define KERNEL_VERSION_BUILD_HEX 0x@KERNEL_VERSION_BUILD_HEX@ -#define KERNEL_VERSION_BUILD_STR "@KERNEL_VERSION_BUILD@@REVISION@" -#define KERNEL_VERSION_BUILD_RC "@KERNEL_VERSION_BUILD@@REVISION@\0" -#define KERNEL_RELEASE_RC "@KERNEL_VERSION@\0" -#define KERNEL_RELEASE_STR "@KERNEL_VERSION@" -#define KERNEL_VERSION_RC "@KERNEL_VERSION@\0" -#define KERNEL_VERSION_STR "@KERNEL_VERSION@" -#define REACTOS_DLL_VERSION_MAJOR @REACTOS_DLL_VERSION_MAJOR@ -#define REACTOS_DLL_RELEASE_RC "@DLL_VERSION_STR@\0" -#define REACTOS_DLL_RELEASE_STR "@DLL_VERSION_STR@" -#define REACTOS_DLL_VERSION_RC "@DLL_VERSION_STR@\0" -#define REACTOS_DLL_VERSION_STR "@DLL_VERSION_STR@" -#endif -/* EOF */ +/* Do not edit - Machine generated */ +#ifndef _INC_REACTOS_BUILDNO +#define _INC_REACTOS_BUILDNO +#define KERNEL_VERSION_BUILD @KERNEL_VERSION_BUILD@ +#define KERNEL_VERSION_BUILD_HEX 0x@KERNEL_VERSION_BUILD_HEX@ +#define KERNEL_VERSION_BUILD_STR "@KERNEL_VERSION_BUILD@@REVISION@" +#define KERNEL_VERSION_BUILD_RC "@KERNEL_VERSION_BUILD@@REVISION@\0" +#define KERNEL_RELEASE_RC "@KERNEL_VERSION@\0" +#define KERNEL_RELEASE_STR "@KERNEL_VERSION@" +#define KERNEL_VERSION_RC "@KERNEL_VERSION@\0" +#define KERNEL_VERSION_STR "@KERNEL_VERSION@" +#define REACTOS_DLL_VERSION_MAJOR @REACTOS_DLL_VERSION_MAJOR@ +#define REACTOS_DLL_RELEASE_RC "@DLL_VERSION_STR@\0" +#define REACTOS_DLL_RELEASE_STR "@DLL_VERSION_STR@" +#define REACTOS_DLL_VERSION_RC "@DLL_VERSION_STR@\0" +#define REACTOS_DLL_VERSION_STR "@DLL_VERSION_STR@" +#endif +/* EOF */ diff --git a/include/reactos/mc/neteventmsg.mc b/include/reactos/mc/neteventmsg.mc index 3800d163961..420c4519673 100644 --- a/include/reactos/mc/neteventmsg.mc +++ b/include/reactos/mc/neteventmsg.mc @@ -22,7 +22,49 @@ LanguageNames=(English=0x409:MSG00409) ; Facility=System -; Eventlog messages 6xxx- +; +; eventlog events 6000-6099 +; + +MessageId=6000 +Severity=Warning +Facility=System +SymbolicName=EVENT_LOG_FULL +Language=English +The %1 log file is full. +. + +MessageId=6001 +Severity=Warning +Facility=System +SymbolicName=EVENT_LogFileNotOpened +Language=English +The %1 log file cannot be opened. +. + +MessageId=6002 +Severity=Warning +Facility=System +SymbolicName=EVENT_LogFileCorrupt +Language=English +The %1 log file is corrupted and will be cleared. +. + +MessageId=6003 +Severity=Warning +Facility=System +SymbolicName=EVENT_DefaultLogCorrupt +Language=English +The Application log file could not be opened. %1 will be used as the default log file. +. + +MessageId=6004 +Severity=Warning +Facility=System +SymbolicName=EVENT_BadDriverPacket +Language=English +A driver packet received from the I/O subsystem was invalid. The data is the packet. +. MessageId=6005 Severity=Warning @@ -40,6 +82,22 @@ Language=English The Event log service was stopped. . +MessageId=6007 +Severity=Warning +Facility=System +SymbolicName=TITLE_EventlogMessageBox +Language=English +Eventlog Service %0 +. + +MessageId=6008 +Severity=Warning +Facility=System +SymbolicName=EVENT_EventlogAbnormalShutdown +Language=English +The previous system shutdown at %1 on %2 was unexpected. +. + MessageId=6009 Severity=Warning Facility=System @@ -48,8 +106,366 @@ Language=English ReactOS %1 %2 %3 %4. . +MessageId=6010 +Severity=Error +Facility=System +SymbolicName=EVENT_ServiceNoEventLog +Language=English +The %1 service was unable to set up an event source. +. -; transport messages +MessageId=6011 +Severity=Error +Facility=System +SymbolicName=EVENT_ComputerNameChange +Language=English +The NetBIOS name and DNS host name of this machine have been changed from %1 to %2. +. + +MessageId=6012 +Severity=Error +Facility=System +SymbolicName=EVENT_DNSDomainNameChange +Language=English +The DNS domain assigned to this computer has been changed from %1 to %2. +. + + +; +; system events 6100 - 6199 +; + +MessageId=6100 +Severity=Error +Facility=System +SymbolicName=EVENT_UP_DRIVER_ON_MP +Language=English +A uniprocessor-specific driver was loaded on a multiprocessor system. The driver could not load. +. + + +; +; service controller events 7000-7899 +; + +MessageId=7000 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_START_FAILED +Language=English +The %1 service failed to start due to the following error: %n%2 +. + +MessageId=7001 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_START_FAILED_II +Language=English +The %1 service depends on the %2 service which failed to start because of the following error: %n%3 +. + +MessageId=7002 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_START_FAILED_GROUP +Language=English +The %1 service depends on the %2 group and no member of this group started. +. + +MessageId=7003 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_START_FAILED_NONE +Language=English +The %1 service depends on the following nonexistent service: %2 +. + +MessageId=7004 +Severity=Error +Facility=System +SymbolicName=EVENT_CALL_TO_FUNCTION_FAILED +Language=English +The %1 call failed with the following error: %n%2 +. + +MessageId=7005 +Severity=Error +Facility=System +SymbolicName=EVENT_CALL_TO_FUNCTION_FAILED_II +Language=English +The %1 call failed for %2 with the following error: %n%3 +. + +MessageId=7006 +Severity=Error +Facility=System +SymbolicName=EVENT_REVERTED_TO_LASTKNOWNGOOD +Language=English +The system reverted to its last known good configuration. The system is restarting.... +. + +MessageId=7007 +Severity=Error +Facility=System +SymbolicName=EVENT_BAD_ACCOUNT_NAME +Language=English +No backslash is in the account name. +. + +MessageId=7008 +Severity=Error +Facility=System +SymbolicName=EVENT_CONNECTION_TIMEOUT +Language=English +Timeout (%1 milliseconds) waiting for the %2 service to connect. +. + +MessageId=7009 +Severity=Error +Facility=System +SymbolicName=EVENT_READFILE_TIMEOUT +Language=English +Timeout (%1 milliseconds) waiting for ReadFile. +. + +MessageId=7010 +Severity=Error +Facility=System +SymbolicName=EVENT_TRANSACT_TIMEOUT +Language=English +Timeout (%1 milliseconds) waiting for a transaction response from the %2 service. +. + +MessageId=7011 +Severity=Error +Facility=System +SymbolicName=EVENT_TRANSACT_INVALID +Language=English +Message returned in transaction has incorrect size. +. + +MessageId=7012 +Severity=Error +Facility=System +SymbolicName=EVENT_FIRST_LOGON_FAILED +Language=English +Logon attempt with current password failed with the following error: %n%1 +. + +MessageId=7013 +Severity=Error +Facility=System +SymbolicName=EVENT_SECOND_LOGON_FAILED +Language=English +Second logon attempt with old password also failed with the following error: %n%1 +. + +MessageId=7014 +Severity=Error +Facility=System +SymbolicName=EVENT_INVALID_DRIVER_DEPENDENCY +Language=English +Boot-start or system-start driver (%1) must not depend on a service. +. + +MessageId=7015 +Severity=Error +Facility=System +SymbolicName=EVENT_BAD_SERVICE_STATE +Language=English +The %1 service has reported an invalid current state %2. +. + +MessageId=7016 +Severity=Error +Facility=System +SymbolicName=EVENT_CIRCULAR_DEPENDENCY_DEMAND +Language=English +Detected circular dependencies demand starting %1. +. + +MessageId=7017 +Severity=Error +Facility=System +SymbolicName=EVENT_CIRCULAR_DEPENDENCY_AUTO +Language=English +Detected circular dependencies auto-starting services. +. + +MessageId=7018 +Severity=Error +Facility=System +SymbolicName=EVENT_DEPEND_ON_LATER_SERVICE +Language=English +Circular dependency: The %1 service depends on a service in a group which starts later. +. + +MessageId=7019 +Severity=Error +Facility=System +SymbolicName=EVENT_DEPEND_ON_LATER_GROUP +Language=English +Circular dependency: The %1 service depends on a group which starts later. +. + +MessageId=7020 +Severity=Error +Facility=System +SymbolicName=EVENT_SEVERE_SERVICE_FAILED +Language=English +About to revert to the last known good configuration because the %1 service failed to start. +. + +MessageId=7021 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_START_HUNG +Language=English +The %1 service hung on starting. +. + +MessageId=7022 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_EXIT_FAILED +Language=English +The %1 service terminated with the following error: %n%2 +. + +MessageId=7023 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_EXIT_FAILED_SPECIFIC +Language=English +The %1 service terminated with service-specific error %2. +. + +MessageId=7024 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_START_AT_BOOT_FAILED +Language=English +At least one service or driver failed during system startup. Use Event Viewer to examine the event log for details. +. + +MessageId=7025 +Severity=Error +Facility=System +SymbolicName=EVENT_BOOT_SYSTEM_DRIVERS_FAILED +Language=English +The following boot-start or system-start driver(s) failed to load: %1 +. + +MessageId=7026 +Severity=Error +Facility=System +SymbolicName=EVENT_RUNNING_LASTKNOWNGOOD +Language=English +ReactOS could not be started as configured. A previous working configuration was used instead. +. + +MessageId=7027 +Severity=Error +Facility=System +SymbolicName=EVENT_TAKE_OWNERSHIP +Language=English +The %1 Registry key denied access to SYSTEM account programs so the Service Control Manager took ownership of the Registry key. +. + +MessageId=7028 +Severity=Error +Facility=System +SymbolicName=TITLE_SC_MESSAGE_BOX +Language=English +Service Control Manager %0 +. + +MessageId=7029 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_NOT_INTERACTIVE +Language=English +The %1 service is marked as an interactive service. However, the system is configured to not allow interactive services. This service may not function properly. +. + +MessageId=7030 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_CRASH +Language=English +The %1 service terminated unexpectedly. It has done this %2 time(s). The following corrective action will be taken in %3 milliseconds: %5. +. + +MessageId=7031 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_RECOVERY_FAILED +Language=English +The Service Control Manager tried to take a corrective action (%2) after the unexpected termination of the %3 service, but this action failed with the following error: %n%4 +. + +MessageId=7032 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_SCESRV_FAILED +Language=English +The Service Control Manager did not initialize successfully. The security +configuration server (scesrv.dll) failed to initialize with error %1. The +system is restarting... +. + +MessageId=7033 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_CRASH_NO_ACTION +Language=English +The %1 service terminated unexpectedly. It has done this %2 time(s). +. + +MessageId=7034 +Severity=Informational +Facility=System +SymbolicName=EVENT_SERVICE_CONTROL_SUCCESS +Language=English +The %1 service was successfully sent a %2 control. +. + +MessageId=7035 +Severity=Informational +Facility=System +SymbolicName=EVENT_SERVICE_STATUS_SUCCESS +Language=English +Service Control Manager %0 +. + +MessageId=7036 +Severity=Error +Facility=System +SymbolicName=EVENT_SERVICE_CONFIG_BACKOUT_FAILED +Language=English +The Service Control Manager encountered an error undoing a configuration change +to the %1 service. The service's %2 is currently in an unpredictable state. + +If you do not correct this configuration, you may not be able to restart the %1 +service or may encounter other errors. To ensure that the service is configured +properly, use the Services snap-in in Microsoft Management Console (MMC). +. + +MessageId=7037 +Severity=Error +Facility=System +SymbolicName=EVENT_FIRST_LOGON_FAILED_II +Language=English +The %1 service was unable to log on as %2 with the currently configured +password due to the following error: %n%3%n%nTo ensure that the service is +configured properly, use the Services snap-in in Microsoft Management +Console (MMC). +. + + +; +; transport events 9000-9499 +; MessageId=9004 Severity=Error diff --git a/include/reactos/version.h.cmake b/include/reactos/version.h.cmake index 64dc2f3eda9..7ced99b1620 100644 --- a/include/reactos/version.h.cmake +++ b/include/reactos/version.h.cmake @@ -1,31 +1,31 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: include/internal/version.h - * PURPOSE: Defines the current version - * PROGRAMMER: David Welch (welch@mcmail.com) - * REVISIONS: - * 1999-11-06 (ea) - * Moved from include/internal in include/reactos - * to be used by buildno. - * 2002-01-17 (ea) - * KERNEL_VERSION removed. Use - * reactos/buildno.h:KERNEL_VERSION_STR instead. - */ - -#ifndef __VERSION_H -#define __VERSION_H - -#define KERNEL_VERSION_MAJOR @KERNEL_VERSION_MAJOR@ -#define KERNEL_VERSION_MINOR @KERNEL_VERSION_MINOR@ -#define KERNEL_VERSION_PATCH_LEVEL @KERNEL_VERSION_PATCH_LEVEL@ - -#define COPYRIGHT_YEAR "@COPYRIGHT_YEAR@" - -/* KERNEL_VERSION_BUILD_TYPE is L"SVN", L"RC1", L"RC2" or L"" (for the release) */ -#define KERNEL_VERSION_BUILD_TYPE "@KERNEL_VERSION_BUILD_TYPE@" - - -#endif - -/* EOF */ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: include/internal/version.h + * PURPOSE: Defines the current version + * PROGRAMMER: David Welch (welch@mcmail.com) + * REVISIONS: + * 1999-11-06 (ea) + * Moved from include/internal in include/reactos + * to be used by buildno. + * 2002-01-17 (ea) + * KERNEL_VERSION removed. Use + * reactos/buildno.h:KERNEL_VERSION_STR instead. + */ + +#ifndef __VERSION_H +#define __VERSION_H + +#define KERNEL_VERSION_MAJOR @KERNEL_VERSION_MAJOR@ +#define KERNEL_VERSION_MINOR @KERNEL_VERSION_MINOR@ +#define KERNEL_VERSION_PATCH_LEVEL @KERNEL_VERSION_PATCH_LEVEL@ + +#define COPYRIGHT_YEAR "@COPYRIGHT_YEAR@" + +/* KERNEL_VERSION_BUILD_TYPE is L"SVN", L"RC1", L"RC2" or L"" (for the release) */ +#define KERNEL_VERSION_BUILD_TYPE "@KERNEL_VERSION_BUILD_TYPE@" + + +#endif + +/* EOF */ diff --git a/include/reactos/wine/alloca.h b/include/reactos/wine/alloca.h index 265fecfb54f..72972026fb8 100644 --- a/include/reactos/wine/alloca.h +++ b/include/reactos/wine/alloca.h @@ -1,2 +1,8 @@ +#ifdef _MSC_VER #include +#define alloca _alloca +#else +#include_next +#endif + diff --git a/include/reactos/wine/port.h b/include/reactos/wine/port.h index 2853a42bb41..0b253172ff5 100644 --- a/include/reactos/wine/port.h +++ b/include/reactos/wine/port.h @@ -153,11 +153,7 @@ struct statfs; /* Constructor functions */ -#ifdef _MSC_VER // ReactOS -#pragma message("DECL_GLOBAL_CONSTRUCTOR is not properly defined") -# define DECL_GLOBAL_CONSTRUCTOR(func) \ - static void func(void) -#elif defined(__GNUC__) +#ifdef __GNUC__ # define DECL_GLOBAL_CONSTRUCTOR(func) \ static void func(void) __attribute__((constructor)); \ static void func(void) diff --git a/include/reactos/wine/test.h b/include/reactos/wine/test.h index 22d64ce7570..eb45ad653b1 100644 --- a/include/reactos/wine/test.h +++ b/include/reactos/wine/test.h @@ -96,7 +96,7 @@ extern void winetest_vskip( const char *msg, __winetest_va_list ap ); #ifdef __GNUC__ -extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ); +extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) __attribute__((format (printf,2,3) )); extern void __winetest_cdecl winetest_skip( const char *msg, ... ) __attribute__((format (printf,1,2))); extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2))); extern void __winetest_cdecl winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2))); @@ -440,13 +440,13 @@ void winetest_wait_child_process( HANDLE process ) { if (exit_code > 255) { - fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, (unsigned int)exit_code ); + fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, exit_code ); InterlockedIncrement( &failures ); } else { fprintf( stdout, "%s: %u failures in child process\n", - current_test->name, (unsigned int)exit_code ); + current_test->name, exit_code ); while (exit_code-- > 0) InterlockedIncrement(&failures); } @@ -558,10 +558,10 @@ static int run_test( const char *name ) if (winetest_debug) { fprintf( stdout, "%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n", - test->name, (int)(successes + failures + todo_successes + todo_failures), - (int)todo_successes, (int)(failures + todo_failures), + test->name, successes + failures + todo_successes + todo_failures, + todo_successes, failures + todo_failures, (failures + todo_failures != 1) ? "failures" : "failure", - (int)skipped ); + skipped ); } status = (failures + todo_failures < 255) ? failures + todo_failures : 255; return status; diff --git a/include/reactos/wine/typeof.h b/include/reactos/wine/typeof.h index 369e4029815..daefcc185af 100644 --- a/include/reactos/wine/typeof.h +++ b/include/reactos/wine/typeof.h @@ -25,7 +25,7 @@ struct _xsltStylesheet; struct jpeg_decompress_struct; typedef struct IWineD3D * (__stdcall typeof(WineDirect3DCreate))(unsigned int, struct IUnknown *); -typedef struct IWineD3DClipper * (__stdcall typeof(WineDirect3DCreateClipper))(void); +typedef struct IWineD3DClipper * (__stdcall typeof(WineDirect3DCreateClipper))(struct IUnknown *); typedef int (__stdcall typeof(ImeInquire))(struct _tagIMEINFO *, __typeof_wchar *, const __typeof_wchar *); typedef int (__stdcall typeof(ImeConfigure))(void *, void *, unsigned int, void *); typedef int (__stdcall typeof(ImeDestroy))(unsigned int); diff --git a/lib/drivers/ip/network/routines.c b/lib/drivers/ip/network/routines.c index 1c01c1b7833..44aa2761076 100644 --- a/lib/drivers/ip/network/routines.c +++ b/lib/drivers/ip/network/routines.c @@ -54,9 +54,46 @@ static VOID DisplayIPHeader( ((IPHeader->DstAddr >> 16) & 0xFF), ((IPHeader->DstAddr >> 24) & 0xFF)); } +static VOID DisplayTCPHeader( + PCHAR Header, + UINT Length) +{ + /* FIXME: IPv4 only */ + PIPv4_HEADER IPHeader = (PIPv4_HEADER)Header; + PTCPv4_HEADER TCPHeader; + + if (IPHeader->Protocol != IPPROTO_TCP) { + DbgPrint("This is not a TCP datagram. Protocol is %d\n", IPHeader->Protocol); + return; + } + + TCPHeader = (PTCPv4_HEADER)((PCHAR)IPHeader + (IPHeader->VerIHL & 0x0F) * 4); + + DbgPrint("TCP header:\n"); + DbgPrint(" SourcePort: %d\n", WN2H(TCPHeader->SourcePort)); + DbgPrint(" DestinationPort: %d\n", WN2H(TCPHeader->DestinationPort)); + DbgPrint(" SequenceNumber: 0x%x\n", DN2H(TCPHeader->SequenceNumber)); + DbgPrint(" AckNumber: 0x%x\n", DN2H(TCPHeader->AckNumber)); + DbgPrint(" DataOffset: 0x%x (0x%x) 32-bit words\n", TCPHeader->DataOffset, TCPHeader->DataOffset >> 4); + DbgPrint(" Flags: 0x%x (0x%x)\n", TCPHeader->Flags, TCPHeader->Flags & 0x3F); + if ((TCPHeader->Flags & TCP_URG) > 0) DbgPrint(" TCP_URG - Urgent Pointer field significant\n"); + if ((TCPHeader->Flags & TCP_ACK) > 0) DbgPrint(" TCP_ACK - Acknowledgement field significant\n"); + if ((TCPHeader->Flags & TCP_PSH) > 0) DbgPrint(" TCP_PSH - Push Function\n"); + if ((TCPHeader->Flags & TCP_RST) > 0) DbgPrint(" TCP_RST - Reset the connection\n"); + if ((TCPHeader->Flags & TCP_SYN) > 0) DbgPrint(" TCP_SYN - Synchronize sequence numbers\n"); + if ((TCPHeader->Flags & TCP_FIN) > 0) DbgPrint(" TCP_FIN - No more data from sender\n"); + DbgPrint(" Window: 0x%x\n", WN2H(TCPHeader->Window)); + DbgPrint(" Checksum: 0x%x\n", WN2H(TCPHeader->Checksum)); + DbgPrint(" Urgent: 0x%x\n", WN2H(TCPHeader->Urgent)); +} + + VOID DisplayTCPPacket( PIP_PACKET IPPacket) { + UINT Length; + PCHAR Buffer; + if ((DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK) != TRUE) || (DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_TCP | DPFLTR_MASK) != TRUE)) { return; @@ -75,6 +112,20 @@ VOID DisplayTCPPacket( TI_DbgPrint(MIN_TRACE, ("TotalSize (%d).\n", IPPacket->TotalSize)); TI_DbgPrint(MIN_TRACE, ("ContigSize (%d).\n", IPPacket->ContigSize)); TI_DbgPrint(MIN_TRACE, ("NdisPacket (0x%X).\n", IPPacket->NdisPacket)); + + if (IPPacket->NdisPacket) { + NdisQueryPacket(IPPacket->NdisPacket, NULL, NULL, NULL, &Length); + Buffer = ExAllocatePool(NonPagedPool, Length); + if (Buffer) { + Length = CopyPacketToBuffer(Buffer, IPPacket->NdisPacket, 0, Length); + DisplayTCPHeader(Buffer, Length); + ExFreePool(Buffer); + } + } else { + Buffer = IPPacket->Header; + Length = IPPacket->ContigSize; + DisplayTCPHeader(Buffer, Length); + } } #endif diff --git a/lib/rossym/compat.h b/lib/rossym/compat.h index 375b498fa3e..64dc549f11c 100644 --- a/lib/rossym/compat.h +++ b/lib/rossym/compat.h @@ -32,8 +32,6 @@ void *RosSymRealloc(void *mem, ulong newsize); void xfree(void *v); #define werrstr(str, ...) DPRINT(str "\n" ,##__VA_ARGS__) -//#define werrstr(x, ...) printf("(%s:%d) " x "\n",__FILE__,__LINE__,##__VA_ARGS__) - #define malloc(x) RosSymAllocMem(x) #define mallocz(x,y) RosSymAllocMemZero(x,y) #define free(x) xfree(x) diff --git a/lib/rossym/delete.c b/lib/rossym/delete.c index 1e6fe8393e2..c97e40c7799 100644 --- a/lib/rossym/delete.c +++ b/lib/rossym/delete.c @@ -10,19 +10,15 @@ #define NTOSAPI #include #include -#include +#include "rossympriv.h" #define NDEBUG #include -#include "rossympriv.h" -#include "pe.h" -#include "dwarf.h" - VOID RosSymDelete(PROSSYM_INFO RosSymInfo) { - dwarfclose(RosSymInfo); + RosSymFreeMem(RosSymInfo); } /* EOF */ diff --git a/lib/rossym/dwarf.h b/lib/rossym/dwarf.h index 7308d7deab0..04689814bd7 100644 --- a/lib/rossym/dwarf.h +++ b/lib/rossym/dwarf.h @@ -6,8 +6,6 @@ typedef struct DwarfBlock DwarfBlock; typedef struct DwarfBuf DwarfBuf; typedef struct DwarfExpr DwarfExpr; typedef struct DwarfSym DwarfSym; -typedef struct DwarfStack DwarfStack; -typedef struct DwarfParam DwarfParam; typedef union DwarfVal DwarfVal; enum @@ -205,16 +203,6 @@ struct DwarfBlock ulong len; }; -struct DwarfParam -{ - char *name; - ulong unit; - ulong type; - ulong loctype; - ulong fde, len; - ulong value; -}; - /* not for consumer use */ struct DwarfBuf { @@ -384,16 +372,19 @@ struct DwarfExpr struct DwarfSym { - DwarfAttrs attrs; - + DwarfAttrs attrs; + /* not for consumer use... */ - uint num; - DwarfBuf b; - int depth; - ulong unit, childoff, nextunit; - ulong aoff; + DwarfBuf b; + ulong unit; + uint uoff; + ulong aoff; + int depth; + int allunits; + ulong nextunit; }; + struct _Pe; Dwarf *dwarfopen(struct _Pe *elf); void dwarfclose(Dwarf*); @@ -407,11 +398,9 @@ int dwarfenumunit(Dwarf*, ulong, DwarfSym*); int dwarfseeksym(Dwarf*, ulong, ulong, DwarfSym*); int dwarfenum(Dwarf*, DwarfSym*); int dwarfnextsym(Dwarf*, DwarfSym*); -int dwarfnextsymat(Dwarf*, DwarfSym *parent, DwarfSym *child); -int dwarfpctoline(Dwarf*, DwarfSym *proc, ulong, char**, char**, ulong *); -int dwarfgetarg(Dwarf *d, const char *name, DwarfBuf *locbuf, ulong cfa, PROSSYM_REGISTERS registers, ulong *value); -int dwarfgettype(Dwarf *d, DwarfSym *param, DwarfSym *type); - +int dwarfnextsymat(Dwarf*, DwarfSym*, int); +int dwarfpctoline(Dwarf*, ulong, char**, char**, char**, char **, ulong*, ulong*, ulong*); +int dwarfunwind(Dwarf*, ulong, DwarfExpr*, DwarfExpr*, DwarfExpr*, int); ulong dwarfget1(DwarfBuf*); ulong dwarfget2(DwarfBuf*); ulong dwarfget4(DwarfBuf*); @@ -422,10 +411,7 @@ ulong dwarfgetaddr(DwarfBuf*); int dwarfgetn(DwarfBuf*, uchar*, int); uchar *dwarfgetnref(DwarfBuf*, ulong); char *dwarfgetstring(DwarfBuf*); -int dwarfcomputecfa(Dwarf *d, DwarfExpr *cfa, PROSSYM_REGISTERS registers, ulong *cfaLocation); -int dwarfregunwind(Dwarf *d, ulong pc, ulong fde, DwarfExpr *cfa, PROSSYM_REGISTERS registers); -int dwarfargvalue(Dwarf *d, DwarfSym *proc, ulong pc, ulong cfa, PROSSYM_REGISTERS registers, DwarfParam *parameters); -int dwarfgetparams(Dwarf *d, DwarfSym *s, ulong pc, int pnum, DwarfParam *paramblocks); + typedef struct DwarfAbbrev DwarfAbbrev; typedef struct DwarfAttr DwarfAttr; @@ -463,7 +449,6 @@ struct Dwarf DwarfBlock pubtypes; DwarfBlock ranges; DwarfBlock str; - DwarfBlock loc; /* little cache */ struct { @@ -473,15 +458,14 @@ struct Dwarf } acache; }; -struct DwarfStack -{ - ulong storage[16]; // own storage - ulong *data; - ulong length, max; -}; - DwarfAbbrev *dwarfgetabbrev(Dwarf*, ulong, ulong); int dwarfgetinfounit(Dwarf*, ulong, DwarfBlock*); +extern int dwarf386nregs; +extern char *dwarf386regs[]; +extern char *dwarf386fp; + +#define SYMBOL_SIZE 18 #define MAXIMUM_DWARF_NAME_SIZE 64 +#define MAXIMUM_COFF_SYMBOL_LENGTH 256 diff --git a/lib/rossym/dwarfabbrev.c b/lib/rossym/dwarfabbrev.c index 365d44232d4..d21ca6a25d1 100644 --- a/lib/rossym/dwarfabbrev.c +++ b/lib/rossym/dwarfabbrev.c @@ -25,119 +25,117 @@ DwarfAbbrev *dwarfgetabbrev(Dwarf*, ulong, ulong); static int loadabbrevs(Dwarf *d, ulong off, DwarfAbbrev **aa) { - int nattr, nabbrev; - DwarfAbbrev *abbrev; - DwarfAttr *attr; + int nattr, nabbrev; + DwarfAbbrev *abbrev; + DwarfAttr *attr; - if(d->acache.off == off && d->acache.na){ - *aa = d->acache.a; - return d->acache.na; - } + if(d->acache.off == off && d->acache.na){ + *aa = d->acache.a; + return d->acache.na; + } - /* two passes - once to count, then allocate, then a second to copy */ - if(parseabbrevs(d, off, nil, nil, &nabbrev, &nattr) < 0) { - return -1; - } + /* two passes - once to count, then allocate, then a second to copy */ + if(parseabbrevs(d, off, nil, nil, &nabbrev, &nattr) < 0) { + return -1; + } - abbrev = malloc(nabbrev*sizeof(DwarfAbbrev) + nattr*sizeof(DwarfAttr)); - attr = (DwarfAttr*)(abbrev+nabbrev); + abbrev = malloc(nabbrev*sizeof(DwarfAbbrev) + nattr*sizeof(DwarfAttr)); + attr = (DwarfAttr*)(abbrev+nabbrev); - if(parseabbrevs(d, off, abbrev, attr, nil, nil) < 0){ - free(abbrev); - return -1; - } + if(parseabbrevs(d, off, abbrev, attr, nil, nil) < 0){ + free(abbrev); + return -1; + } - free(d->acache.a); - d->acache.a = abbrev; - d->acache.na = nabbrev; - d->acache.off = off; + free(d->acache.a); + d->acache.a = abbrev; + d->acache.na = nabbrev; + d->acache.off = off; - *aa = abbrev; - return nabbrev; + *aa = abbrev; + return nabbrev; } static int parseabbrevs(Dwarf *d, ulong off, DwarfAbbrev *abbrev, DwarfAttr *attr, int *pnabbrev, int *pnattr) { - int i, nabbrev, nattr, haskids; - ulong num, tag, name, form; - DwarfBuf b; + int i, nabbrev, nattr, haskids; + ulong num, tag, name, form; + DwarfBuf b; - if(off >= d->abbrev.len){ - werrstr("bad abbrev section offset 0x%lux >= 0x%lux", off, d->abbrev.len); - return -1; - } + if(off >= d->abbrev.len){ + werrstr("bad abbrev section offset 0x%lux >= 0x%lux\n", off, d->abbrev.len); + return -1; + } - memset(&b, 0, sizeof b); - b.p = d->abbrev.data + off; - b.ep = d->abbrev.data + d->abbrev.len; + memset(&b, 0, sizeof b); + b.p = d->abbrev.data + off; + b.ep = d->abbrev.data + d->abbrev.len; - nabbrev = 0; - nattr = 0; - for(;;){ - if(b.p == nil){ - werrstr("malformed abbrev data"); - return -1; - } - num = dwarfget128(&b); - if(num == 0) - break; - tag = dwarfget128(&b); - DPRINT("num %d tag %x @ %x", num, tag, b.p - d->abbrev.data); - haskids = dwarfget1(&b); - for(i=0;; i++){ - name = dwarfget128(&b); - form = dwarfget128(&b); - assert(form < 0x3000); - if(name == 0 && form == 0) - break; - if(attr){ - attr[i].name = name; - attr[i].form = form; - } - } - if(abbrev){ - abbrev->num = num; - abbrev->tag = tag; - abbrev->haskids = haskids; - abbrev->attr = attr; - abbrev->nattr = i; - abbrev++; - attr += i; - } - nabbrev++; - nattr += i; - } - if(pnabbrev) - *pnabbrev = nabbrev; - if(pnattr) - *pnattr = nattr; - return 0; + nabbrev = 0; + nattr = 0; + for(;;){ + if(b.p == nil){ + werrstr("malformed abbrev data"); + return -1; + } + num = dwarfget128(&b); + if(num == 0) + break; + tag = dwarfget128(&b); + haskids = dwarfget1(&b); + for(i=0;; i++){ + name = dwarfget128(&b); + form = dwarfget128(&b); + if(name == 0 && form == 0) + break; + if(attr){ + attr[i].name = name; + attr[i].form = form; + } + } + if(abbrev){ + abbrev->num = num; + abbrev->tag = tag; + abbrev->haskids = haskids; + abbrev->attr = attr; + abbrev->nattr = i; + abbrev++; + attr += i; + } + nabbrev++; + nattr += i; + } + if(pnabbrev) + *pnabbrev = nabbrev; + if(pnattr) + *pnattr = nattr; + return 0; } static DwarfAbbrev* findabbrev(DwarfAbbrev *a, int na, ulong num) { - int i; + int i; - for(i=0; iaranges.data; - b.ep = b.p + d->aranges.len; + memset(&b, 0, sizeof b); + b.d = d; + b.p = d->aranges.data; + b.ep = b.p + d->aranges.len; - while(b.p < b.ep){ - start = b.p; - len = dwarfget4(&b); - if (!len) { b.ep = b.p - 4; return -1; } - if((id = dwarfget2(&b)) != 2){ - if(b.p == nil){ - underflow: - werrstr("buffer underflow reading address ranges header"); - }else - werrstr("bad dwarf version 0x%x in address ranges header", id); - return -1; - } - off = dwarfget4(&b); - b.addrsize = dwarfget1(&b); - if(d->addrsize == 0) - d->addrsize = b.addrsize; - segsize = dwarfget1(&b); - USED(segsize); /* what am i supposed to do with this? */ - if(b.p == nil) - goto underflow; - if((i = (b.p-start) % (2*b.addrsize)) != 0) - b.p += 2*b.addrsize - i; - end = start+4+len; - while(b.p!=nil && b.paddrsize == 0) + d->addrsize = b.addrsize; + segsize = dwarfget1(&b); + USED(segsize); /* what am i supposed to do with this? */ + if(b.p == nil) + goto underflow; + if((i = (b.p-start) % (2*b.addrsize)) != 0) + b.p += 2*b.addrsize - i; + end = start+4+len; + while(b.p!=nil && b.p -#include "pe.h" #include "dwarf.h" -#define trace 1 +#define trace 0 typedef struct State State; struct State @@ -72,7 +71,7 @@ dwarfunwind(Dwarf *d, ulong pc, DwarfExpr *cfa, DwarfExpr *ra, DwarfExpr *r, int memset(r, 0, nr*sizeof(r[0])); for(i=0; iiquantum = dwarfget128(&b); @@ -165,7 +163,6 @@ findfde(Dwarf *d, ulong pc, State *s, DwarfBuf *fde) }else{ /* FDE */ base = dwarfgetaddr(&b); size = dwarfgetaddr(&b); - if (trace) werrstr("FDE: base %x-%x (want pc %x)", base, base+size, pc); fde->p = b.p; fde->ep = next; s->loc = base; @@ -174,7 +171,7 @@ findfde(Dwarf *d, ulong pc, State *s, DwarfBuf *fde) return 0; } } - werrstr("cannot find call frame information for pc 0x%lx", pc); + werrstr("cannot find call frame information for pc 0x%lux", pc); return -1; } @@ -183,7 +180,7 @@ static int checkreg(State *s, long r) { if(r < 0 || r >= s->nr){ - werrstr("bad register number 0x%lx", r); + werrstr("bad register number 0x%lux", r); return -1; } return 0; @@ -200,21 +197,20 @@ dexec(DwarfBuf *b, State *s, int locstop) if(b->p == b->ep){ if(s->initr) s->loc = s->endloc; - werrstr("end dexec"); return 0; } c = dwarfget1(b); if(b->p == nil){ werrstr("ran out of instructions during cfa program"); - if(trace) werrstr("%r"); + if(trace) werrstr("%r\n"); return -1; } - if(trace) werrstr("+ loc=0x%x op 0x%x ", s->loc, c); + if(trace) werrstr("+ loc=0x%lux op 0x%ux ", s->loc, c); switch(c>>6){ case 1: /* advance location */ arg1 = c&0x3F; advance: - if(trace) werrstr("loc += %ld", arg1*s->iquantum); + if(trace) werrstr("loc += %ld\n", arg1*s->iquantum); s->loc += arg1 * s->iquantum; if(locstop) return 0; @@ -224,7 +220,7 @@ dexec(DwarfBuf *b, State *s, int locstop) arg1 = c&0x3F; arg2 = dwarfget128(b); offset: - if(trace) werrstr("r%ld += %ld", arg1, arg2*s->dquantum); + if(trace) werrstr("r%ld += %ld\n", arg1, arg2*s->dquantum); if(checkreg(s, arg1) < 0) return -1; s->r[arg1].type = RuleCfaOffset; @@ -234,7 +230,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 3: /* restore initial setting */ arg1 = c&0x3F; restore: - if(trace) werrstr("r%ld = init", arg1); + if(trace) werrstr("r%ld = init\n", arg1); if(checkreg(s, arg1) < 0) return -1; s->r[arg1] = s->initr[arg1]; @@ -243,12 +239,12 @@ dexec(DwarfBuf *b, State *s, int locstop) switch(c){ case 0: /* nop */ - if(trace) werrstr("nop"); + if(trace) werrstr("nop\n"); continue; case 0x01: /* set location */ s->loc = dwarfgetaddr(b); - if(trace) werrstr("loc = 0x%lx", s->loc); + if(trace) werrstr("loc = 0x%lux\n", s->loc); if(locstop) return 0; continue; @@ -276,7 +272,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 0x07: /* undefined */ arg1 = dwarfget128(b); - if(trace) werrstr("r%ld = undef", arg1); + if(trace) werrstr("r%ld = undef\n", arg1); if(checkreg(s, arg1) < 0) return -1; s->r[arg1].type = RuleUndef; @@ -284,7 +280,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 0x08: /* same value */ arg1 = dwarfget128(b); - if(trace) werrstr("r%ld = same", arg1); + if(trace) werrstr("r%ld = same\n", arg1); if(checkreg(s, arg1) < 0) return -1; s->r[arg1].type = RuleSame; @@ -293,7 +289,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 0x09: /* register */ arg1 = dwarfget128(b); arg2 = dwarfget128(b); - if(trace) werrstr("r%ld = r%ld", arg1, arg2); + if(trace) werrstr("r%ld = r%ld\n", arg1, arg2); if(checkreg(s, arg1) < 0 || checkreg(s, arg2) < 0) return -1; s->r[arg1].type = RuleRegister; @@ -302,7 +298,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 0x0A: /* remember state */ e = malloc(s->nr*sizeof(e[0])); - if(trace) werrstr("push"); + if(trace) werrstr("push\n"); if(e == nil) return -1; void *newstack = malloc(s->nstack*sizeof(s->stack[0])); @@ -323,7 +319,7 @@ dexec(DwarfBuf *b, State *s, int locstop) continue; case 0x0B: /* restore state */ - if(trace) werrstr("pop"); + if(trace) werrstr("pop\n"); if(s->nstack == 0){ werrstr("restore state underflow"); return -1; @@ -338,7 +334,7 @@ dexec(DwarfBuf *b, State *s, int locstop) arg1 = dwarfget128(b); arg2 = dwarfget128(b); defcfa: - if(trace) werrstr("cfa %ld(r%ld)", arg2, arg1); + if(trace) werrstr("cfa %ld(r%ld)\n", arg2, arg1); if(checkreg(s, arg1) < 0) return -1; s->cfa->type = RuleRegOff; @@ -348,7 +344,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 0x0D: /* def cfa register */ arg1 = dwarfget128(b); - if(trace) werrstr("cfa reg r%ld", arg1); + if(trace) werrstr("cfa reg r%ld\n", arg1); if(s->cfa->type != RuleRegOff){ werrstr("change CFA register but CFA not in register+offset form"); return -1; @@ -361,7 +357,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 0x0E: /* def cfa offset */ arg1 = dwarfget128(b); cfaoffset: - if(trace) werrstr("cfa off %ld", arg1); + if(trace) werrstr("cfa off %ld\n", arg1); if(s->cfa->type != RuleRegOff){ werrstr("change CFA offset but CFA not in register+offset form"); return -1; @@ -370,7 +366,7 @@ dexec(DwarfBuf *b, State *s, int locstop) continue; case 0x0F: /* def cfa expression */ - if(trace) werrstr("cfa expr"); + if(trace) werrstr("cfa expr\n"); s->cfa->type = RuleLocation; s->cfa->loc.len = dwarfget128(b); s->cfa->loc.data = dwarfgetnref(b, s->cfa->loc.len); @@ -378,7 +374,7 @@ dexec(DwarfBuf *b, State *s, int locstop) case 0x10: /* def reg expression */ arg1 = dwarfget128(b); - if(trace) werrstr("reg expr r%ld", arg1); + if(trace) werrstr("reg expr r%ld\n", arg1); if(checkreg(s, arg1) < 0) return -1; s->r[arg1].type = RuleLocation; @@ -401,98 +397,11 @@ dexec(DwarfBuf *b, State *s, int locstop) goto cfaoffset; default: /* unknown */ - werrstr("unknown opcode 0x%x in cfa program", c); + werrstr("unknown opcode 0x%ux in cfa program", c); return -1; } } /* not reached */ } -int dwarfcomputecfa(Dwarf *d, DwarfExpr *cfa, PROSSYM_REGISTERS registers, ulong *cfaLocation) -{ - switch (cfa->type) { - case RuleRegOff: - *cfaLocation = registers->Registers[cfa->reg] + cfa->offset; - werrstr("cfa reg %d (%x) offset %x = %x", cfa->reg, (ulong)registers->Registers[cfa->reg], cfa->offset, cfaLocation); - break; - default: - werrstr("cfa->type %x", cfa->type); - return -1; - } - return 0; -} - -int dwarfregunwind(Dwarf *d, ulong pc, ulong fde, DwarfExpr *cfa, PROSSYM_REGISTERS registers) -{ - int i; - State s = { }; - DwarfExpr initr[sizeof(registers->Registers) / sizeof(registers->Registers[0])] = { }; - DwarfExpr r[sizeof(registers->Registers) / sizeof(registers->Registers[0])] = { }; - DwarfExpr ra; - - int nr = s.nr = sizeof(registers->Registers) / sizeof(registers->Registers[0]); - s.initr = initr; - s.r = r; - for (i = 0; i < sizeof(r) / sizeof(r[0]); i++) { - r[i].type = RuleRegister; - r[i].offset = registers->Registers[i]; - r[i].reg = i; - } - - int res = dwarfunwind(d, pc, cfa, &ra, initr, sizeof(initr) / sizeof(initr[0])); - if (res == -1) return -1; - - ulong cfaLocation; - - if (dwarfcomputecfa(d, cfa, registers, &cfaLocation) == -1) - return -1; - - for (i = 0; i < nr; i++) { - switch (r[i].type) { - case RuleUndef: - werrstr("Undefined register slot %d", i); - assert(FALSE); - break; - case RuleSame: - break; - case RuleRegister: - registers->Registers[i] = registers->Registers[r[i].reg]; - break; - case RuleRegOff: { - BOOLEAN success = - RosSymCallbacks.MemGetProc - (d->pe->fd, - ®isters->Registers[i], - r[i].offset + registers->Registers[r[i].reg], - d->addrsize); - if (!success) return -1; - } break; - case RuleCfaOffset: - { - BOOLEAN success = - RosSymCallbacks.MemGetProc - (d->pe->fd, - ®isters->Registers[i], - r[i].offset + cfaLocation, - d->addrsize); - werrstr("reg[%d] = %x: cfa offset (cfa %x, offset %x) -> @%x", i, (ulong)registers->Registers[i], cfaLocation, initr[i].offset, r[i].offset + cfaLocation); - if (!success) return -1; - } break; - default: - werrstr("We don't yet support cfa rule %d in slot %d", r[i].type, i); - assert(FALSE); - break; - } - } - - ulong cfaSpace[4]; - for (i = 0; i < sizeof(cfaSpace) / sizeof(cfaSpace[0]); i++) { - RosSymCallbacks.MemGetProc - (d->pe->fd, &cfaSpace[i], cfaLocation + (i * 4), d->addrsize); - } - werrstr("CFA(%x) [%08x, %08x, %08x, %08x]", - cfaLocation, cfaSpace[0], cfaSpace[1], cfaSpace[2], cfaSpace[3]); - - return 0; -} diff --git a/lib/rossym/dwarfget.c b/lib/rossym/dwarfget.c index 7787163a21b..d32177cd1db 100644 --- a/lib/rossym/dwarfget.c +++ b/lib/rossym/dwarfget.c @@ -139,7 +139,7 @@ dwarfgetaddr(DwarfBuf *b) return dwarfget8(b); default: if(++nbad == 1) - werrstr("dwarf: unexpected address size %lud in dwarfgetaddr", b->addrsize); + werrstr("dwarf: unexpected address size %lud in dwarfgetaddr\n", b->addrsize); b->p = nil; return 0; } @@ -190,7 +190,7 @@ dwarfget128(DwarfBuf *b) while(b->pep && *b->p&0x80) b->p++; if(++nbad == 1) - werrstr("dwarf: overflow during parsing of uleb128 integer"); + werrstr("dwarf: overflow during parsing of uleb128 integer\n"); return c; } diff --git a/lib/rossym/dwarfinfo.c b/lib/rossym/dwarfinfo.c index 397702f1180..cc25499483a 100644 --- a/lib/rossym/dwarfinfo.c +++ b/lib/rossym/dwarfinfo.c @@ -13,971 +13,649 @@ #include #include "dwarf.h" -#include "pe.h" #include enum { - DwarfAttrSibling = 0x01, - DwarfAttrLocation = 0x02, - DwarfAttrName = 0x03, - DwarfAttrOrdering = 0x09, - DwarfAttrByteSize = 0x0B, - DwarfAttrBitOffset = 0x0C, - DwarfAttrBitSize = 0x0D, - DwarfAttrStmtList = 0x10, - DwarfAttrLowpc = 0x11, - DwarfAttrHighpc = 0x12, - DwarfAttrLanguage = 0x13, - DwarfAttrDiscr = 0x15, - DwarfAttrDiscrValue = 0x16, - DwarfAttrVisibility = 0x17, - DwarfAttrImport = 0x18, - DwarfAttrStringLength = 0x19, - DwarfAttrCommonRef = 0x1A, - DwarfAttrCompDir = 0x1B, - DwarfAttrConstValue = 0x1C, - DwarfAttrContainingType = 0x1D, - DwarfAttrDefaultValue = 0x1E, - DwarfAttrInline = 0x20, - DwarfAttrIsOptional = 0x21, - DwarfAttrLowerBound = 0x22, - DwarfAttrProducer = 0x25, - DwarfAttrPrototyped = 0x27, - DwarfAttrReturnAddr = 0x2A, - DwarfAttrStartScope = 0x2C, - DwarfAttrStrideSize = 0x2E, - DwarfAttrUpperBound = 0x2F, - DwarfAttrAbstractOrigin = 0x31, - DwarfAttrAccessibility = 0x32, - DwarfAttrAddrClass = 0x33, - DwarfAttrArtificial = 0x34, - DwarfAttrBaseTypes = 0x35, - DwarfAttrCalling = 0x36, - DwarfAttrCount = 0x37, - DwarfAttrDataMemberLoc = 0x38, - DwarfAttrDeclColumn = 0x39, - DwarfAttrDeclFile = 0x3A, - DwarfAttrDeclLine = 0x3B, - DwarfAttrDeclaration = 0x3C, - DwarfAttrDiscrList = 0x3D, - DwarfAttrEncoding = 0x3E, - DwarfAttrExternal = 0x3F, - DwarfAttrFrameBase = 0x40, - DwarfAttrFriend = 0x41, - DwarfAttrIdentifierCase = 0x42, - DwarfAttrMacroInfo = 0x43, - DwarfAttrNamelistItem = 0x44, - DwarfAttrPriority = 0x45, - DwarfAttrSegment = 0x46, - DwarfAttrSpecification = 0x47, - DwarfAttrStaticLink = 0x48, - DwarfAttrType = 0x49, - DwarfAttrUseLocation = 0x4A, - DwarfAttrVarParam = 0x4B, - DwarfAttrVirtuality = 0x4C, - DwarfAttrVtableElemLoc = 0x4D, - DwarfAttrAllocated = 0x4E, - DwarfAttrAssociated = 0x4F, - DwarfAttrDataLocation = 0x50, - DwarfAttrStride = 0x51, - DwarfAttrEntrypc = 0x52, - DwarfAttrUseUTF8 = 0x53, - DwarfAttrExtension = 0x54, - DwarfAttrRanges = 0x55, - DwarfAttrTrampoline = 0x56, - DwarfAttrCallColumn = 0x57, - DwarfAttrCallFile = 0x58, - DwarfAttrCallLine = 0x59, - DwarfAttrDescription = 0x5A, - DwarfAttrMax, + DwarfAttrSibling = 0x01, + DwarfAttrLocation = 0x02, + DwarfAttrName = 0x03, + DwarfAttrOrdering = 0x09, + DwarfAttrByteSize = 0x0B, + DwarfAttrBitOffset = 0x0C, + DwarfAttrBitSize = 0x0D, + DwarfAttrStmtList = 0x10, + DwarfAttrLowpc = 0x11, + DwarfAttrHighpc = 0x12, + DwarfAttrLanguage = 0x13, + DwarfAttrDiscr = 0x15, + DwarfAttrDiscrValue = 0x16, + DwarfAttrVisibility = 0x17, + DwarfAttrImport = 0x18, + DwarfAttrStringLength = 0x19, + DwarfAttrCommonRef = 0x1A, + DwarfAttrCompDir = 0x1B, + DwarfAttrConstValue = 0x1C, + DwarfAttrContainingType = 0x1D, + DwarfAttrDefaultValue = 0x1E, + DwarfAttrInline = 0x20, + DwarfAttrIsOptional = 0x21, + DwarfAttrLowerBound = 0x22, + DwarfAttrProducer = 0x25, + DwarfAttrPrototyped = 0x27, + DwarfAttrReturnAddr = 0x2A, + DwarfAttrStartScope = 0x2C, + DwarfAttrStrideSize = 0x2E, + DwarfAttrUpperBound = 0x2F, + DwarfAttrAbstractOrigin = 0x31, + DwarfAttrAccessibility = 0x32, + DwarfAttrAddrClass = 0x33, + DwarfAttrArtificial = 0x34, + DwarfAttrBaseTypes = 0x35, + DwarfAttrCalling = 0x36, + DwarfAttrCount = 0x37, + DwarfAttrDataMemberLoc = 0x38, + DwarfAttrDeclColumn = 0x39, + DwarfAttrDeclFile = 0x3A, + DwarfAttrDeclLine = 0x3B, + DwarfAttrDeclaration = 0x3C, + DwarfAttrDiscrList = 0x3D, + DwarfAttrEncoding = 0x3E, + DwarfAttrExternal = 0x3F, + DwarfAttrFrameBase = 0x40, + DwarfAttrFriend = 0x41, + DwarfAttrIdentifierCase = 0x42, + DwarfAttrMacroInfo = 0x43, + DwarfAttrNamelistItem = 0x44, + DwarfAttrPriority = 0x45, + DwarfAttrSegment = 0x46, + DwarfAttrSpecification = 0x47, + DwarfAttrStaticLink = 0x48, + DwarfAttrType = 0x49, + DwarfAttrUseLocation = 0x4A, + DwarfAttrVarParam = 0x4B, + DwarfAttrVirtuality = 0x4C, + DwarfAttrVtableElemLoc = 0x4D, + DwarfAttrAllocated = 0x4E, + DwarfAttrAssociated = 0x4F, + DwarfAttrDataLocation = 0x50, + DwarfAttrStride = 0x51, + DwarfAttrEntrypc = 0x52, + DwarfAttrUseUTF8 = 0x53, + DwarfAttrExtension = 0x54, + DwarfAttrRanges = 0x55, + DwarfAttrTrampoline = 0x56, + DwarfAttrCallColumn = 0x57, + DwarfAttrCallFile = 0x58, + DwarfAttrCallLine = 0x59, + DwarfAttrDescription = 0x5A, + DwarfAttrMax, - FormAddr = 0x01, - FormDwarfBlock2 = 0x03, - FormDwarfBlock4 = 0x04, - FormData2 = 0x05, - FormData4 = 0x06, - FormData8 = 0x07, - FormString = 0x08, - FormDwarfBlock = 0x09, - FormDwarfBlock1 = 0x0A, - FormData1 = 0x0B, - FormFlag = 0x0C, - FormSdata = 0x0D, - FormStrp = 0x0E, - FormUdata = 0x0F, - FormRefAddr = 0x10, - FormRef1 = 0x11, - FormRef2 = 0x12, - FormRef4 = 0x13, - FormRef8 = 0x14, - FormRefUdata = 0x15, - FormIndirect = 0x16 + FormAddr = 0x01, + FormDwarfBlock2 = 0x03, + FormDwarfBlock4 = 0x04, + FormData2 = 0x05, + FormData4 = 0x06, + FormData8 = 0x07, + FormString = 0x08, + FormDwarfBlock = 0x09, + FormDwarfBlock1 = 0x0A, + FormData1 = 0x0B, + FormFlag = 0x0C, + FormSdata = 0x0D, + FormStrp = 0x0E, + FormUdata = 0x0F, + FormRefAddr = 0x10, + FormRef1 = 0x11, + FormRef2 = 0x12, + FormRef4 = 0x13, + FormRef8 = 0x14, + FormRefUdata = 0x15, + FormIndirect = 0x16 }; -static int parseattrs(Dwarf *d, DwarfBuf*, ulong, ulong, DwarfAbbrev*, DwarfAttrs*); +static int parseattrs(DwarfBuf*, ulong, DwarfAbbrev*, DwarfAttrs*); static int getulong(DwarfBuf*, int, ulong, ulong*, int*); static int getuchar(DwarfBuf*, int, uchar*); -static int getstring(Dwarf *d, DwarfBuf*, int, char**); +static int getstring(DwarfBuf*, int, char**); static int getblock(DwarfBuf*, int, DwarfBlock*); -static int skipform(Dwarf *d, DwarfBuf*, int); +static int skipform(DwarfBuf*, int); +static int constblock(Dwarf*, DwarfBlock*, ulong*); int dwarflookupnameinunit(Dwarf *d, ulong unit, char *name, DwarfSym *s) { - DwarfSym compunit = { }; - if(dwarfenumunit(d, unit, &compunit) < 0) - return -1; - while(dwarfnextsymat(d, &compunit, s) == 1) - if(s->attrs.name && strcmp(s->attrs.name, name) == 0) - return 0; - werrstr("symbol '%s' not found", name); - return -1; + if(dwarfenumunit(d, unit, s) < 0) + return -1; + + dwarfnextsymat(d, s, 0); /* s is now the CompileUnit */ + while(dwarfnextsymat(d, s, 1) == 1) + if(s->attrs.name && strcmp(s->attrs.name, name) == 0) + return 0; + werrstr("symbol '%s' not found", name); + return -1; } + int dwarflookupsubname(Dwarf *d, DwarfSym *parent, char *name, DwarfSym *s) { - *s = *parent; - while(dwarfnextsymat(d, parent, s)) - if(s->attrs.name && strcmp(s->attrs.name, name) == 0) - return 0; - werrstr("symbol '%s' not found", name); - return -1; -} - -int -dwarflookupchildtag(Dwarf *d, DwarfSym *parent, ulong tag, DwarfSym *s) -{ - int rsym = dwarfnextsymat(d, parent, s); - while (rsym == 0 && s->attrs.tag != tag) { - if (s->attrs.haskids) { - DwarfSym p = *s; - int csym = dwarflookupchildtag(d, &p, tag, s); - if (csym == 0) { - return csym; - } - } - rsym = dwarfnextsym(d, s); - } - return rsym; + *s = *parent; + while(dwarfnextsymat(d, s, parent->depth+1)) + if(s->attrs.name && strcmp(s->attrs.name, name) == 0) + return 0; + werrstr("symbol '%s' not found", name); + return -1; } int dwarflookuptag(Dwarf *d, ulong unit, ulong tag, DwarfSym *s) { - DwarfSym compunit = { }; - if (dwarfenumunit(d, unit, &compunit) < 0) { - return -1; - } - do { - if (compunit.attrs.tag == tag) { - *s = compunit; - return 0; - } - if (dwarflookupchildtag(d, &compunit, tag, s) == 0) - return 0; - } while(dwarfnextsym(d, &compunit) == 0); - werrstr("symbol with tag 0x%lux not found", tag); - return -1; + if(dwarfenumunit(d, unit, s) < 0) { + return -1; + } + + dwarfnextsymat(d, s, 0); /* s is now the CompileUnit */ + if(s->attrs.tag == tag) { + return 0; + } + while(dwarfnextsymat(d, s, 1) == 1) + if(s->attrs.tag == tag) { + return 0; + } + werrstr("symbol with tag 0x%lux not found", tag); + return -1; } int dwarfseeksym(Dwarf *d, ulong unit, ulong off, DwarfSym *s) { - DwarfSym compunit = { }; - if(dwarfenumunit(d, unit, &compunit) < 0) - return -1; - s->b.p = d->info.data + unit + off; - if(dwarfnextsymat(d, &compunit, s) == -1) - return -1; - werrstr("dwarfseeksym: unit %x off %x, tag %x", unit, off, s->attrs.tag); - return 0; + if(dwarfenumunit(d, unit, s) < 0) + return -1; + s->b.p = d->info.data + unit + off; + if(dwarfnextsymat(d, s, 0) != 1) + return -1; + return 0; } int dwarflookupfn(Dwarf *d, ulong unit, ulong pc, DwarfSym *s) { - DwarfSym compunit = { }; - if(dwarfenumunit(d, unit, &compunit) < 0) - return -1; - while(dwarfnextsymat(d, &compunit, s) == 0){ - if(s->attrs.tag != TagSubprogram) - continue; - if(s->attrs.lowpc <= pc && pc < s->attrs.highpc) - return 0; - } - werrstr("fn containing pc 0x%lux not found", pc); - return -1; + if(dwarfenumunit(d, unit, s) < 0) + return -1; + + if(dwarfnextsymat(d, s, 0) != 1) + return -1; + /* s is now the CompileUnit */ + + while(dwarfnextsymat(d, s, 1) == 1){ + if(s->attrs.tag != TagSubprogram) + continue; + if(s->attrs.lowpc <= pc && pc < s->attrs.highpc) + return 0; + } + werrstr("fn containing pc 0x%lux not found", pc); + return -1; } int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s) { - int i; - ulong aoff, len; + int i; + ulong aoff, len; - if(unit >= d->info.len){ - werrstr("dwarf unit address 0x%x >= 0x%x out of range", unit, d->info.len); - return -1; - } - memset(s, 0, sizeof *s); - memset(&s->b, 0, sizeof s->b); + if(unit >= d->info.len){ + werrstr("dwarf unit address 0x%x >= 0x%x out of range", unit, d->info.len); + return -1; + } + memset(s, 0, sizeof *s); + memset(&s->b, 0, sizeof s->b); - s->b.d = d; - s->b.p = d->info.data + unit; - s->b.ep = d->info.data + d->info.len; - len = dwarfget4(&s->b); + s->b.d = d; + s->b.p = d->info.data + unit; + s->b.ep = d->info.data + d->info.len; + len = dwarfget4(&s->b); + s->nextunit = unit + 4 + len; + + if(s->b.ep - s->b.p < len){ + badheader: + werrstr("bad dwarf unit header at unit 0x%lux", unit); + return -1; + } + s->b.ep = s->b.p+len; + if((i=dwarfget2(&s->b)) != 2) + goto badheader; + aoff = dwarfget4(&s->b); + s->b.addrsize = dwarfget1(&s->b); + if(d->addrsize == 0) + d->addrsize = s->b.addrsize; + if(s->b.p == nil) + goto badheader; + + s->aoff = aoff; s->unit = unit; - s->nextunit = unit + 4 + len; - s->b.ep = d->info.data + s->nextunit; + s->depth = 0; + return 0; +} - if(s->b.ep - s->b.p < len){ - badheader: - werrstr("bad dwarf unit header at unit 0x%lux end %x start %x len %x", unit, s->b.ep - d->info.data, s->b.p - d->info.data, len); - return -1; - } - s->b.ep = s->b.p+len; - if((i=dwarfget2(&s->b)) != 2) - goto badheader; - aoff = dwarfget4(&s->b); - s->b.addrsize = dwarfget1(&s->b); - if(d->addrsize == 0) - d->addrsize = s->b.addrsize; - if(s->b.p == nil) - goto badheader; - - s->aoff = aoff; - - return dwarfnextsym(d, s); +int +dwarfenum(Dwarf *d, DwarfSym *s) +{ + if(dwarfenumunit(d, 0, s) < 0) + return -1; + s->allunits = 1; + return 0; } int dwarfnextsym(Dwarf *d, DwarfSym *s) { - ulong num; - DwarfAbbrev *a; + ulong num; + DwarfAbbrev *a; - num = dwarfget128(&s->b); - s->num = num; - if(num == 0){ - return -1; - } + if(s->attrs.haskids) + s->depth++; +top: + if(s->b.p >= s->b.ep){ + if(s->allunits && s->nextunit < d->info.len){ + if(dwarfenumunit(d, s->nextunit, s) < 0) { + return -1; + } + s->allunits = 1; + goto top; + } + return 0; + } - a = dwarfgetabbrev(d, s->aoff, num); - if(a == nil){ - werrstr("getabbrev %ud %ud for %ud,%ud", s->aoff, num, s->unit); - return -1; - } + s->uoff = s->b.p - (d->info.data+s->unit); + num = dwarfget128(&s->b); + if(num == 0){ + if(s->depth == 0) { + return 0; + } + if(s->depth > 0) + s->depth--; + goto top; + } - if(parseattrs(d, &s->b, s->attrs.tag, s->unit, a, &s->attrs) < 0) { - return -1; - } - - if (s->attrs.haskids) { - DwarfSym childSkip = { }; - s->childoff = s->b.p - d->info.data; - int r = dwarfnextsymat(d, s, &childSkip); - while (r == 0) { - r = dwarfnextsym(d, &childSkip); - } - s->b = childSkip.b; - } else { - s->childoff = 0; - } - return 0; + a = dwarfgetabbrev(d, s->aoff, num); + if(a == nil){ + werrstr("getabbrev %ud %ud for %ud,%ud: %r\n", s->aoff, num, s->unit, s->uoff); + return -1; + } + if(parseattrs(&s->b, s->unit, a, &s->attrs) < 0) { + return -1; + } + return 1; } int -dwarfnextsymat(Dwarf *d, DwarfSym *parent, DwarfSym *child) +dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth) { - uint sib; + int r; + DwarfSym t; + uint sib; - if (!parent->attrs.haskids || !parent->childoff) - return -1; + if(s->depth == depth && s->attrs.have.sibling){ + sib = s->attrs.sibling; + if(sib < d->info.len && d->info.data+sib >= s->b.p) + s->b.p = d->info.data+sib; + s->attrs.haskids = 0; + } - child->unit = parent->unit; - child->aoff = parent->aoff; - child->depth = parent->depth + 1; - if(child->attrs.have.sibling){ - sib = child->attrs.sibling; - if(sib < d->info.len && d->info.data+sib > child->b.p) - child->b.p = d->info.data+sib; - else if (sib >= d->info.len) { - werrstr("sibling reported as out of bounds %d vs %d", sib, d->info.len); - return -1; - } else if (d->info.data+sib+parent->unit < child->b.p) { - werrstr("subsequent sibling is listed before prev %d vs %d", sib+parent->unit, child->b.p - d->info.data); - return -1; - } - } - - // Uninitialized - if (!child->b.d) { - child->b = parent->b; - child->b.p = parent->childoff + parent->b.d->info.data; - } - - return dwarfnextsym(d, child); + /* + * The funny game with t and s make sure that + * if we get to the end of a run of a particular + * depth, we leave s so that a call to nextsymat with depth-1 + * will actually produce the desired guy. We could change + * the interface to dwarfnextsym instead, but I'm scared + * to touch it. + */ + t = *s; + for(;;){ + if((r = dwarfnextsym(d, &t)) != 1) { + return r; + } + if(t.depth < depth){ + /* went too far - nothing to see */ + return 0; + } + *s = t; + if(t.depth == depth) { + return 1; + } + } } typedef struct Parse Parse; struct Parse { - int name; - int off; - int haveoff; - int type; + int name; + int off; + int haveoff; + int type; }; #define OFFSET(x) offsetof(DwarfAttrs, x), offsetof(DwarfAttrs, have.x) static Parse plist[] = { /* Font Tab 4 */ - { DwarfAttrAbstractOrigin, OFFSET(abstractorigin), TReference }, - { DwarfAttrAccessibility, OFFSET(accessibility), TConstant }, - { DwarfAttrAddrClass, OFFSET(addrclass), TConstant }, - { DwarfAttrArtificial, OFFSET(isartificial), TFlag }, - { DwarfAttrBaseTypes, OFFSET(basetypes), TReference }, - { DwarfAttrBitOffset, OFFSET(bitoffset), TConstant }, - { DwarfAttrBitSize, OFFSET(bitsize), TConstant }, - { DwarfAttrByteSize, OFFSET(bytesize), TConstant }, - { DwarfAttrCalling, OFFSET(calling), TConstant }, - { DwarfAttrCommonRef, OFFSET(commonref), TReference }, - { DwarfAttrCompDir, OFFSET(compdir), TString }, - { DwarfAttrConstValue, OFFSET(constvalue), TString|TConstant|TBlock }, - { DwarfAttrContainingType, OFFSET(containingtype), TReference }, - { DwarfAttrCount, OFFSET(count), TConstant|TReference }, - { DwarfAttrDataMemberLoc, OFFSET(datamemberloc), TBlock|TConstant|TReference }, - { DwarfAttrDeclColumn, OFFSET(declcolumn), TConstant }, - { DwarfAttrDeclFile, OFFSET(declfile), TConstant }, - { DwarfAttrDeclLine, OFFSET(declline), TConstant }, - { DwarfAttrDeclaration, OFFSET(isdeclaration), TFlag }, - { DwarfAttrDefaultValue, OFFSET(defaultvalue), TReference }, - { DwarfAttrDiscr, OFFSET(discr), TReference }, - { DwarfAttrDiscrList, OFFSET(discrlist), TBlock }, - { DwarfAttrDiscrValue, OFFSET(discrvalue), TConstant }, - { DwarfAttrEncoding, OFFSET(encoding), TConstant }, - { DwarfAttrExternal, OFFSET(isexternal), TFlag }, - { DwarfAttrFrameBase, OFFSET(framebase), TBlock|TConstant }, - { DwarfAttrFriend, OFFSET(friend), TReference }, - { DwarfAttrHighpc, OFFSET(highpc), TAddress }, - { DwarfAttrEntrypc, OFFSET(entrypc), TAddress }, - { DwarfAttrIdentifierCase, OFFSET(identifiercase), TConstant }, - { DwarfAttrImport, OFFSET(import), TReference }, - { DwarfAttrInline, OFFSET(inlined), TConstant }, - { DwarfAttrIsOptional, OFFSET(isoptional), TFlag }, - { DwarfAttrLanguage, OFFSET(language), TConstant }, - { DwarfAttrLocation, OFFSET(location), TReference|TBlock }, - { DwarfAttrLowerBound, OFFSET(lowerbound), TConstant|TReference }, - { DwarfAttrLowpc, OFFSET(lowpc), TAddress }, - { DwarfAttrMacroInfo, OFFSET(macroinfo), TConstant }, - { DwarfAttrName, OFFSET(name), TString }, - { DwarfAttrNamelistItem, OFFSET(namelistitem), TBlock }, - { DwarfAttrOrdering, OFFSET(ordering), TConstant }, - { DwarfAttrPriority, OFFSET(priority), TReference }, - { DwarfAttrProducer, OFFSET(producer), TString }, - { DwarfAttrPrototyped, OFFSET(isprototyped), TFlag }, - { DwarfAttrRanges, OFFSET(ranges), TReference }, - { DwarfAttrReturnAddr, OFFSET(returnaddr), TBlock|TConstant }, - { DwarfAttrSegment, OFFSET(segment), TBlock|TConstant }, - { DwarfAttrSibling, OFFSET(sibling), TReference }, - { DwarfAttrSpecification, OFFSET(specification), TReference }, - { DwarfAttrStartScope, OFFSET(startscope), TConstant }, - { DwarfAttrStaticLink, OFFSET(staticlink), TBlock|TConstant }, - { DwarfAttrStmtList, OFFSET(stmtlist), TConstant }, - { DwarfAttrStrideSize, OFFSET(stridesize), TConstant }, - { DwarfAttrStringLength, OFFSET(stringlength), TBlock|TConstant }, - { DwarfAttrType, OFFSET(type), TReference }, - { DwarfAttrUpperBound, OFFSET(upperbound), TConstant|TReference }, - { DwarfAttrUseLocation, OFFSET(uselocation), TBlock|TConstant }, - { DwarfAttrVarParam, OFFSET(isvarparam), TFlag }, - { DwarfAttrVirtuality, OFFSET(virtuality), TConstant }, - { DwarfAttrVisibility, OFFSET(visibility), TConstant }, - { DwarfAttrVtableElemLoc, OFFSET(vtableelemloc), TBlock|TReference }, - { } + { DwarfAttrAbstractOrigin, OFFSET(abstractorigin), TReference }, + { DwarfAttrAccessibility, OFFSET(accessibility), TConstant }, + { DwarfAttrAddrClass, OFFSET(addrclass), TConstant }, + { DwarfAttrArtificial, OFFSET(isartificial), TFlag }, + { DwarfAttrBaseTypes, OFFSET(basetypes), TReference }, + { DwarfAttrBitOffset, OFFSET(bitoffset), TConstant }, + { DwarfAttrBitSize, OFFSET(bitsize), TConstant }, + { DwarfAttrByteSize, OFFSET(bytesize), TConstant }, + { DwarfAttrCalling, OFFSET(calling), TConstant }, + { DwarfAttrCommonRef, OFFSET(commonref), TReference }, + { DwarfAttrCompDir, OFFSET(compdir), TString }, + { DwarfAttrConstValue, OFFSET(constvalue), TString|TConstant|TBlock }, + { DwarfAttrContainingType, OFFSET(containingtype), TReference }, + { DwarfAttrCount, OFFSET(count), TConstant|TReference }, + { DwarfAttrDataMemberLoc, OFFSET(datamemberloc), TBlock|TConstant|TReference }, + { DwarfAttrDeclColumn, OFFSET(declcolumn), TConstant }, + { DwarfAttrDeclFile, OFFSET(declfile), TConstant }, + { DwarfAttrDeclLine, OFFSET(declline), TConstant }, + { DwarfAttrDeclaration, OFFSET(isdeclaration), TFlag }, + { DwarfAttrDefaultValue, OFFSET(defaultvalue), TReference }, + { DwarfAttrDiscr, OFFSET(discr), TReference }, + { DwarfAttrDiscrList, OFFSET(discrlist), TBlock }, + { DwarfAttrDiscrValue, OFFSET(discrvalue), TConstant }, + { DwarfAttrEncoding, OFFSET(encoding), TConstant }, + { DwarfAttrExternal, OFFSET(isexternal), TFlag }, + { DwarfAttrFrameBase, OFFSET(framebase), TBlock|TConstant }, + { DwarfAttrFriend, OFFSET(friend), TReference }, + { DwarfAttrHighpc, OFFSET(highpc), TAddress }, + { DwarfAttrEntrypc, OFFSET(entrypc), TAddress }, + { DwarfAttrIdentifierCase, OFFSET(identifiercase), TConstant }, + { DwarfAttrImport, OFFSET(import), TReference }, + { DwarfAttrInline, OFFSET(inlined), TConstant }, + { DwarfAttrIsOptional, OFFSET(isoptional), TFlag }, + { DwarfAttrLanguage, OFFSET(language), TConstant }, + { DwarfAttrLocation, OFFSET(location), TBlock|TConstant }, + { DwarfAttrLowerBound, OFFSET(lowerbound), TConstant|TReference }, + { DwarfAttrLowpc, OFFSET(lowpc), TAddress }, + { DwarfAttrMacroInfo, OFFSET(macroinfo), TConstant }, + { DwarfAttrName, OFFSET(name), TString }, + { DwarfAttrNamelistItem, OFFSET(namelistitem), TBlock }, + { DwarfAttrOrdering, OFFSET(ordering), TConstant }, + { DwarfAttrPriority, OFFSET(priority), TReference }, + { DwarfAttrProducer, OFFSET(producer), TString }, + { DwarfAttrPrototyped, OFFSET(isprototyped), TFlag }, + { DwarfAttrRanges, OFFSET(ranges), TReference }, + { DwarfAttrReturnAddr, OFFSET(returnaddr), TBlock|TConstant }, + { DwarfAttrSegment, OFFSET(segment), TBlock|TConstant }, + { DwarfAttrSibling, OFFSET(sibling), TReference }, + { DwarfAttrSpecification, OFFSET(specification), TReference }, + { DwarfAttrStartScope, OFFSET(startscope), TConstant }, + { DwarfAttrStaticLink, OFFSET(staticlink), TBlock|TConstant }, + { DwarfAttrStmtList, OFFSET(stmtlist), TConstant }, + { DwarfAttrStrideSize, OFFSET(stridesize), TConstant }, + { DwarfAttrStringLength, OFFSET(stringlength), TBlock|TConstant }, + { DwarfAttrType, OFFSET(type), TReference }, + { DwarfAttrUpperBound, OFFSET(upperbound), TConstant|TReference }, + { DwarfAttrUseLocation, OFFSET(uselocation), TBlock|TConstant }, + { DwarfAttrVarParam, OFFSET(isvarparam), TFlag }, + { DwarfAttrVirtuality, OFFSET(virtuality), TConstant }, + { DwarfAttrVisibility, OFFSET(visibility), TConstant }, + { DwarfAttrVtableElemLoc, OFFSET(vtableelemloc), TBlock|TReference }, + { } }; static Parse ptab[DwarfAttrMax]; static int -parseattrs(Dwarf *d, DwarfBuf *b, ulong tag, ulong unit, DwarfAbbrev *a, DwarfAttrs *attrs) +parseattrs(DwarfBuf *b, ulong unit, DwarfAbbrev *a, DwarfAttrs *attrs) { - int i, f, n, got; - static int nbad; - void *v; + int i, f, n, got; + static int nbad; + void *v; - /* initialize ptab first time through for quick access */ - if(ptab[DwarfAttrName].name != DwarfAttrName) - for(i=0; plist[i].name; i++) - ptab[plist[i].name] = plist[i]; + /* initialize ptab first time through for quick access */ + if(ptab[DwarfAttrName].name != DwarfAttrName) + for(i=0; plist[i].name; i++) + ptab[plist[i].name] = plist[i]; - memset(attrs, 0, sizeof *attrs); - attrs->tag = a->tag; - attrs->haskids = a->haskids; + memset(attrs, 0, sizeof *attrs); + attrs->tag = a->tag; + attrs->haskids = a->haskids; - for(i=0; inattr; i++){ - n = a->attr[i].name; - f = a->attr[i].form; - if(n < 0 || n >= DwarfAttrMax || ptab[n].name==0) { - if (skipform(d, b, f) < 0) { - if(++nbad == 1) - werrstr("dwarf parse attrs: cannot skip form %d", f); - return -1; - } - continue; - } - v = (char*)attrs + ptab[n].off; - got = 0; - if(f == FormIndirect) - f = dwarfget128(b); - if((ptab[n].type&(TConstant|TReference|TAddress)) - && getulong(b, f, unit, v, &got) >= 0) - ; - else if((ptab[n].type&TFlag) && getuchar(b, f, v) >= 0) - got = TFlag; - else if((ptab[n].type&TString) && getstring(d, b, f, v) >= 0) - got = TString; - else if((ptab[n].type&TBlock) && getblock(b, f, v) >= 0) - got = TBlock; - else { - if(skipform(d, b, f) < 0){ - if(++nbad == 1) - werrstr("dwarf parse attrs: cannot skip form %d", f); - return -1; - } - } -#if 0 - if(got == TBlock && (ptab[n].type&TConstant)) - got = constblock(b->d, v, v); -#endif - *((uchar*)attrs+ptab[n].haveoff) = got; - } - return 0; + for(i=0; inattr; i++){ + n = a->attr[i].name; + f = a->attr[i].form; + if(n < 0 || n >= DwarfAttrMax || ptab[n].name==0){ + if(++nbad == 1) + werrstr("dwarf parse attrs: unexpected attribute name 0x%x", n); + continue; //return -1; + } + v = (char*)attrs + ptab[n].off; + got = 0; + if(f == FormIndirect) + f = dwarfget128(b); + if((ptab[n].type&(TConstant|TReference|TAddress)) + && getulong(b, f, unit, v, &got) >= 0) + ; + else if((ptab[n].type&TFlag) && getuchar(b, f, v) >= 0) + got = TFlag; + else if((ptab[n].type&TString) && getstring(b, f, v) >= 0) + got = TString; + else if((ptab[n].type&TBlock) && getblock(b, f, v) >= 0) + got = TBlock; + else{ + if(skipform(b, f) < 0){ + if(++nbad == 1) + werrstr("dwarf parse attrs: cannot skip form %d", f); + return -1; + } + } + if(got == TBlock && (ptab[n].type&TConstant)) + got = constblock(b->d, v, v); + *((uchar*)attrs+ptab[n].haveoff) = got; + } + return 0; } static int getulong(DwarfBuf *b, int form, ulong unit, ulong *u, int *type) { - static int nbad; - uvlong uv; + static int nbad; + uvlong uv; - switch(form){ - default: - return -1; + switch(form){ + default: + return -1; /* addresses */ - case FormAddr: - *type = TAddress; - *u = dwarfgetaddr(b); - return 0; + case FormAddr: + *type = TAddress; + *u = dwarfgetaddr(b); + return 0; /* references */ - case FormRefAddr: - /* absolute ref in .debug_info */ - *type = TReference; - *u = dwarfgetaddr(b); - return 0; - case FormRef1: - *u = dwarfget1(b); - goto relativeref; - case FormRef2: - *u = dwarfget2(b); - goto relativeref; - case FormRef4: - *u = dwarfget4(b); - goto relativeref; - case FormRef8: - *u = dwarfget8(b); - goto relativeref; - case FormRefUdata: - *u = dwarfget128(b); - relativeref: - *u += unit; - *type = TReference; - return 0; + case FormRefAddr: + /* absolute ref in .debug_info */ + *type = TReference; + *u = dwarfgetaddr(b); + return 0; + case FormRef1: + *u = dwarfget1(b); + goto relativeref; + case FormRef2: + *u = dwarfget2(b); + goto relativeref; + case FormRef4: + *u = dwarfget4(b); + goto relativeref; + case FormRef8: + *u = dwarfget8(b); + goto relativeref; + case FormRefUdata: + *u = dwarfget128(b); + relativeref: + *u += unit; + *type = TReference; + return 0; /* constants */ - case FormData1: - *u = dwarfget1(b); - goto constant; - case FormData2: - *u = dwarfget2(b); - goto constant; - case FormData4: - *u = dwarfget4(b); - goto constant; - case FormData8: - uv = dwarfget8(b); - *u = uv; - if(uv != *u && ++nbad == 1) - werrstr("dwarf: truncating 64-bit attribute constants"); - goto constant; - case FormSdata: - *u = dwarfget128s(b); - goto constant; - case FormUdata: - *u = dwarfget128(b); - constant: - *type = TConstant; - return 0; - } + case FormData1: + *u = dwarfget1(b); + goto constant; + case FormData2: + *u = dwarfget2(b); + goto constant; + case FormData4: + *u = dwarfget4(b); + goto constant; + case FormData8: + uv = dwarfget8(b); + *u = uv; + if(uv != *u && ++nbad == 1) + werrstr("dwarf: truncating 64-bit attribute constants"); + goto constant; + case FormSdata: + *u = dwarfget128s(b); + goto constant; + case FormUdata: + *u = dwarfget128(b); + constant: + *type = TConstant; + return 0; + } } static int getuchar(DwarfBuf *b, int form, uchar *u) { - switch(form){ - default: - return -1; + switch(form){ + default: + return -1; - case FormFlag: - *u = dwarfget1(b); - return 0; - } + case FormFlag: + *u = dwarfget1(b); + return 0; + } } static int -getstring(Dwarf *d, DwarfBuf *b, int form, char **s) +getstring(DwarfBuf *b, int form, char **s) { - static int nbad; - ulong u, x; + static int nbad; + ulong u; - switch(form){ - default: - return -1; + switch(form){ + default: + return -1; - case FormString: - x = b->p - d->info.data; - *s = dwarfgetstring(b); - for (u = 0; (*s)[u]; u++) { - assert(isprint((*s)[u])); - } - return 0; + case FormString: + *s = dwarfgetstring(b); + return 0; - case FormStrp: - u = dwarfget4(b); - if(u >= b->d->str.len){ - if(++nbad == 1) - werrstr("dwarf: bad string pointer 0x%lux in attribute", u); - /* don't return error - maybe can proceed */ - *s = nil; - }else - *s = (char*)b->d->str.data + u; - return 0; + case FormStrp: + u = dwarfget4(b); + if(u >= b->d->str.len){ + if(++nbad == 1) + werrstr("dwarf: bad string pointer 0x%lux in attribute", u); + /* don't return error - maybe can proceed */ + *s = nil; + }else + *s = (char*)b->d->str.data + u; + return 0; - } + } } static int getblock(DwarfBuf *b, int form, DwarfBlock *bl) { - ulong n; + ulong n; - switch(form){ - default: - return -1; - case FormDwarfBlock: - n = dwarfget128(b); - goto copyn; - case FormDwarfBlock1: - n = dwarfget1(b); - goto copyn; - case FormDwarfBlock2: - n = dwarfget2(b); - goto copyn; - case FormDwarfBlock4: - n = dwarfget4(b); - copyn: - bl->data = dwarfgetnref(b, n); - bl->len = n; - if(bl->data == nil) - return -1; - return 0; - } + switch(form){ + default: + return -1; + case FormDwarfBlock: + n = dwarfget128(b); + goto copyn; + case FormDwarfBlock1: + n = dwarfget1(b); + goto copyn; + case FormDwarfBlock2: + n = dwarfget2(b); + goto copyn; + case FormDwarfBlock4: + n = dwarfget4(b); + copyn: + bl->data = dwarfgetnref(b, n); + bl->len = n; + if(bl->data == nil) + return -1; + return 0; + } +} + +static int +constblock(Dwarf *d, DwarfBlock *bl, ulong *pval) +{ + DwarfBuf b; + + memset(&b, 0, sizeof b); + b.p = bl->data; + b.ep = bl->data+bl->len; + b.d = d; + + switch(dwarfget1(&b)){ + case OpAddr: + *pval = dwarfgetaddr(&b); + return TConstant; + case OpConst1u: + *pval = dwarfget1(&b); + return TConstant; + case OpConst1s: + *pval = (schar)dwarfget1(&b); + return TConstant; + case OpConst2u: + *pval = dwarfget2(&b); + return TConstant; + case OpConst2s: + *pval = (s16int)dwarfget2(&b); + return TConstant; + case OpConst4u: + *pval = dwarfget4(&b); + return TConstant; + case OpConst4s: + *pval = (s32int)dwarfget4(&b); + return TConstant; + case OpConst8u: + *pval = (u64int)dwarfget8(&b); + return TConstant; + case OpConst8s: + *pval = (s64int)dwarfget8(&b); + return TConstant; + case OpConstu: + *pval = dwarfget128(&b); + return TConstant; + case OpConsts: + *pval = dwarfget128s(&b); + return TConstant; + case OpPlusUconst: + *pval = dwarfget128(&b); + return TConstant; + default: + return TBlock; + } } /* last resort */ static int -skipform(Dwarf *d, DwarfBuf *b, int form) +skipform(DwarfBuf *b, int form) { - int type; - DwarfVal val; + int type; + DwarfVal val; - if(getulong(b, form, 0, &val.c, &type) < 0 - && getuchar(b, form, (uchar*)&val) < 0 - && getstring(d, b, form, &val.s) < 0 - && getblock(b, form, &val.b) < 0) - return -1; - return 0; + if(getulong(b, form, 0, &val.c, &type) < 0 + && getuchar(b, form, (uchar*)&val) < 0 + && getstring(b, form, &val.s) < 0 + && getblock(b, form, &val.b) < 0) + return -1; + return 0; } -void stackinit(DwarfStack *stack) -{ - memset(stack, 0, sizeof(*stack)); - stack->data = stack->storage; - stack->length = 0; stack->max = sizeof(stack->storage) / sizeof(stack->storage[0]); -} - -void stackpush(DwarfStack *stack, ulong value) -{ - if (stack->length == stack->max) { - ulong *newstack = malloc(sizeof(ulong)*stack->max*2); - memcpy(newstack, stack->data, sizeof(ulong)*stack->length); - if (stack->data != stack->storage) - free(stack->data); - stack->data = newstack; - stack->max *= 2; - } - werrstr("stack[%d] = %x", stack->length, value); - stack->data[stack->length++] = value; -} - -ulong stackpop(DwarfStack *stack) -{ - ASSERT(stack->length > 0); - ulong val = stack->data[--stack->length]; - werrstr("pop stack[%d] -> %x", stack->length, val); - return val; -} - -void stackfree(DwarfStack *stack) -{ - if (stack->data != stack->storage) - free(stack->data); -} - -// Returns -1 on failure -int dwarfgetarg(Dwarf *d, const char *name, DwarfBuf *buf, ulong cfa, PROSSYM_REGISTERS registers, ulong *result) -{ - int ret = 0; - DwarfStack stack = { }; - stackinit(&stack); - while (buf->p < buf->ep) { - int opcode = dwarfget1(buf); - werrstr("opcode %x", opcode); - switch (opcode) { - case 0: - buf->p = buf->ep; - break; - case OpAddr: - if (d->addrsize == 4) { - stackpush(&stack, dwarfget4(buf)); - break; - } else { - werrstr("%s: we only support 4 byte addrs", name); - goto fatal; - } - case OpConst1s: { - signed char c = dwarfget1(buf); - stackpush(&stack, c); - } break; - case OpConst1u: - stackpush(&stack, dwarfget1(buf)); - break; - case OpConst2s: { - signed short s = dwarfget2(buf); - stackpush(&stack, s); - } break; - case OpConst2u: - stackpush(&stack, dwarfget2(buf)); - break; - case OpConst4s: { - signed int i = dwarfget4(buf); - stackpush(&stack, i); - } break; - case OpConst4u: - stackpush(&stack, dwarfget4(buf)); - break; - case OpConst8s: - case OpConst8u: - werrstr("const 8 not yet supported"); - goto fatal; - case OpConsts: - stackpush(&stack, dwarfget128s(buf)); - break; - case OpConstu: - stackpush(&stack, dwarfget128(buf)); - break; - case OpDup: { - ulong popped = stackpop(&stack); - stackpush(&stack, popped); - stackpush(&stack, popped); - } break; - case OpDrop: - stackpop(&stack); - break; - case OpOver: { - if (stack.length < 2) goto fatal; - stackpush(&stack, stack.data[stack.length-2]); - } break; - case OpPick: { - ulong arg = dwarfget1(buf); - if (arg >= stack.length) goto fatal; - arg = stack.data[stack.length-1-arg]; - stackpush(&stack, arg); - } break; - case OpSwap: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b); - stackpush(&stack, a); - } break; - case OpRot: { - ulong a = stackpop(&stack), b = stackpop(&stack), c = stackpop(&stack); - stackpush(&stack, b); - stackpush(&stack, c); - stackpush(&stack, a); - } break; - case OpXderef: - case OpXderefSize: - werrstr("Xderef not yet supported"); - goto fatal; - case OpAbs: { - long a = stackpop(&stack); - stackpush(&stack, a < 0 ? -a : a); - } break; - case OpAnd: - stackpush(&stack, stackpop(&stack) & stackpop(&stack)); - break; - case OpDiv: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b / a); - } break; - case OpMinus: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b - a); - } break; - case OpMod: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b % a); - } break; - case OpMul: - stackpush(&stack, stackpop(&stack) * stackpop(&stack)); - break; - case OpNeg: - stackpush(&stack, -stackpop(&stack)); - break; - case OpNot: - stackpush(&stack, ~stackpop(&stack)); - break; - case OpOr: - stackpush(&stack, stackpop(&stack) | stackpop(&stack)); - break; - case OpPlus: - stackpush(&stack, stackpop(&stack) + stackpop(&stack)); - break; - case OpPlusUconst: - stackpush(&stack, stackpop(&stack) + dwarfget128(buf)); - break; - case OpShl: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b << a); - } break; - case OpShr: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b >> a); - } break; - case OpShra: { - ulong a = stackpop(&stack); - long b = stackpop(&stack); - if (b < 0) - b = -(-b >> a); - else - b = b >> a; - stackpush(&stack, b); - } break; - case OpXor: - stackpush(&stack, stackpop(&stack) ^ stackpop(&stack)); - break; - case OpSkip: - buf->p += dwarfget2(buf); - break; - case OpBra: { - ulong a = dwarfget2(buf); - if (stackpop(&stack)) - buf->p += a; - } break; - case OpEq: - stackpush(&stack, stackpop(&stack) == stackpop(&stack)); - break; - case OpGe: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b >= a); - } break; - case OpGt: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b > a); - } break; - case OpLe: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b <= a); - } break; - case OpLt: { - ulong a = stackpop(&stack), b = stackpop(&stack); - stackpush(&stack, b < a); - } break; - case OpNe: - stackpush(&stack, stackpop(&stack) != stackpop(&stack)); - break; - case OpNop: - break; - case OpDeref: { - ulong val, addr = stackpop(&stack); - if (!RosSymCallbacks.MemGetProc - (d->pe->fd, - &val, - addr, - d->addrsize)) - goto fatal; - stackpush(&stack, val); - } break; - case OpDerefSize: { - ulong val, addr = stackpop(&stack), size = dwarfget1(buf); - if (!RosSymCallbacks.MemGetProc - (d->pe->fd, - &val, - addr, - size)) - goto fatal; - stackpush(&stack, val); - } break; - case OpFbreg: { - ulong val, addr = cfa, offset = dwarfget128s(buf); - werrstr("FBREG cfa %x offset %x", cfa, offset); - if (!RosSymCallbacks.MemGetProc - (d->pe->fd, - &val, - addr+offset, - d->addrsize)) - goto fatal; - stackpush(&stack, val); - } break; - case OpPiece: - werrstr("OpPiece not supported"); - goto fatal; - default: - if (opcode >= OpLit0 && opcode < OpReg0) - stackpush(&stack, opcode - OpLit0); - else if (opcode >= OpReg0 && opcode < OpBreg0) { - ulong reg = opcode - OpReg0; - werrstr("REG[%d] value %x", reg, (ulong)registers->Registers[reg]); - stackpush(&stack, registers->Registers[reg]); - } else if (opcode >= OpBreg0 && opcode < OpRegx) { - ulong val, - reg = opcode - OpBreg0, - addr = registers->Registers[reg], - offset = dwarfget128s(buf); - werrstr("BREG[%d] reg %x offset %x", reg, addr, offset); - if (!RosSymCallbacks.MemGetProc - (d->pe->fd, - &val, - addr + offset, - d->addrsize)) - goto fatal; - stackpush(&stack, val); - } else { - werrstr("opcode %x not supported", opcode); - goto fatal; - } - break; - } - } - if (stack.length < 1) goto fatal; - *result = stackpop(&stack); - werrstr("%s: value %x", name, *result); - goto finish; - -fatal: - ret = -1; - -finish: - stackfree(&stack); - return ret; -} - -int dwarfargvalue(Dwarf *d, DwarfSym *proc, ulong pc, ulong cfa, PROSSYM_REGISTERS registers, DwarfParam *parameter) -{ - int gotarg; - DwarfSym unit = { }; - - if (dwarfenumunit(d, proc->unit, &unit) == -1) - return -1; - - werrstr("lookup in unit %x-%x, pc %x", unit.attrs.lowpc, unit.attrs.highpc, pc); - pc -= unit.attrs.lowpc; - - werrstr("paramblock %s -> unit %x type %x fde %x len %d registers %x", - parameter->name, - parameter->unit, - parameter->type, - parameter->fde, - parameter->len, - registers); - - // Seek our range in loc - DwarfBuf locbuf; - DwarfBuf instream = { }; - - locbuf.d = d; - locbuf.addrsize = d->addrsize; - - if (parameter->loctype == TConstant) { - locbuf.p = d->loc.data + parameter->fde; - locbuf.ep = d->loc.data + d->loc.len; - ulong start, end, len; - do { - len = 0; - start = dwarfget4(&locbuf); - end = dwarfget4(&locbuf); - if (start && end) { - len = dwarfget2(&locbuf); - instream = locbuf; - instream.ep = instream.p + len; - locbuf.p = instream.ep; - } - werrstr("ip %x s %x e %x (%x bytes)", pc, start, end, len); - } while (start && end && (start > pc || end <= pc)); - } else if (parameter->loctype == TBlock) { - instream = locbuf; - instream.p = (void *)parameter->fde; - instream.ep = instream.p + parameter->len; - } else { - werrstr("Wrong block type for parameter %s", parameter->name); - return -1; - } - - gotarg = dwarfgetarg(d, parameter->name, &instream, cfa, registers, ¶meter->value); - if (gotarg == -1) - return -1; - - return 0; -} - -int -dwarfgetparams(Dwarf *d, DwarfSym *s, ulong pc, int pnum, DwarfParam *paramblocks) -{ - int ip = 0; - DwarfSym param = { }; - int res = dwarfnextsymat(d, s, ¶m); - while (res == 0 && ip < pnum) { - if (param.attrs.tag == TagFormalParameter && - param.attrs.have.name && - param.attrs.have.location) { - paramblocks[ip].name = malloc(strlen(param.attrs.name)+1); - strcpy(paramblocks[ip].name, param.attrs.name); - paramblocks[ip].unit = param.unit; - paramblocks[ip].type = param.attrs.type; - paramblocks[ip].loctype = param.attrs.have.location; - paramblocks[ip].len = param.attrs.location.b.len; - paramblocks[ip].fde = param.attrs.location.b.data; - werrstr("param[%d] block %s -> type %x loctype %x fde %x len %x", - ip, - paramblocks[ip].name, - paramblocks[ip].type, - paramblocks[ip].loctype, - paramblocks[ip].fde, - paramblocks[ip].len); - ip++; - } - res = dwarfnextsymat(d, s, ¶m); - } - return ip; -} diff --git a/lib/rossym/dwarfopen.c b/lib/rossym/dwarfopen.c index b3ea2cd18d6..9a5f20c80fa 100644 --- a/lib/rossym/dwarfopen.c +++ b/lib/rossym/dwarfopen.c @@ -31,8 +31,7 @@ dwarfopen(Pe *pe) || pe->loadsection(pe, ".debug_aranges", &d->aranges) < 0 || pe->loadsection(pe, ".debug_line", &d->line) < 0 || pe->loadsection(pe, ".debug_pubnames", &d->pubnames) < 0 - || pe->loadsection(pe, ".debug_info", &d->info) < 0 - || pe->loadsection(pe, ".debug_loc", &d->loc) < 0) + || pe->loadsection(pe, ".debug_info", &d->info) < 0) goto err; pe->loadsection(pe, ".debug_frame", &d->frame); pe->loadsection(pe, ".debug_ranges", &d->ranges); @@ -50,7 +49,6 @@ err: free(d->ranges.data); free(d->str.data); free(d->info.data); - free(d->loc.data); free(d); return nil; } diff --git a/lib/rossym/dwarfpc.c b/lib/rossym/dwarfpc.c index ec41e10d16c..4edb5569ae9 100644 --- a/lib/rossym/dwarfpc.c +++ b/lib/rossym/dwarfpc.c @@ -27,389 +27,359 @@ enum { - Isstmt = 1<<0, - BasicDwarfBlock = 1<<1, - EndSequence = 1<<2, - PrologueEnd = 1<<3, - EpilogueBegin = 1<<4 + Isstmt = 1<<0, + BasicDwarfBlock = 1<<1, + EndSequence = 1<<2, + PrologueEnd = 1<<3, + EpilogueBegin = 1<<4 }; typedef struct State State; struct State { - ulong addr; - ulong file; - ulong line; - ulong column; - ulong flags; - ulong isa; + ulong addr; + ulong file; + ulong line; + ulong column; + ulong flags; + ulong isa; }; int -dwarfpctoline(Dwarf *d, DwarfSym *proc, ulong pc, char **file, char **function, ulong *line) +dwarfpctoline(Dwarf *d, ulong pc, char **cdir, char **dir, char **file, char **function, ulong *line, ulong *mtime, ulong *length) { - char *cdir; - uchar *prog, *opcount, *end, *dirs; - ulong off, unit, len, vers, x, start, lastline; - int i, first, firstline, op, a, l, quantum, isstmt, linebase, linerange, opcodebase, nf; - char *files, *s; - DwarfBuf b; - DwarfSym sym; - State emit, cur, reset; - char **f, **newf; + uchar *prog, *opcount, *end, *dirs; + ulong off, unit, len, vers, x, start, lastline; + int i, first, firstline, op, a, l, quantum, isstmt, linebase, linerange, opcodebase, nf; + char *files, *s; + DwarfBuf b; + DwarfSym sym; + State emit, cur, reset; + uchar **f, **newf; - f = nil; - memset(proc, 0, sizeof(*proc)); + f = nil; - int runit = dwarfaddrtounit(d, pc, &unit); - if (runit < 0) - return -1; - int rtag = dwarflookuptag(d, unit, TagCompileUnit, &sym); - if (rtag < 0) - return -1; + if(dwarfaddrtounit(d, pc, &unit) < 0 + || dwarflookuptag(d, unit, TagCompileUnit, &sym) < 0) + return -1; - if(!sym.attrs.have.stmtlist){ - werrstr("no line mapping information for 0x%x", pc); - return -1; - } - off = sym.attrs.stmtlist; - if(off >= d->line.len){ - werrstr("bad stmtlist"); - goto bad; - } - - if(trace) werrstr("unit 0x%x stmtlist 0x%x", unit, sym.attrs.stmtlist); - - memset(&b, 0, sizeof b); - b.d = d; - b.p = d->line.data + off; - b.ep = b.p + d->line.len; - b.addrsize = sym.b.addrsize; /* should i get this from somewhere else? */ - - len = dwarfget4(&b); - if(b.p==nil || b.p+len > b.ep || b.p+len < b.p){ - werrstr("bad len"); - goto bad; - } - - b.ep = b.p+len; - vers = dwarfget2(&b); - if(vers != 2){ - werrstr("bad dwarf version 0x%x", vers); - return -1; - } - - len = dwarfget4(&b); - if(b.p==nil || b.p+len > b.ep || b.p+len < b.p){ - werrstr("another bad len"); - goto bad; - } - prog = b.p+len; - - quantum = dwarfget1(&b); - isstmt = dwarfget1(&b); - linebase = (schar)dwarfget1(&b); - linerange = (schar)dwarfget1(&b); - opcodebase = dwarfget1(&b); - - opcount = b.p-1; - dwarfgetnref(&b, opcodebase-1); - if(b.p == nil){ - werrstr("bad opcode chart"); - goto bad; - } - - /* just skip the files and dirs for now; we'll come back */ - dirs = b.p; - while (b.p && *b.p) - dwarfgetstring(&b); - dwarfget1(&b); - - files = (char*)b.p; - while(b.p!=nil && *b.p!=0){ - dwarfgetstring(&b); - dwarfget128(&b); - dwarfget128(&b); - dwarfget128(&b); - } - dwarfget1(&b); - - /* move on to the program */ - if(b.p == nil || b.p > prog){ - werrstr("bad header"); - goto bad; - } - b.p = prog; - - reset.addr = 0; - reset.file = 1; - reset.line = 1; - reset.column = 0; - reset.flags = isstmt ? Isstmt : 0; - reset.isa = 0; - - cur = reset; - emit = reset; - nf = 0; - start = 0; - if(trace) werrstr("program @ %lu ... %.*H opbase = %d", b.p - d->line.data, b.ep-b.p, b.p, opcodebase); - first = 1; - while(b.p != nil){ - firstline = 0; - op = dwarfget1(&b); - if(trace) werrstr("\tline %lu, addr 0x%x, op %d %.10H", cur.line, cur.addr, op, b.p); - if(op >= opcodebase){ - a = (op - opcodebase) / linerange; - l = (op - opcodebase) % linerange + linebase; - cur.line += l; - cur.addr += a * quantum; - if(trace) werrstr(" +%d,%d", a, l); - emit: - if(first){ - if(cur.addr > pc){ - werrstr("found wrong line mapping 0x%x for pc 0x%x", cur.addr, pc); - /* This is an overzealous check. gcc can produce discontiguous ranges - and reorder statements, so it's possible for a future line to start - ahead of pc and still find a matching one. */ - /*goto out;*/ - firstline = 1; - } - first = 0; - start = cur.addr; - } - if(cur.addr > pc && !firstline) - break; - if(b.p == nil){ - werrstr("buffer underflow in line mapping"); - goto out; - } - emit = cur; - if(emit.flags & EndSequence){ - werrstr("found wrong line mapping 0x%x-0x%x for pc 0x%x", start, cur.addr, pc); - goto out; - } - cur.flags &= ~(BasicDwarfBlock|PrologueEnd|EpilogueBegin); - }else{ - switch(op){ - case 0: /* extended op code */ - if(trace) werrstr(" ext"); - len = dwarfget128(&b); - end = b.p+len; - if(b.p == nil || end > b.ep || end < b.p || len < 1) - goto bad; - switch(dwarfget1(&b)){ - case 1: /* end sequence */ - if(trace) werrstr(" end"); - cur.flags |= EndSequence; - goto emit; - case 2: /* set address */ - cur.addr = dwarfgetaddr(&b); - if(trace) werrstr(" set pc 0x%x", cur.addr); - break; - case 3: /* define file */ - newf = malloc(nf+1*sizeof(f[0])); - if (newf) - RtlMoveMemory(newf, f, nf*sizeof(f[0])); - if(newf == nil) - goto out; - free(f); - f = newf; - f[nf++] = s = dwarfgetstring(&b); - DPRINT1("str %s", s); - dwarfget128(&b); - dwarfget128(&b); - dwarfget128(&b); - if(trace) werrstr(" def file %s", s); - break; - } - if(b.p == nil || b.p > end) - goto bad; - b.p = end; - break; - case 1: /* emit */ - if(trace) werrstr(" emit"); - goto emit; - case 2: /* advance pc */ - a = dwarfget128(&b); - if(trace) werrstr(" advance pc + %lu", a*quantum); - cur.addr += a * quantum; - break; - case 3: /* advance line */ - l = dwarfget128s(&b); - if(trace) werrstr(" advance line + %ld", l); - cur.line += l; - break; - case 4: /* set file */ - if(trace) werrstr(" set file"); - cur.file = dwarfget128s(&b); - break; - case 5: /* set column */ - if(trace) werrstr(" set column"); - cur.column = dwarfget128(&b); - break; - case 6: /* negate stmt */ - if(trace) werrstr(" negate stmt"); - cur.flags ^= Isstmt; - break; - case 7: /* set basic block */ - if(trace) werrstr(" set basic block"); - cur.flags |= BasicDwarfBlock; - break; - case 8: /* const add pc */ - a = (255 - opcodebase) / linerange * quantum; - if(trace) werrstr(" const add pc + %d", a); - cur.addr += a; - break; - case 9: /* fixed advance pc */ - a = dwarfget2(&b); - if(trace) werrstr(" fixed advance pc + %d", a); - cur.addr += a; - break; - case 10: /* set prologue end */ - if(trace) werrstr(" set prologue end"); - cur.flags |= PrologueEnd; - break; - case 11: /* set epilogue begin */ - if(trace) werrstr(" set epilogue begin"); - cur.flags |= EpilogueBegin; - break; - case 12: /* set isa */ - if(trace) werrstr(" set isa"); - cur.isa = dwarfget128(&b); - break; - default: /* something new - skip it */ - if(trace) werrstr(" unknown %d", opcount[op]); - for(i=0; i 0 && b.p!=nil && *b.p!=0; i--){ - dwarfgetstring(&b); - dwarfget128(&b); - dwarfget128(&b); - dwarfget128(&b); - } - if(b.p == nil){ - werrstr("problem parsing file data second time (cannot happen)"); - goto bad; - } - if(*b.p == 0){ - if(i >= nf){ - werrstr("bad file index in mapping data"); - goto bad; - } - b.p = (uchar*)f[i]; - } - s = dwarfgetstring(&b); - *file = s; - i = dwarfget128(&b); /* directory */ - x = dwarfget128(&b); - x = dwarfget128(&b); - - /* fetch dir name */ - cdir = sym.attrs.have.compdir ? sym.attrs.compdir : 0; - - char *dwarfdir; - dwarfdir = nil; - b.p = dirs; - for (x = 1; b.p && *b.p; x++) { - dwarfdir = dwarfgetstring(&b); - if (x == i) break; + if(!sym.attrs.have.stmtlist){ + werrstr("no line mapping information for 0x%x", pc); + return -1; + } + off = sym.attrs.stmtlist; + if(off >= d->line.len){ + werrstr("bad stmtlist\n"); + goto bad; } - if (!cdir && dwarfdir) - cdir = dwarfdir; - - char *filefull = malloc(strlen(cdir) + strlen(*file) + 2); - strcpy(filefull, cdir); - strcat(filefull, "/"); - strcat(filefull, *file); - *file = filefull; - - *function = nil; - lastline = 0; - - runit = dwarfaddrtounit(d, pc, &unit); - if (runit == 0) { - DwarfSym compunit = { }; - int renum = dwarfenumunit(d, unit, &compunit); - if (renum < 0) - return -1; - renum = dwarfnextsymat(d, &compunit, proc); - while (renum == 0) { - if (proc->attrs.tag == TagSubprogram && - proc->attrs.have.name) - { - if (proc->attrs.lowpc <= pc && proc->attrs.highpc > pc) { - *function = malloc(strlen(proc->attrs.name)+1); - strcpy(*function, proc->attrs.name); - goto done; - } - } - renum = dwarfnextsym(d, proc); - } - } + if(trace) werrstr("unit 0x%x stmtlist 0x%x", unit, sym.attrs.stmtlist); - // Next search by declaration - runit = dwarfaddrtounit(d, pc, &unit); - if (runit == 0) { - DwarfSym compunit = { }; - int renum = dwarfenumunit(d, unit, &compunit); - if (renum < 0) - return -1; - renum = dwarfnextsymat(d, &compunit, proc); - while (renum == 0) { - if (proc->attrs.tag == TagSubprogram && - proc->attrs.have.name && - proc->attrs.declfile == emit.file) - { - if (proc->attrs.declline <= *line && - proc->attrs.declline > lastline) { - free(*function); - *function = malloc(strlen(proc->attrs.name)+1); - strcpy(*function, proc->attrs.name); - goto done; - } - lastline = proc->attrs.declline; - } - renum = dwarfnextsym(d, proc); - } - } + memset(&b, 0, sizeof b); + b.d = d; + b.p = d->line.data + off; + b.ep = b.p + d->line.len; + b.addrsize = sym.b.addrsize; /* should i get this from somewhere else? */ + + len = dwarfget4(&b); + if(b.p==nil || b.p+len > b.ep || b.p+len < b.p){ + werrstr("bad len\n"); + goto bad; + } + + b.ep = b.p+len; + vers = dwarfget2(&b); + if(vers != 2){ + werrstr("bad dwarf version 0x%x", vers); + return -1; + } + + len = dwarfget4(&b); + if(b.p==nil || b.p+len > b.ep || b.p+len < b.p){ + werrstr("another bad len\n"); + goto bad; + } + prog = b.p+len; + + quantum = dwarfget1(&b); + isstmt = dwarfget1(&b); + linebase = (schar)dwarfget1(&b); + linerange = (schar)dwarfget1(&b); + opcodebase = dwarfget1(&b); + + opcount = b.p-1; + dwarfgetnref(&b, opcodebase-1); + if(b.p == nil){ + werrstr("bad opcode chart\n"); + goto bad; + } + + /* just skip the files and dirs for now; we'll come back */ + dirs = b.p; + while (b.p && *b.p) + dwarfgetstring(&b); + dwarfget1(&b); + + files = (char*)b.p; + while(b.p!=nil && *b.p!=0){ + dwarfgetstring(&b); + dwarfget128(&b); + dwarfget128(&b); + dwarfget128(&b); + } + dwarfget1(&b); + + /* move on to the program */ + if(b.p == nil || b.p > prog){ + werrstr("bad header\n"); + goto bad; + } + b.p = prog; + + reset.addr = 0; + reset.file = 1; + reset.line = 1; + reset.column = 0; + reset.flags = isstmt ? Isstmt : 0; + reset.isa = 0; + + cur = reset; + emit = reset; + nf = 0; + start = 0; + if(trace) werrstr("program @ %lu ... %.*H opbase = %d\n", b.p - d->line.data, b.ep-b.p, b.p, opcodebase); + first = 1; + while(b.p != nil){ + firstline = 0; + op = dwarfget1(&b); + if(trace) werrstr("\tline %lu, addr 0x%x, op %d %.10H", cur.line, cur.addr, op, b.p); + if(op >= opcodebase){ + a = (op - opcodebase) / linerange; + l = (op - opcodebase) % linerange + linebase; + cur.line += l; + cur.addr += a * quantum; + if(trace) werrstr(" +%d,%d\n", a, l); + emit: + if(first){ + if(cur.addr > pc){ + werrstr("found wrong line mapping 0x%x for pc 0x%x", cur.addr, pc); + /* This is an overzealous check. gcc can produce discontiguous ranges + and reorder statements, so it's possible for a future line to start + ahead of pc and still find a matching one. */ + /*goto out;*/ + firstline = 1; + } + first = 0; + start = cur.addr; + } + if(cur.addr > pc && !firstline) + break; + if(b.p == nil){ + werrstr("buffer underflow in line mapping"); + goto out; + } + emit = cur; + if(emit.flags & EndSequence){ + werrstr("found wrong line mapping 0x%x-0x%x for pc 0x%x", start, cur.addr, pc); + goto out; + } + cur.flags &= ~(BasicDwarfBlock|PrologueEnd|EpilogueBegin); + }else{ + switch(op){ + case 0: /* extended op code */ + if(trace) werrstr(" ext"); + len = dwarfget128(&b); + end = b.p+len; + if(b.p == nil || end > b.ep || end < b.p || len < 1) + goto bad; + switch(dwarfget1(&b)){ + case 1: /* end sequence */ + if(trace) werrstr(" end\n"); + cur.flags |= EndSequence; + goto emit; + case 2: /* set address */ + cur.addr = dwarfgetaddr(&b); + if(trace) werrstr(" set pc 0x%x\n", cur.addr); + break; + case 3: /* define file */ + newf = malloc(nf+1*sizeof(f[0])); + if (newf) + RtlMoveMemory(newf, f, nf*sizeof(f[0])); + if(newf == nil) + goto out; + f[nf++] = b.p; + s = dwarfgetstring(&b); + dwarfget128(&b); + dwarfget128(&b); + dwarfget128(&b); + if(trace) werrstr(" def file %s\n", s); + break; + } + if(b.p == nil || b.p > end) + goto bad; + b.p = end; + break; + case 1: /* emit */ + if(trace) werrstr(" emit\n"); + goto emit; + case 2: /* advance pc */ + a = dwarfget128(&b); + if(trace) werrstr(" advance pc + %lu\n", a*quantum); + cur.addr += a * quantum; + break; + case 3: /* advance line */ + l = dwarfget128s(&b); + if(trace) werrstr(" advance line + %ld\n", l); + cur.line += l; + break; + case 4: /* set file */ + if(trace) werrstr(" set file\n"); + cur.file = dwarfget128s(&b); + break; + case 5: /* set column */ + if(trace) werrstr(" set column\n"); + cur.column = dwarfget128(&b); + break; + case 6: /* negate stmt */ + if(trace) werrstr(" negate stmt\n"); + cur.flags ^= Isstmt; + break; + case 7: /* set basic block */ + if(trace) werrstr(" set basic block\n"); + cur.flags |= BasicDwarfBlock; + break; + case 8: /* const add pc */ + a = (255 - opcodebase) / linerange * quantum; + if(trace) werrstr(" const add pc + %d\n", a); + cur.addr += a; + break; + case 9: /* fixed advance pc */ + a = dwarfget2(&b); + if(trace) werrstr(" fixed advance pc + %d\n", a); + cur.addr += a; + break; + case 10: /* set prologue end */ + if(trace) werrstr(" set prologue end\n"); + cur.flags |= PrologueEnd; + break; + case 11: /* set epilogue begin */ + if(trace) werrstr(" set epilogue begin\n"); + cur.flags |= EpilogueBegin; + break; + case 12: /* set isa */ + if(trace) werrstr(" set isa\n"); + cur.isa = dwarfget128(&b); + break; + default: /* something new - skip it */ + if(trace) werrstr(" unknown %d\n", opcount[op]); + for(i=0; i 0 && b.p!=nil && *b.p!=0; i--){ + dwarfgetstring(&b); + dwarfget128(&b); + dwarfget128(&b); + dwarfget128(&b); + } + if(b.p == nil){ + werrstr("problem parsing file data second time (cannot happen)"); + goto bad; + } + if(*b.p == 0){ + if(i >= nf){ + werrstr("bad file index in mapping data"); + goto bad; + } + b.p = f[i]; + } + s = dwarfgetstring(&b); + if(file) + *file = s; + i = dwarfget128(&b); /* directory */ + x = dwarfget128(&b); + if(mtime) + *mtime = x; + x = dwarfget128(&b); + if(length) + *length = x; + + /* fetch dir name */ + if(cdir) + *cdir = sym.attrs.compdir; + + if(dir){ + *dir = nil; + b.p = dirs; + for (x = 1; b.p && *b.p; x++) + if (x == i) { + *dir = dwarfgetstring(&b); + break; + } + } + + *function = nil; + lastline = 0; +#if 0 + if (dwarfenumunit(d, unit, &proc) >= 0) { + dwarfnextsymat(d, &proc, 0); + while (dwarfnextsymat(d, &proc, 1) == 1) { + if (proc.attrs.tag == TagSubprogram && + proc.attrs.have.name && + proc.attrs.declfile == emit.file && + proc.attrs.declline <= *line && + proc.attrs.declline > lastline) { + lastline = proc.attrs.declline; + free(*function); + *function = malloc(strlen(proc.attrs.name)+1); + strcpy(*function, proc.attrs.name); + } + } + } +#elif 1 + ulong lastaddr = 0; + *function = NULL; + for (i = 0; i < d->pe->nsymbols; i++) { + if (d->pe->symtab[i].address > lastaddr && + d->pe->symtab[i].address <= pc - d->pe->imagebase && + d->pe->symtab[i].address < d->pe->imagesize) { + lastaddr = d->pe->symtab[i].address; + *function = d->pe->symtab[i].name; + } + } +#else + // *sigh* we get unrelocated low_pc and high_pc because the dwarf symbols + // are not 'loaded' in the PE sense. + if (dwarflookupfn(d, unit, pc, &proc) >= 0) { + *function = malloc(strlen(proc.attrs.name)+1); + strcpy(*function, proc.attrs.name); + } +#endif + + /* free at last, free at last */ + free(f); + return 0; - /* free at last, free at last */ -done: - free(f); - return 0; bad: - werrstr("corrupted line mapping for 0x%x", pc); + werrstr("corrupted line mapping for 0x%x", pc); out: - free(f); - return -1; + free(f); + return -1; } -VOID RosSymFreeInfo(PROSSYM_LINEINFO LineInfo) -{ - int i; - free(LineInfo->FileName); - LineInfo->FileName = NULL; - free(LineInfo->FunctionName); - LineInfo->FunctionName = NULL; - for (i = 0; i < sizeof(LineInfo->Parameters)/sizeof(LineInfo->Parameters[0]); i++) - free(LineInfo->Parameters[i].ValueName); -} diff --git a/lib/rossym/find.c b/lib/rossym/find.c index 9cc5aeeeece..c311e3eed0a 100644 --- a/lib/rossym/find.c +++ b/lib/rossym/find.c @@ -42,90 +42,107 @@ #define NDEBUG #include -#include "rossym.h" -#include "dwarf.h" -#include "pe.h" +static PROSSYM_ENTRY +FindEntry(IN PROSSYM_INFO RosSymInfo, IN ULONG_PTR RelativeAddress) +{ + /* + * Perform a binary search. + * + * The code below is a bit sneaky. After a comparison fails, we + * divide the work in half by moving either left or right. If lim + * is odd, moving left simply involves halving lim: e.g., when lim + * is 5 we look at item 2, so we change lim to 2 so that we will + * look at items 0 & 1. If lim is even, the same applies. If lim + * is odd, moving right again involes halving lim, this time moving + * the base up one item past p: e.g., when lim is 5 we change base + * to item 3 and make lim 2 so that we will look at items 3 and 4. + * If lim is even, however, we have to shrink it by one before + * halving: e.g., when lim is 4, we still looked at item 2, so we + * have to make lim 3, then halve, obtaining 1, so that we will only + * look at item 3. + */ + PROSSYM_ENTRY Base = RosSymInfo->Symbols; + ULONG Lim; + PROSSYM_ENTRY Mid, Low; + + if (RelativeAddress < Base->Address) + { + return NULL; + } + + Low = Base; + for (Lim = RosSymInfo->SymbolsCount; Lim != 0; Lim >>= 1) + { + Mid = Base + (Lim >> 1); + if (RelativeAddress == Mid->Address) + { + return Mid; + } + if (Mid->Address < RelativeAddress) /* key > mid: move right */ + { + Low = Mid; + Base = Mid + 1; + Lim--; + } /* else move left */ + } + + return Low; +} + BOOLEAN -RosSymGetAddressInformation -(PROSSYM_INFO RosSymInfo, - ULONG_PTR RelativeAddress, - PROSSYM_LINEINFO RosSymLineInfo) +RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo, + ULONG_PTR RelativeAddress, + ULONG *LineNumber, + char *FileName, + char *FunctionName) { - ROSSYM_REGISTERS registers; - DwarfParam params[sizeof(RosSymLineInfo->Parameters)/sizeof(RosSymLineInfo->Parameters[0])]; - DwarfSym proc = { }; - int i; - int res = dwarfpctoline - (RosSymInfo, - &proc, - RelativeAddress + RosSymInfo->pe->imagebase, - &RosSymLineInfo->FileName, - &RosSymLineInfo->FunctionName, - &RosSymLineInfo->LineNumber); - if (res == -1) { - werrstr("Could not get basic function info"); - return FALSE; + PROSSYM_ENTRY RosSymEntry; + + DPRINT("RelativeAddress = 0x%08x\n", RelativeAddress); + + if (RosSymInfo->Symbols == NULL || RosSymInfo->SymbolsCount == 0 || + RosSymInfo->Strings == NULL || RosSymInfo->StringsLength == 0) + { + DPRINT1("Uninitialized RosSymInfo\n"); + return FALSE; } - if (!(RosSymLineInfo->Flags & ROSSYM_LINEINFO_HAS_REGISTERS)) - return TRUE; + ASSERT(LineNumber || FileName || FunctionName); - registers = RosSymLineInfo->Registers; + /* find symbol entry for function */ + RosSymEntry = FindEntry(RosSymInfo, RelativeAddress); - DwarfExpr cfa = { }; - ulong cfaLocation; - if (dwarfregunwind - (RosSymInfo, - RelativeAddress + RosSymInfo->pe->imagebase, - proc.attrs.framebase.c, - &cfa, - ®isters) == -1) { - werrstr("Can't get cfa location for %s", RosSymLineInfo->FunctionName); - return TRUE; + if (NULL == RosSymEntry) + { + DPRINT("None of the requested information was found!\n"); + return FALSE; } - res = dwarfgetparams - (RosSymInfo, - &proc, - RelativeAddress + RosSymInfo->pe->imagebase, - sizeof(params)/sizeof(params[0]), - params); - - if (res == -1) { - werrstr("%s: could not get params at all", RosSymLineInfo->FunctionName); - RosSymLineInfo->NumParams = 0; - return TRUE; + if (LineNumber != NULL) + { + *LineNumber = RosSymEntry->SourceLine; + } + if (FileName != NULL) + { + PCSTR Name = ""; + if (RosSymEntry->FileOffset != 0) + { + Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FileOffset; + } + strcpy(FileName, Name); + } + if (FunctionName != NULL) + { + PCSTR Name = ""; + if (RosSymEntry->FunctionOffset != 0) + { + Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FunctionOffset; + } + strcpy(FunctionName, Name); } - werrstr("%s: res %d", RosSymLineInfo->FunctionName, res); - RosSymLineInfo->NumParams = res; - - res = dwarfcomputecfa(RosSymInfo, &cfa, ®isters, &cfaLocation); - if (res == -1) { - werrstr("%s: could not get our own cfa", RosSymLineInfo->FunctionName); - return TRUE; - } - - for (i = 0; i < RosSymLineInfo->NumParams; i++) { - werrstr("Getting arg %s, unit %x, type %x", - params[i].name, params[i].unit, params[i].type); - res = dwarfargvalue - (RosSymInfo, - &proc, - RelativeAddress + RosSymInfo->pe->imagebase, - cfaLocation, - ®isters, - ¶ms[i]); - if (res == -1) { RosSymLineInfo->NumParams = i; return TRUE; } - werrstr("%s: %x", params[i].name, params[i].value); - RosSymLineInfo->Parameters[i].ValueName = malloc(strlen(params[i].name)+1); - strcpy(RosSymLineInfo->Parameters[i].ValueName, params[i].name); - free(params[i].name); - RosSymLineInfo->Parameters[i].Value = params[i].value; - } - - return TRUE; + return TRUE; } /* EOF */ diff --git a/lib/rossym/fromfile.c b/lib/rossym/fromfile.c index c26ea3e2a80..21339b7ac3f 100644 --- a/lib/rossym/fromfile.c +++ b/lib/rossym/fromfile.c @@ -8,156 +8,140 @@ */ #define NTOSAPI -#include -#include +#include #include #include "rossympriv.h" -#include "pe.h" #include -#include "dwarf.h" - #define NDEBUG #include -#define SYMBOL_SIZE 18 - -extern NTSTATUS RosSymStatus; - BOOLEAN RosSymCreateFromFile(PVOID FileContext, PROSSYM_INFO *RosSymInfo) { - IMAGE_DOS_HEADER DosHeader; - IMAGE_NT_HEADERS NtHeaders; - PIMAGE_SECTION_HEADER SectionHeaders; - unsigned SectionIndex; - unsigned SymbolTable, NumSymbols; + IMAGE_DOS_HEADER DosHeader; + IMAGE_NT_HEADERS NtHeaders; + PIMAGE_SECTION_HEADER SectionHeaders, SectionHeader; + unsigned SectionIndex; + char SectionName[IMAGE_SIZEOF_SHORT_NAME]; + ROSSYM_HEADER RosSymHeader; - /* Load DOS header */ - if (! RosSymSeekFile(FileContext, 0)) + /* Load DOS header */ + if (! RosSymReadFile(FileContext, &DosHeader, sizeof(IMAGE_DOS_HEADER))) { - werrstr("Could not rewind file\n"); - return FALSE; + DPRINT1("Failed to read DOS header\n"); + return FALSE; } - if (! RosSymReadFile(FileContext, &DosHeader, sizeof(IMAGE_DOS_HEADER))) + if (! ROSSYM_IS_VALID_DOS_HEADER(&DosHeader)) { - werrstr("Failed to read DOS header %x\n", RosSymStatus); - return FALSE; - } - if (! ROSSYM_IS_VALID_DOS_HEADER(&DosHeader)) - { - werrstr("Image doesn't have a valid DOS header\n"); - return FALSE; + DPRINT1("Image doesn't have a valid DOS header\n"); + return FALSE; } - /* Load NT headers */ - if (! RosSymSeekFile(FileContext, DosHeader.e_lfanew)) + /* Load NT headers */ + if (! RosSymSeekFile(FileContext, DosHeader.e_lfanew)) { - werrstr("Failed seeking to NT headers\n"); - return FALSE; + DPRINT1("Failed seeking to NT headers\n"); + return FALSE; } - if (! RosSymReadFile(FileContext, &NtHeaders, sizeof(IMAGE_NT_HEADERS))) + if (! RosSymReadFile(FileContext, &NtHeaders, sizeof(IMAGE_NT_HEADERS))) { - werrstr("Failed to read NT headers\n"); - return FALSE; + DPRINT1("Failed to read NT headers\n"); + return FALSE; } - if (! ROSSYM_IS_VALID_NT_HEADERS(&NtHeaders)) + if (! ROSSYM_IS_VALID_NT_HEADERS(&NtHeaders)) { - werrstr("Image doesn't have a valid PE header\n"); - return FALSE; + DPRINT1("Image doesn't have a valid PE header\n"); + return FALSE; } - SymbolTable = NtHeaders.FileHeader.PointerToSymbolTable; - NumSymbols = NtHeaders.FileHeader.NumberOfSymbols; - - if (!NumSymbols) + /* Load section headers */ + if (! RosSymSeekFile(FileContext, (char *) IMAGE_FIRST_SECTION(&NtHeaders) - + (char *) &NtHeaders + DosHeader.e_lfanew)) { - werrstr("Image doesn't have debug symbols\n"); - return FALSE; + DPRINT1("Failed seeking to section headers\n"); + return FALSE; + } + SectionHeaders = RosSymAllocMem(NtHeaders.FileHeader.NumberOfSections + * sizeof(IMAGE_SECTION_HEADER)); + if (NULL == SectionHeaders) + { + DPRINT1("Failed to allocate memory for %u section headers\n", + NtHeaders.FileHeader.NumberOfSections); + return FALSE; + } + if (! RosSymReadFile(FileContext, SectionHeaders, + NtHeaders.FileHeader.NumberOfSections + * sizeof(IMAGE_SECTION_HEADER))) + { + RosSymFreeMem(SectionHeaders); + DPRINT1("Failed to read section headers\n"); + return FALSE; } - DPRINT("SymbolTable %x NumSymbols %x\n", SymbolTable, NumSymbols); - - /* Load section headers */ - if (! RosSymSeekFile(FileContext, (char *) IMAGE_FIRST_SECTION(&NtHeaders) - - (char *) &NtHeaders + DosHeader.e_lfanew)) + /* Search for the section header */ + strncpy(SectionName, ROSSYM_SECTION_NAME, IMAGE_SIZEOF_SHORT_NAME); + SectionHeader = SectionHeaders; + for (SectionIndex = 0; SectionIndex < NtHeaders.FileHeader.NumberOfSections; SectionIndex++) { - werrstr("Failed seeking to section headers\n"); - return FALSE; - } - DPRINT("Alloc section headers\n"); - SectionHeaders = RosSymAllocMem(NtHeaders.FileHeader.NumberOfSections - * sizeof(IMAGE_SECTION_HEADER)); - if (NULL == SectionHeaders) - { - werrstr("Failed to allocate memory for %u section headers\n", - NtHeaders.FileHeader.NumberOfSections); - return FALSE; - } - if (! RosSymReadFile(FileContext, SectionHeaders, - NtHeaders.FileHeader.NumberOfSections - * sizeof(IMAGE_SECTION_HEADER))) - { - RosSymFreeMem(SectionHeaders); - werrstr("Failed to read section headers\n"); - return FALSE; - } - - // Convert names to ANSI_STRINGs - for (SectionIndex = 0; SectionIndex < NtHeaders.FileHeader.NumberOfSections; - SectionIndex++) - { - ANSI_STRING astr; - if (SectionHeaders[SectionIndex].Name[0] != '/') { - DPRINT("Short name string %d, %s\n", SectionIndex, SectionHeaders[SectionIndex].Name); - astr.Buffer = RosSymAllocMem(IMAGE_SIZEOF_SHORT_NAME); - memcpy(astr.Buffer, SectionHeaders[SectionIndex].Name, IMAGE_SIZEOF_SHORT_NAME); - astr.MaximumLength = IMAGE_SIZEOF_SHORT_NAME; - astr.Length = GetStrnlen(astr.Buffer, IMAGE_SIZEOF_SHORT_NAME); - } else { - UNICODE_STRING intConv; - NTSTATUS Status; - ULONG StringOffset; - - Status = RtlCreateUnicodeStringFromAsciiz(&intConv, (PCSZ)SectionHeaders[SectionIndex].Name + 1); - if (!NT_SUCCESS(Status)) goto freeall; - Status = RtlUnicodeStringToInteger(&intConv, 10, &StringOffset); - RtlFreeUnicodeString(&intConv); - if (!NT_SUCCESS(Status)) goto freeall; - if (!RosSymSeekFile(FileContext, SymbolTable + NumSymbols * SYMBOL_SIZE + StringOffset)) - goto freeall; - astr.Buffer = RosSymAllocMem(MAXIMUM_DWARF_NAME_SIZE); - if (!RosSymReadFile(FileContext, astr.Buffer, MAXIMUM_DWARF_NAME_SIZE)) - goto freeall; - astr.Length = GetStrnlen(astr.Buffer, MAXIMUM_DWARF_NAME_SIZE); - astr.MaximumLength = MAXIMUM_DWARF_NAME_SIZE; - DPRINT("Long name %d, %s\n", SectionIndex, astr.Buffer); + if (0 == memcmp(SectionName, SectionHeader->Name, IMAGE_SIZEOF_SHORT_NAME)) + { + break; } - *ANSI_NAME_STRING(&SectionHeaders[SectionIndex]) = astr; + SectionHeader++; + } + if (NtHeaders.FileHeader.NumberOfSections <= SectionIndex) + { + RosSymFreeMem(SectionHeaders); + DPRINT("No %s section found\n", ROSSYM_SECTION_NAME); + return FALSE; } - DPRINT("Done with sections\n"); - Pe *pe = RosSymAllocMem(sizeof(*pe)); - pe->fd = FileContext; - pe->e2 = peget2; - pe->e4 = peget4; - pe->e8 = peget8; - pe->nsections = NtHeaders.FileHeader.NumberOfSections; - pe->sect = SectionHeaders; - pe->imagebase = pe->loadbase = NtHeaders.OptionalHeader.ImageBase; - pe->imagesize = NtHeaders.OptionalHeader.SizeOfImage; - pe->loadsection = loaddisksection; - *RosSymInfo = dwarfopen(pe); + /* Load rossym header */ + if (! RosSymSeekFile(FileContext, SectionHeader->PointerToRawData)) + { + RosSymFreeMem(SectionHeaders); + DPRINT1("Failed seeking to section data\n"); + return FALSE; + } + RosSymFreeMem(SectionHeaders); + if (! RosSymReadFile(FileContext, &RosSymHeader, sizeof(ROSSYM_HEADER))) + { + DPRINT1("Failed to read rossym header\n"); + return FALSE; + } + if (RosSymHeader.SymbolsOffset < sizeof(ROSSYM_HEADER) + || RosSymHeader.StringsOffset < RosSymHeader.SymbolsOffset + RosSymHeader.SymbolsLength + || 0 != (RosSymHeader.SymbolsLength % sizeof(ROSSYM_ENTRY))) + { + DPRINT1("Invalid ROSSYM_HEADER\n"); + return FALSE; + } - return TRUE; + *RosSymInfo = RosSymAllocMem(sizeof(ROSSYM_INFO) - sizeof(ROSSYM_HEADER) + + RosSymHeader.StringsOffset + RosSymHeader.StringsLength + 1); + if (NULL == *RosSymInfo) + { + DPRINT1("Failed to allocate memory for rossym\n"); + return FALSE; + } + (*RosSymInfo)->Symbols = (PROSSYM_ENTRY)((char *) *RosSymInfo + sizeof(ROSSYM_INFO) + - sizeof(ROSSYM_HEADER) + RosSymHeader.SymbolsOffset); + (*RosSymInfo)->SymbolsCount = RosSymHeader.SymbolsLength / sizeof(ROSSYM_ENTRY); + (*RosSymInfo)->Strings = (PCHAR) *RosSymInfo + sizeof(ROSSYM_INFO) - sizeof(ROSSYM_HEADER) + + RosSymHeader.StringsOffset; + (*RosSymInfo)->StringsLength = RosSymHeader.StringsLength; + if (! RosSymReadFile(FileContext, *RosSymInfo + 1, + RosSymHeader.StringsOffset + RosSymHeader.StringsLength + - sizeof(ROSSYM_HEADER))) + { + DPRINT1("Failed to read rossym headers\n"); + return FALSE; + } + /* Make sure the last string is null terminated, we allocated an extra byte for that */ + (*RosSymInfo)->Strings[(*RosSymInfo)->StringsLength] = '\0'; -freeall: - for (SectionIndex = 0; SectionIndex < NtHeaders.FileHeader.NumberOfSections; - SectionIndex++) - RtlFreeAnsiString(ANSI_NAME_STRING(&SectionHeaders[SectionIndex])); - RosSymFreeMem(SectionHeaders); - - return FALSE; + return TRUE; } /* EOF */ diff --git a/lib/rossym/frommem.c b/lib/rossym/frommem.c index 2e201d27a48..f03274eb735 100644 --- a/lib/rossym/frommem.c +++ b/lib/rossym/frommem.c @@ -8,8 +8,7 @@ */ #define NTOSAPI -#include -#include +#include #include #include "rossympriv.h" #include @@ -17,144 +16,76 @@ #define NDEBUG #include -#include "dwarf.h" -#include "pe.h" - BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo) { - ANSI_STRING AnsiNameString = { }; - PIMAGE_DOS_HEADER DosHeader; - PIMAGE_NT_HEADERS NtHeaders; - PIMAGE_SECTION_HEADER SectionHeaders; - ULONG SectionIndex; - unsigned SymbolTable, NumSymbols; - - /* Check if MZ header is valid */ - DosHeader = (PIMAGE_DOS_HEADER) ImageStart; - if (ImageSize < sizeof(IMAGE_DOS_HEADER) - || ! ROSSYM_IS_VALID_DOS_HEADER(DosHeader)) - { - DPRINT1("Image doesn't have a valid DOS header\n"); - return FALSE; - } - - /* Locate NT header */ - NtHeaders = (PIMAGE_NT_HEADERS)((char *) ImageStart + DosHeader->e_lfanew); - if (ImageSize < DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS) - || ! ROSSYM_IS_VALID_NT_HEADERS(NtHeaders)) - { - DPRINT1("Image doesn't have a valid PE header\n"); - return FALSE; - } - - SymbolTable = NtHeaders->FileHeader.PointerToSymbolTable; - NumSymbols = NtHeaders->FileHeader.NumberOfSymbols; - - /* Search for the section header */ - ULONG SectionHeaderSize = NtHeaders->FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER); - SectionHeaders = RosSymAllocMem(SectionHeaderSize); - RtlCopyMemory(SectionHeaders, IMAGE_FIRST_SECTION(NtHeaders), SectionHeaderSize); - - // Convert names to ANSI_STRINGs - for (SectionIndex = 0; SectionIndex < NtHeaders->FileHeader.NumberOfSections; - SectionIndex++) - { - if (SectionHeaders[SectionIndex].Name[0] != '/') { - AnsiNameString.Buffer = RosSymAllocMem(IMAGE_SIZEOF_SHORT_NAME); - RtlCopyMemory(AnsiNameString.Buffer, SectionHeaders[SectionIndex].Name, IMAGE_SIZEOF_SHORT_NAME); - AnsiNameString.MaximumLength = IMAGE_SIZEOF_SHORT_NAME; - AnsiNameString.Length = GetStrnlen(AnsiNameString.Buffer, IMAGE_SIZEOF_SHORT_NAME); - } else { - UNICODE_STRING intConv; - NTSTATUS Status; - ULONG StringOffset; - - Status = RtlCreateUnicodeStringFromAsciiz(&intConv, (PCSZ)SectionHeaders[SectionIndex].Name + 1); - if (!NT_SUCCESS(Status)) goto freeall; - Status = RtlUnicodeStringToInteger(&intConv, 10, &StringOffset); - RtlFreeUnicodeString(&intConv); - if (!NT_SUCCESS(Status)) goto freeall; - ULONG VirtualOffset = pefindrva(SectionHeaders, NtHeaders->FileHeader.NumberOfSections, SymbolTable+(NumSymbols*SYMBOL_SIZE)+StringOffset); - if (!VirtualOffset) goto freeall; - AnsiNameString.Buffer = RosSymAllocMem(MAXIMUM_DWARF_NAME_SIZE); - if (!AnsiNameString.Buffer) goto freeall; - PCHAR StringTarget = ((PCHAR)ImageStart)+VirtualOffset; - PCHAR EndOfImage = ((PCHAR)ImageStart) + NtHeaders->OptionalHeader.SizeOfImage; - if (StringTarget >= EndOfImage) goto freeall; - ULONG PossibleStringLength = EndOfImage - StringTarget; - if (PossibleStringLength > MAXIMUM_DWARF_NAME_SIZE) - PossibleStringLength = MAXIMUM_DWARF_NAME_SIZE; - RtlCopyMemory(AnsiNameString.Buffer, StringTarget, PossibleStringLength); - AnsiNameString.Length = strlen(AnsiNameString.Buffer); - AnsiNameString.MaximumLength = MAXIMUM_DWARF_NAME_SIZE; - } - memcpy - (&SectionHeaders[SectionIndex], - &AnsiNameString, - sizeof(AnsiNameString)); - } - - Pe *pe = RosSymAllocMem(sizeof(*pe)); - pe->fd = ImageStart; - pe->e2 = peget2; - pe->e4 = peget4; - pe->e8 = peget8; - pe->loadbase = (ULONG)ImageStart; - pe->imagebase = NtHeaders->OptionalHeader.ImageBase; - pe->imagesize = NtHeaders->OptionalHeader.SizeOfImage; - pe->nsections = NtHeaders->FileHeader.NumberOfSections; - pe->sect = SectionHeaders; - pe->nsymbols = NtHeaders->FileHeader.NumberOfSymbols; - pe->symtab = malloc(pe->nsymbols * sizeof(CoffSymbol)); - PSYMENT SymbolData = (PSYMENT) - (((PCHAR)ImageStart) + - pefindrva - (pe->sect, - pe->nsections, - NtHeaders->FileHeader.PointerToSymbolTable)); - int i, j; - for (i = 0, j = 0; i < pe->nsymbols; i++) { - if ((SymbolData[i].e_scnum < 1) || - (SymbolData[i].e_sclass != C_EXT && - SymbolData[i].e_sclass != C_STAT)) - continue; - int section = SymbolData[i].e_scnum - 1; - if (SymbolData[i].e.e.e_zeroes) { - pe->symtab[j].name = malloc(sizeof(SymbolData[i].e.e_name)+1); - strcpy(pe->symtab[j].name, SymbolData[i].e.e_name); - } else { - PCHAR SymbolName = ((PCHAR)ImageStart) + - pefindrva - (pe->sect, - pe->nsections, - NtHeaders->FileHeader.PointerToSymbolTable + - (NtHeaders->FileHeader.NumberOfSymbols * 18) + - SymbolData[i].e.e.e_offset); - pe->symtab[j].name = malloc(strlen(SymbolName)+1); - strcpy(pe->symtab[j].name, SymbolName); - } - if (pe->symtab[j].name[0] == '.') { - free(pe->symtab[j].name); - continue; - } - pe->symtab[j].address = pe->sect[section].VirtualAddress + SymbolData[i].e_value; - j++; - } - pe->nsymbols = j; - pe->loadsection = loadmemsection; - *RosSymInfo = dwarfopen(pe); + PIMAGE_DOS_HEADER DosHeader; + PIMAGE_NT_HEADERS NtHeaders; + PIMAGE_SECTION_HEADER SectionHeader; + ULONG SectionIndex; + BOOLEAN RosSymSectionFound = FALSE; + CHAR SectionName[IMAGE_SIZEOF_SHORT_NAME]; - return !!*RosSymInfo; - -freeall: - if (AnsiNameString.Buffer) RosSymFreeMem(AnsiNameString.Buffer); - for (SectionIndex = 0; SectionIndex < NtHeaders->FileHeader.NumberOfSections; - SectionIndex++) - RtlFreeAnsiString(ANSI_NAME_STRING(&SectionHeaders[SectionIndex])); - RosSymFreeMem(SectionHeaders); - - return FALSE; + /* Check if MZ header is valid */ + DosHeader = (PIMAGE_DOS_HEADER) ImageStart; + if (ImageSize < sizeof(IMAGE_DOS_HEADER) + || ! ROSSYM_IS_VALID_DOS_HEADER(DosHeader)) + { + DPRINT1("Image doesn't have a valid DOS header\n"); + return FALSE; + } + + /* Locate NT header */ + NtHeaders = (PIMAGE_NT_HEADERS)((char *) ImageStart + DosHeader->e_lfanew); + if (ImageSize < DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS) + || ! ROSSYM_IS_VALID_NT_HEADERS(NtHeaders)) + { + DPRINT1("Image doesn't have a valid PE header\n"); + return FALSE; + } + + /* Search for the section header */ + SectionHeader = IMAGE_FIRST_SECTION(NtHeaders); + if (ImageSize < (ULONG_PTR)((char *) (SectionHeader + NtHeaders->FileHeader.NumberOfSections) + - (char *) ImageStart)) + { + DPRINT1("Image doesn't have valid section headers\n"); + return FALSE; + } + strncpy(SectionName, ROSSYM_SECTION_NAME, IMAGE_SIZEOF_SHORT_NAME); + for (SectionIndex = 0; SectionIndex < NtHeaders->FileHeader.NumberOfSections; SectionIndex++) + { + if (0 == memcmp(SectionName, SectionHeader->Name, IMAGE_SIZEOF_SHORT_NAME)) + { + RosSymSectionFound = TRUE; + break; + } + SectionHeader++; + } + + if (!RosSymSectionFound) + { + DPRINT("No %s section found\n", ROSSYM_SECTION_NAME); + return FALSE; + } + + /* Locate the section itself */ + if (ImageSize < SectionHeader->PointerToRawData + SectionHeader->SizeOfRawData + || SectionHeader->SizeOfRawData < sizeof(ROSSYM_HEADER)) + { + DPRINT("Invalid %s section\n", ROSSYM_SECTION_NAME); + return FALSE; + } + + if (SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize > ImageSize) + { + DPRINT("Bad %s section virtual size!\n", ROSSYM_SECTION_NAME); + return FALSE; + } + + /* Load it */ + return RosSymCreateFromRaw((char *) ImageStart + SectionHeader->VirtualAddress, + SectionHeader->SizeOfRawData, RosSymInfo); } /* EOF */ diff --git a/lib/rossym/initkm.c b/lib/rossym/initkm.c index 4f1c07111a3..a50680e11da 100644 --- a/lib/rossym/initkm.c +++ b/lib/rossym/initkm.c @@ -38,8 +38,8 @@ RosSymInitKernelMode(VOID) { RosSymAllocMemKM, RosSymFreeMemKM, - RosSymIoReadFile, - RosSymIoSeekFile + RosSymZwReadFile, + RosSymZwSeekFile }; RosSymInit(&KmCallbacks); diff --git a/lib/rossym/initum.c b/lib/rossym/initum.c index eb59c0f185e..c00a13a1e09 100644 --- a/lib/rossym/initum.c +++ b/lib/rossym/initum.c @@ -7,13 +7,9 @@ * PROGRAMMERS: Ge van Geldorp (gvg@reactos.com) */ -#define WIN32_NO_STATUS #include #include #include "rossympriv.h" -#define NTOS_MODE_USER -#include -#include #define NDEBUG #include @@ -21,19 +17,13 @@ static PVOID RosSymAllocMemUM(ULONG_PTR Size) { - return RtlAllocateHeap(RtlGetProcessHeap(), 0, Size); + return HeapAlloc(GetProcessHeap(), 0, Size); } static VOID RosSymFreeMemUM(PVOID Area) { - RtlFreeHeap(RtlGetProcessHeap(), 0, Area); -} - -static BOOLEAN -RosSymGetMemUM(ULONG_PTR *Target, PVOID SourceMem, ULONG Size) -{ - return FALSE; + HeapFree(GetProcessHeap(), 0, Area); } VOID @@ -44,8 +34,7 @@ RosSymInitUserMode(VOID) RosSymAllocMemUM, RosSymFreeMemUM, RosSymZwReadFile, - RosSymZwSeekFile, - RosSymGetMemUM + RosSymZwSeekFile }; RosSymInit(&KmCallbacks); diff --git a/lib/rossym/pe.c b/lib/rossym/pe.c index cace420fec2..a00716cd185 100644 --- a/lib/rossym/pe.c +++ b/lib/rossym/pe.c @@ -111,6 +111,10 @@ void pefree(Pe *pe) { for (i = 0; i < pe->nsections; i++) { RtlFreeAnsiString(ANSI_NAME_STRING(&pe->sect[i])); } + for (i = 0; i < pe->nsymbols; i++) { + free(pe->symtab[i].name); + } + free(pe->symtab); free(pe->sect); free(pe); } diff --git a/lib/rossym/pe.h b/lib/rossym/pe.h index 6b5bbdaa8f4..5e659a216e9 100644 --- a/lib/rossym/pe.h +++ b/lib/rossym/pe.h @@ -6,19 +6,49 @@ struct DwarfBlock; typedef struct _IMAGE_SECTION_HEADER PeSect; +typedef struct _CoffSymbol { + ulong address; + char *name; +} CoffSymbol; + typedef struct _Pe { void *fd; u16int (*e2)(const unsigned char *data); u32int (*e4)(const unsigned char *data); u64int (*e8)(const unsigned char *data); ulong imagebase, imagesize, loadbase; + ulong nsymbols; + CoffSymbol *symtab; int (*loadsection)(struct _Pe *pe, char *name, struct DwarfBlock *b); int nsections; struct _IMAGE_SECTION_HEADER *sect; } Pe; +#define E_SYMNMLEN 8 +#include +typedef struct { + union { + char e_name[E_SYMNMLEN]; + struct { + unsigned long e_zeroes; + unsigned long e_offset; + } e; + } e; + unsigned long e_value; + short e_scnum; + unsigned short e_type; + unsigned char e_sclass; + unsigned char e_numaux; +} SYMENT, *PSYMENT; +#include + +#define C_EXT 2 +#define C_STAT 3 +#define DT_FCN 0x40 + Pe *peopen(const char *name); int loaddisksection(struct _Pe *pe, char *name, struct DwarfBlock *b); +int loadmemsection(struct _Pe *pe, char *name, struct DwarfBlock *b); u16int peget2(const unsigned char *ptr); u32int peget4(const unsigned char *ptr); u64int peget8(const unsigned char *ptr); diff --git a/lib/rossym/rossympriv.h b/lib/rossym/rossympriv.h index 1a604ef3f47..cc3f8ff2ff9 100644 --- a/lib/rossym/rossympriv.h +++ b/lib/rossym/rossympriv.h @@ -9,7 +9,12 @@ #pragma once -#define HIGHBIT 0x80000000 +typedef struct _ROSSYM_INFO { + PROSSYM_ENTRY Symbols; + ULONG SymbolsCount; + PCHAR Strings; + ULONG StringsLength; +} ROSSYM_INFO; extern ROSSYM_CALLBACKS RosSymCallbacks; @@ -17,7 +22,6 @@ extern ROSSYM_CALLBACKS RosSymCallbacks; #define RosSymFreeMem(Area) (*RosSymCallbacks.FreeMemProc)(Area) #define RosSymReadFile(FileContext, Buffer, Size) (*RosSymCallbacks.ReadFileProc)((FileContext), (Buffer), (Size)) #define RosSymSeekFile(FileContext, Position) (*RosSymCallbacks.SeekFileProc)((FileContext), (Position)) -#define RosSymGetMem(TargetAddress, Address, Size) (*RosSymCallbacks.MemGetProc)((TargetAddress), (Address), (Size)) extern BOOLEAN RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size); extern BOOLEAN RosSymZwSeekFile(PVOID FileContext, ULONG_PTR Position); diff --git a/lib/rossym/zwfile.c b/lib/rossym/zwfile.c index a6ce196c632..dc89c3e3157 100644 --- a/lib/rossym/zwfile.c +++ b/lib/rossym/zwfile.c @@ -15,40 +15,38 @@ #define NDEBUG #include -NTSTATUS RosSymStatus; - BOOLEAN RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size) { - //NTSTATUS Status; + NTSTATUS Status; IO_STATUS_BLOCK IoStatusBlock; - RosSymStatus = ZwReadFile(*((HANDLE *) FileContext), + Status = ZwReadFile(*((HANDLE *) FileContext), 0, 0, 0, &IoStatusBlock, Buffer, Size, 0, 0); - return NT_SUCCESS(RosSymStatus) && IoStatusBlock.Information == Size; + return NT_SUCCESS(Status) && IoStatusBlock.Information == Size; } BOOLEAN RosSymZwSeekFile(PVOID FileContext, ULONG_PTR Position) { - //NTSTATUS Status; + NTSTATUS Status; IO_STATUS_BLOCK IoStatusBlock; FILE_POSITION_INFORMATION NewPosition; NewPosition.CurrentByteOffset.u.HighPart = 0; NewPosition.CurrentByteOffset.u.LowPart = Position; - RosSymStatus = ZwSetInformationFile(*((HANDLE *) FileContext), + Status = ZwSetInformationFile(*((HANDLE *) FileContext), &IoStatusBlock, (PVOID) &NewPosition, sizeof(FILE_POSITION_INFORMATION), FilePositionInformation); - return NT_SUCCESS(RosSymStatus); + return NT_SUCCESS(Status); } /* EOF */ diff --git a/lib/sdk/crt/string/atol.c b/lib/sdk/crt/string/atol.c index b66d1767d77..c05a72f8312 100644 --- a/lib/sdk/crt/string/atol.c +++ b/lib/sdk/crt/string/atol.c @@ -9,14 +9,9 @@ long atol(const char *str) return (long)_atoi64(str); } -long _wtol(const wchar_t *str) -{ - return (long)_wtoi64(str); -} - int _atoldbl(_LDOUBLE *value, char *str) { /* FIXME needs error checking for huge/small values */ //*value = strtold(str,0); return -1; -} \ No newline at end of file +} diff --git a/media/inf/syssetup.inf b/media/inf/syssetup.inf index 8aba811299a..817066c8224 100644 --- a/media/inf/syssetup.inf +++ b/media/inf/syssetup.inf @@ -5,6 +5,7 @@ ClassGUID = {00000000-0000-0000-0000-000000000000} [DeviceInfsToInstall] battery.inf cdrom.inf +disk.inf display.inf fdc.inf hdc.inf @@ -14,6 +15,7 @@ msmouse.inf NET_NIC.inf ports.inf scsi.inf +unknown.inf usbport.inf audio.inf ks.inf diff --git a/ntoskrnl/ex/sysinfo.c b/ntoskrnl/ex/sysinfo.c index ca006177891..837c9e6fc41 100644 --- a/ntoskrnl/ex/sysinfo.c +++ b/ntoskrnl/ex/sysinfo.c @@ -1777,11 +1777,15 @@ QSI_DEF(SystemInvalidInfoClass4) /* Class 50 - System range start address */ QSI_DEF(SystemRangeStartInformation) { - /* FIXME */ - DPRINT1("NtQuerySystemInformation - SystemRangeStartInformation not implemented\n"); - return STATUS_NOT_IMPLEMENTED; -} + /* Check user buffer's size */ + if (Size != sizeof(ULONG_PTR)) return STATUS_INFO_LENGTH_MISMATCH; + *(PULONG_PTR)Buffer = (ULONG_PTR)MmSystemRangeStart; + + if (ReqSize) *ReqSize = sizeof(ULONG_PTR); + + return STATUS_SUCCESS; +} /* Class 51 - Driver verifier information */ QSI_DEF(SystemVerifierInformation) diff --git a/ntoskrnl/kdbg/kdb_symbols.c b/ntoskrnl/kdbg/kdb_symbols.c index 7d23f6c8cb4..f54f1cc14c1 100644 --- a/ntoskrnl/kdbg/kdb_symbols.c +++ b/ntoskrnl/kdbg/kdb_symbols.c @@ -13,7 +13,6 @@ #include #define NDEBUG -#include "../cache/section/newmm.h" #include /* GLOBALS ******************************************************************/ @@ -27,61 +26,13 @@ typedef struct _IMAGE_SYMBOL_INFO_CACHE } IMAGE_SYMBOL_INFO_CACHE, *PIMAGE_SYMBOL_INFO_CACHE; -typedef struct _ROSSYM_KM_OWN_CONTEXT { - LARGE_INTEGER FileOffset; - PFILE_OBJECT FileObject; -} ROSSYM_KM_OWN_CONTEXT, *PROSSYM_KM_OWN_CONTEXT; - static BOOLEAN LoadSymbols; static LIST_ENTRY SymbolFileListHead; static KSPIN_LOCK SymbolFileListLock; -static PROSSYM_INFO KdbpRosSymInfo; -static ULONG_PTR KdbpImageBase; BOOLEAN KdbpSymbolsInitialized = FALSE; /* FUNCTIONS ****************************************************************/ -static BOOLEAN -KdbpSeekSymFile(PVOID FileContext, ULONG_PTR Target) -{ - PROSSYM_KM_OWN_CONTEXT Context = (PROSSYM_KM_OWN_CONTEXT)FileContext; - Context->FileOffset.QuadPart = Target; - return TRUE; -} - -static BOOLEAN -KdbpReadSymFile(PVOID FileContext, PVOID Buffer, ULONG Length) -{ - PROSSYM_KM_OWN_CONTEXT Context = (PROSSYM_KM_OWN_CONTEXT)FileContext; - IO_STATUS_BLOCK Iosb; - NTSTATUS Status = MiSimpleRead - (Context->FileObject, - &Context->FileOffset, - Buffer, - Length, - FALSE, - &Iosb); - return NT_SUCCESS(Status); -} - -static PROSSYM_KM_OWN_CONTEXT -KdbpCaptureFileForSymbols(PFILE_OBJECT FileObject) -{ - PROSSYM_KM_OWN_CONTEXT Context = ExAllocatePool(NonPagedPool, sizeof(*Context)); - if (!Context) return NULL; - ObReferenceObject(FileObject); - Context->FileOffset.QuadPart = 0; - Context->FileObject = FileObject; - return Context; -} - -static VOID -KdbpReleaseFileForSymbols(PROSSYM_KM_OWN_CONTEXT Context) -{ - ObDereferenceObject(Context->FileObject); - ExFreePool(Context); -} - static BOOLEAN KdbpSymSearchModuleList( IN PLIST_ENTRY current_entry, @@ -174,142 +125,31 @@ KdbSymPrintAddress( IN PVOID Address, IN PKTRAP_FRAME Context) { - int i; - PMEMORY_AREA MemoryArea = NULL; - PROS_SECTION_OBJECT SectionObject; PLDR_DATA_TABLE_ENTRY LdrEntry; - PROSSYM_KM_OWN_CONTEXT FileContext; ULONG_PTR RelativeAddress; NTSTATUS Status; - ROSSYM_LINEINFO LineInfo = { }; - - struct { - enum _ROSSYM_REGNAME regname; - size_t ctx_offset; - } regmap[] = { - { ROSSYM_X86_EDX, FIELD_OFFSET(KTRAP_FRAME, Edx) }, - { ROSSYM_X86_EAX, FIELD_OFFSET(KTRAP_FRAME, Eax) }, - { ROSSYM_X86_ECX, FIELD_OFFSET(KTRAP_FRAME, Ecx) }, - { ROSSYM_X86_EBX, FIELD_OFFSET(KTRAP_FRAME, Ebx) }, - { ROSSYM_X86_ESI, FIELD_OFFSET(KTRAP_FRAME, Esi) }, - { ROSSYM_X86_EDI, FIELD_OFFSET(KTRAP_FRAME, Edi) }, - { ROSSYM_X86_EBP, FIELD_OFFSET(KTRAP_FRAME, Ebp) }, - { ROSSYM_X86_ESP, FIELD_OFFSET(KTRAP_FRAME, HardwareEsp) } - }; - - if (Context) - { - DPRINT("Has Context %x (EBP %x)\n", Context, Context->Ebp); - LineInfo.Flags = ROSSYM_LINEINFO_HAS_REGISTERS; - - for (i = 0; i < sizeof(regmap) / sizeof(regmap[0]); i++) { - memcpy - (&LineInfo.Registers.Registers[regmap[i].regname], - ((PCHAR)Context)+regmap[i].ctx_offset, - sizeof(ULONG_PTR)); - DPRINT("DWARF REG[%d] -> %x\n", regmap[i].regname, LineInfo.Registers.Registers[regmap[i].regname]); - } - } + ULONG LineNumber; + CHAR FileName[256]; + CHAR FunctionName[256]; if (!KdbpSymbolsInitialized || !KdbpSymFindModule(Address, NULL, -1, &LdrEntry)) return FALSE; RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase; - Status = KdbSymGetAddressInformation - (LdrEntry->PatchInformation, - RelativeAddress, - &LineInfo); - + Status = KdbSymGetAddressInformation(LdrEntry->PatchInformation, + RelativeAddress, + &LineNumber, + FileName, + FunctionName); if (NT_SUCCESS(Status)) { DbgPrint("<%wZ:%x (%s:%d (%s))>", - &LdrEntry->BaseDllName, RelativeAddress, LineInfo.FileName, LineInfo.LineNumber, LineInfo.FunctionName); - if (Context) - { - int i; - char *comma = ""; - DbgPrint("("); - for (i = 0; i < LineInfo.NumParams; i++) { - DbgPrint - ("%s%s=%llx", - comma, - LineInfo.Parameters[i].ValueName, - LineInfo.Parameters[i].Value); - comma = ","; - } - DbgPrint(")"); - } - - return TRUE; + &LdrEntry->BaseDllName, RelativeAddress, FileName, LineNumber, FunctionName); + } + else + { + DbgPrint("<%wZ:%x>", &LdrEntry->BaseDllName, RelativeAddress); } - else if (Address < MmSystemRangeStart) - { - MemoryArea = MmLocateMemoryAreaByAddress(&PsGetCurrentProcess()->Vm, Address); - if (!MemoryArea || MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) - { - goto end; - } - SectionObject = MemoryArea->Data.SectionData.Section; - if (!(SectionObject->AllocationAttributes & SEC_IMAGE)) goto end; - if (MemoryArea->StartingAddress != (PVOID)KdbpImageBase) - { - if (KdbpRosSymInfo) - { - RosSymDelete(KdbpRosSymInfo); - KdbpRosSymInfo = NULL; - KdbpImageBase = 0; - } - - if ((FileContext = KdbpCaptureFileForSymbols(SectionObject->FileObject))) - { - if (RosSymCreateFromFile(FileContext, &KdbpRosSymInfo)) - KdbpImageBase = (ULONG_PTR)MemoryArea->StartingAddress; - - KdbpReleaseFileForSymbols(FileContext); - } - } - - if (KdbpRosSymInfo) - { - RelativeAddress = (ULONG_PTR)Address - KdbpImageBase; - RosSymFreeInfo(&LineInfo); - Status = KdbSymGetAddressInformation - (KdbpRosSymInfo, - RelativeAddress, - &LineInfo); - if (NT_SUCCESS(Status)) - { - DbgPrint - ("<%wZ:%x (%s:%d (%s))>", - &SectionObject->FileObject->FileName, - RelativeAddress, - LineInfo.FileName, - LineInfo.LineNumber, - LineInfo.FunctionName); - - if (Context) - { - int i; - char *comma = ""; - DbgPrint("("); - for (i = 0; i < LineInfo.NumParams; i++) { - DbgPrint - ("%s%s=%llx", - comma, - LineInfo.Parameters[i].ValueName, - LineInfo.Parameters[i].Value); - comma = ","; - } - DbgPrint(")"); - } - - return TRUE; - } - } - } - -end: - DbgPrint("<%wZ:%x>", &LdrEntry->BaseDllName, RelativeAddress); return TRUE; } @@ -335,11 +175,13 @@ NTSTATUS KdbSymGetAddressInformation( IN PROSSYM_INFO RosSymInfo, IN ULONG_PTR RelativeAddress, - IN PROSSYM_LINEINFO LineInfo) + OUT PULONG LineNumber OPTIONAL, + OUT PCH FileName OPTIONAL, + OUT PCH FunctionName OPTIONAL) { if (!KdbpSymbolsInitialized || !RosSymInfo || - !RosSymGetAddressInformation(RosSymInfo, RelativeAddress, LineInfo)) + !RosSymGetAddressInformation(RosSymInfo, RelativeAddress, LineNumber, FileName, FunctionName)) { return STATUS_UNSUCCESSFUL; } @@ -367,6 +209,8 @@ KdbpSymFindCachedFile( PLIST_ENTRY CurrentEntry; KIRQL Irql; + DPRINT("Looking for cached symbol file %wZ\n", FileName); + KeAcquireSpinLock(&SymbolFileListLock, &Irql); CurrentEntry = SymbolFileListHead.Flink; @@ -374,6 +218,7 @@ KdbpSymFindCachedFile( { Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry); + DPRINT("Current->FileName %wZ FileName %wZ\n", &Current->FileName, FileName); if (RtlEqualUnicodeString(&Current->FileName, FileName, TRUE)) { Current->RefCount++; @@ -470,6 +315,7 @@ KdbpSymRemoveCachedFile( } KeReleaseSpinLock(&SymbolFileListLock, Irql); + DPRINT1("Warning: Removing unknown symbol file: RosSymInfo = %p\n", RosSymInfo); } /*! \brief Loads a symbol file. @@ -488,8 +334,6 @@ KdbpSymLoadModuleSymbols( HANDLE FileHandle; NTSTATUS Status; IO_STATUS_BLOCK IoStatusBlock; - PFILE_OBJECT FileObject; - PROSSYM_KM_OWN_CONTEXT FileContext; /* Allow KDB to break on module load */ KdbModuleLoaded(FileName); @@ -511,7 +355,7 @@ KdbpSymLoadModuleSymbols( /* Open the file */ InitializeObjectAttributes(&ObjectAttributes, FileName, - OBJ_CASE_INSENSITIVE, + 0, NULL, NULL); @@ -531,34 +375,20 @@ KdbpSymLoadModuleSymbols( DPRINT("Loading symbols from %wZ...\n", FileName); - Status = ObReferenceObjectByHandle - (FileHandle, - FILE_READ_DATA|SYNCHRONIZE, - NULL, - KernelMode, - (PVOID*)&FileObject, - NULL); - - if (!NT_SUCCESS(Status)) + if (!RosSymCreateFromFile(&FileHandle, RosSymInfo)) { - DPRINT("Could not get the file object\n"); - ZwClose(FileHandle); + DPRINT("Failed to load symbols from %wZ\n", FileName); return; } - if ((FileContext = KdbpCaptureFileForSymbols(FileObject))) - { - if (RosSymCreateFromFile(FileContext, RosSymInfo)) - { - /* add file to cache */ - KdbpSymAddCachedFile(FileName, *RosSymInfo); - DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo); - } - KdbpReleaseFileForSymbols(FileContext); - } - - ObDereferenceObject(FileObject); ZwClose(FileHandle); + + DPRINT("Symbols loaded.\n"); + + /* add file to cache */ + KdbpSymAddCachedFile(FileName, *RosSymInfo); + + DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo); } VOID @@ -575,16 +405,29 @@ KdbSymProcessSymbols( if (LdrEntry->PatchInformation) KdbpSymRemoveCachedFile(LdrEntry->PatchInformation); - /* Error loading symbol info, try to load it from file */ - KdbpSymLoadModuleSymbols(&LdrEntry->FullDllName, + /* Load new symbol information */ + if (! RosSymCreateFromMem(LdrEntry->DllBase, + LdrEntry->SizeOfImage, + (PROSSYM_INFO*)&LdrEntry->PatchInformation)) + { + /* Error loading symbol info, try to load it from file */ + KdbpSymLoadModuleSymbols(&LdrEntry->FullDllName, (PROSSYM_INFO*)&LdrEntry->PatchInformation); - /* It already added symbols to cache */ + /* It already added symbols to cache */ + } + else + { + /* Add file to cache */ + KdbpSymAddCachedFile(&LdrEntry->FullDllName, LdrEntry->PatchInformation); + } + DPRINT("Installed symbols: %wZ@%p-%p %p\n", &LdrEntry->BaseDllName, LdrEntry->DllBase, (PVOID)(LdrEntry->SizeOfImage + (ULONG_PTR)LdrEntry->DllBase), LdrEntry->PatchInformation); + } VOID @@ -596,26 +439,6 @@ KdbDebugPrint( /* Nothing here */ } -static PVOID KdbpSymAllocMem(ULONG_PTR size) -{ - return ExAllocatePoolWithTag(NonPagedPool, size, 'RSYM'); -} - -static VOID KdbpSymFreeMem(PVOID Area) -{ - return ExFreePool(Area); -} - -static BOOLEAN KdbpSymReadMem(PVOID FileContext, PVOID TargetDebug, PVOID SourceMem, ULONG Size) -{ - return NT_SUCCESS(KdbpSafeReadMemory(TargetDebug, SourceMem, Size)); -} - -static ROSSYM_CALLBACKS KdbpRosSymCallbacks = { - KdbpSymAllocMem, KdbpSymFreeMem, - KdbpReadSymFile, KdbpSeekSymFile, - KdbpSymReadMem -}; /*! \brief Initializes the KDB symbols implementation. * @@ -701,9 +524,9 @@ KdbInitialize( p1 = p2; } - RosSymInit(&KdbpRosSymCallbacks); + RosSymInitKernelMode(); } - else if (BootPhase == 3) + else if (BootPhase == 1) { /* Load symbols for NTOSKRNL.EXE. It is always the first module in PsLoadedModuleList. KeLoaderBlock can't be used here as its content is just temporary. */ diff --git a/ntoskrnl/mm/ARM3/vadnode.c b/ntoskrnl/mm/ARM3/vadnode.c index a3aac247bea..0d6fbd6a47c 100644 --- a/ntoskrnl/mm/ARM3/vadnode.c +++ b/ntoskrnl/mm/ARM3/vadnode.c @@ -393,10 +393,11 @@ MiFindEmptyAddressRangeDownTree(IN SIZE_T Length, /* Calculate the initial upper margin */ HighVpn = BoundaryAddress >> PAGE_SHIFT; - /* Starting from the root, go down until the right-most child, - trying to stay below the boundary. */ + /* Starting from the root, go down until the right-most child + * which is just behind the boundary*/ LowestNode = Node = RtlRightChildAvl(&Table->BalancedRoot); - while ((Child = RtlRightChildAvl(Node))) Node = Child; + while (((Child = RtlRightChildAvl(Node)) != 0 ) + && (Node->EndingVpn < HighVpn )) Node = Child; /* Now loop the Vad nodes */ while (Node) diff --git a/ntoskrnl/ntoskrnl.spec b/ntoskrnl/ntoskrnl.spec index d3ccb9b5279..a4d99747be6 100644 --- a/ntoskrnl/ntoskrnl.spec +++ b/ntoskrnl/ntoskrnl.spec @@ -305,7 +305,7 @@ @ extern HalDispatchTable _HalDispatchTable @ fastcall HalExamineMBR(ptr long long ptr) @ extern HalPrivateDispatchTable -;HeadlessDispatch +@ stdcall HeadlessDispatch(long ptr long ptr ptr) @ stdcall InbvAcquireDisplayOwnership() @ stdcall InbvCheckDisplayOwnership() @ stdcall InbvDisplayString(str) diff --git a/subsystems/win32/csrss/csrsrv/api/process.c b/subsystems/win32/csrss/csrsrv/api/process.c index 42174f03c69..c1e7fdb1921 100644 --- a/subsystems/win32/csrss/csrsrv/api/process.c +++ b/subsystems/win32/csrss/csrsrv/api/process.c @@ -105,7 +105,7 @@ PCSRSS_PROCESS_DATA WINAPI CsrCreateProcessData(HANDLE ProcessId) PROCESS_ALL_ACCESS, &ObjectAttributes, &ClientId); - DPRINT1("CSR PRocess: %p Handle: %p\n", pProcessData, pProcessData->Process); + DPRINT1("CSR Process: %p Handle: %p\n", pProcessData, pProcessData->Process); if (!NT_SUCCESS(Status)) { ProcessData[hash] = pProcessData->next; diff --git a/subsystems/win32/csrss/csrsrv/api/wapi.c b/subsystems/win32/csrss/csrsrv/api/wapi.c index 72d4e811022..678cbde92ca 100644 --- a/subsystems/win32/csrss/csrsrv/api/wapi.c +++ b/subsystems/win32/csrss/csrsrv/api/wapi.c @@ -12,8 +12,6 @@ #include -#define NDEBUG - #define NDEBUG #include @@ -181,7 +179,6 @@ CsrSrvCreateSharedSection(IN PCHAR ParameterValue) if (!NT_SUCCESS(Status)) return Status; /* Multiply by 1024 entries and round to page size */ - #define ROUND_UP(n,size) (((ULONG)(n) + (size - 1)) & ~(size - 1)) // hax CsrSrvSharedSectionSize = ROUND_UP(Size * 1024, CsrNtSysInfo.PageSize); DPRINT1("Size: %lx\n", CsrSrvSharedSectionSize); diff --git a/subsystems/win32/csrss/csrsrv/init.c b/subsystems/win32/csrss/csrsrv/init.c index 6ab51c2c546..e0b1a99c094 100644 --- a/subsystems/win32/csrss/csrsrv/init.c +++ b/subsystems/win32/csrss/csrsrv/init.c @@ -514,9 +514,12 @@ CsrpCreateHeap (int argc, char ** argv, char ** envp) Status = CsrSrvCreateSharedSection(Value); - DPRINT1("Status: %lx\n", Status); - ASSERT(Status == STATUS_SUCCESS); - + if (Status != STATUS_SUCCESS) + { + DPRINT1("CsrSrvCreateSharedSection failed with status 0x%08lx\n", Status); + ASSERT(FALSE); + } + BasepFakeStaticServerData(); return STATUS_SUCCESS; } diff --git a/subsystems/win32/csrss/csrsrv/srv.h b/subsystems/win32/csrss/csrsrv/srv.h index b784e6ed575..34d2e4130a8 100644 --- a/subsystems/win32/csrss/csrsrv/srv.h +++ b/subsystems/win32/csrss/csrsrv/srv.h @@ -18,3 +18,7 @@ /* Internal CSRSS Headers */ #include #include + +/* Defines */ +#define ROUND_UP(n, align) ROUND_DOWN(((ULONG)n) + (align) - 1, (align)) +#define ROUND_DOWN(n, align) (((ULONG)n) & ~((align) - 1l)) diff --git a/subsystems/win32/csrss/win32csr/console.c b/subsystems/win32/csrss/win32csr/console.c index 99a622bb3b7..f74cd28168c 100644 --- a/subsystems/win32/csrss/win32csr/console.c +++ b/subsystems/win32/csrss/win32csr/console.c @@ -286,7 +286,7 @@ CSR_API(CsrAllocConsole) FALSE, 0)) { - DPRINT1("DuplicateHandle() failed: %d\n", GetLastError); + DPRINT1("DuplicateHandle() failed: %lu\n", GetLastError()); ConioDeleteConsole((Object_t *) Console); if (NewConsole || !ProcessData->bInheritHandles) { diff --git a/toolchain-msvc.cmake b/toolchain-msvc.cmake index 506fda90155..d46476affd8 100644 --- a/toolchain-msvc.cmake +++ b/toolchain-msvc.cmake @@ -1,26 +1,20 @@ - -# the name of the target operating system -set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_SYSTEM_PROCESSOR i686) - -# which compilers to use for C and C++ -set(CMAKE_C_COMPILER cl) -set(CMAKE_CXX_COMPILER cl) -set(CMAKE_RC_COMPILER rc) -if(${ARCH} MATCHES amd64) - set(CMAKE_ASM_COMPILER ml64) -else() - set(CMAKE_ASM_COMPILER ml) -endif() - -set(CMAKE_RC_COMPILE_OBJECT " /I${REACTOS_SOURCE_DIR}/include/psdk /I${REACTOS_BINARY_DIR}/include/psdk /I${REACTOS_SOURCE_DIR}/include /I${REACTOS_SOURCE_DIR}/include/reactos /I${REACTOS_BINARY_DIR}/include/reactos /I${REACTOS_SOURCE_DIR}/include/reactos/wine /I${REACTOS_SOURCE_DIR}/include/crt /I${REACTOS_SOURCE_DIR}/include/crt/mingw32 /fo ") - -set(CMAKE_ASM_COMPILE_OBJECT - " /nologo /X /I${REACTOS_SOURCE_DIR}/include/asm /I${REACTOS_BINARY_DIR}/include/asm /D__ASM__ /D_USE_ML /EP /c > .tmp" - " /nologo /Cp /Fo /c /Ta .tmp") - -set(CMAKE_C_STANDARD_LIBRARIES "" CACHE INTERNAL "") - -if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86") - add_definitions(-D__i386__) -endif() + +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR i686) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER cl) +set(CMAKE_CXX_COMPILER cl) +set(CMAKE_RC_COMPILER rc) +if(${ARCH} MATCHES amd64) + set(CMAKE_ASM_COMPILER ml64) +else() + set(CMAKE_ASM_COMPILER ml) +endif() + +set(CMAKE_C_STANDARD_LIBRARIES "" CACHE INTERNAL "") + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86") + add_definitions(-D__i386__) +endif() diff --git a/tools/rsym/rsym.c b/tools/rsym/rsym.c new file mode 100644 index 00000000000..50aa2e39c0e --- /dev/null +++ b/tools/rsym/rsym.c @@ -0,0 +1,985 @@ +/* + * Usage: rsym input-file output-file + * + * There are two sources of information: the .stab/.stabstr + * sections of the executable and the COFF symbol table. Most + * of the information is in the .stab/.stabstr sections. + * However, most of our asm files don't contain .stab directives, + * so routines implemented in assembler won't show up in the + * .stab section. They are present in the COFF symbol table. + * So, we mostly use the .stab/.stabstr sections, but we augment + * the info there with info from the COFF symbol table when + * possible. + * + * This is a tool and is compiled using the host compiler, + * i.e. on Linux gcc and not mingw-gcc (cross-compiler). + * Therefore we can't include SDK headers and we have to + * duplicate some definitions here. + * Also note that the internal functions are "old C-style", + * returning an int, where a return of 0 means success and + * non-zero is failure. + */ + +#include +#include +#include +#include + +#include "rsym.h" + +static int +CompareSymEntry(const PROSSYM_ENTRY SymEntry1, const PROSSYM_ENTRY SymEntry2) +{ + if (SymEntry1->Address < SymEntry2->Address) + { + return -1; + } + + if (SymEntry2->Address < SymEntry1->Address) + { + return +1; + } + + return 0; +} + +static int +GetStabInfo(void *FileData, PIMAGE_FILE_HEADER PEFileHeader, + PIMAGE_SECTION_HEADER PESectionHeaders, + ULONG *StabSymbolsLength, void **StabSymbolsBase, + ULONG *StabStringsLength, void **StabStringsBase) +{ + ULONG Idx; + + /* Load .stab and .stabstr sections if available */ + *StabSymbolsBase = NULL; + *StabSymbolsLength = 0; + *StabStringsBase = NULL; + *StabStringsLength = 0; + + for (Idx = 0; Idx < PEFileHeader->NumberOfSections; Idx++) + { + /* printf("section: '%.08s'\n", PESectionHeaders[Idx].Name); */ + if ((strncmp((char*)PESectionHeaders[Idx].Name, ".stab", 5) == 0) + && (PESectionHeaders[Idx].Name[5] == 0)) + { + /* printf(".stab section found. Size %d\n", + PESectionHeaders[Idx].SizeOfRawData); */ + + *StabSymbolsLength = PESectionHeaders[Idx].SizeOfRawData; + *StabSymbolsBase = (void *)((char *) FileData + PESectionHeaders[Idx].PointerToRawData); + } + + if (strncmp((char*)PESectionHeaders[Idx].Name, ".stabstr", 8) == 0) + { + /* printf(".stabstr section found. Size %d\n", + PESectionHeaders[Idx].SizeOfRawData); */ + + *StabStringsLength = PESectionHeaders[Idx].SizeOfRawData; + *StabStringsBase = (void *)((char *) FileData + PESectionHeaders[Idx].PointerToRawData); + } + } + + return 0; +} + +static int +GetCoffInfo(void *FileData, PIMAGE_FILE_HEADER PEFileHeader, + PIMAGE_SECTION_HEADER PESectionHeaders, + ULONG *CoffSymbolsLength, void **CoffSymbolsBase, + ULONG *CoffStringsLength, void **CoffStringsBase) +{ + + if (0 == PEFileHeader->PointerToSymbolTable || 0 == PEFileHeader->NumberOfSymbols) + { + /* No COFF symbol table */ + *CoffSymbolsLength = 0; + *CoffStringsLength = 0; + } + else + { + *CoffSymbolsLength = PEFileHeader->NumberOfSymbols * sizeof(COFF_SYMENT); + *CoffSymbolsBase = (void *)((char *) FileData + PEFileHeader->PointerToSymbolTable); + *CoffStringsLength = *((ULONG *) ((char *) *CoffSymbolsBase + *CoffSymbolsLength)); + *CoffStringsBase = (void *)((char *) *CoffSymbolsBase + *CoffSymbolsLength); + } + + return 0; +} + +static ULONG +FindOrAddString(char *StringToFind, ULONG *StringsLength, void *StringsBase) +{ + char *Search, *End; + + Search = (char *) StringsBase; + End = Search + *StringsLength; + + while (Search < End) + { + if (0 == strcmp(Search, StringToFind)) + { + return Search - (char *) StringsBase; + } + Search += strlen(Search) + 1; + } + + strcpy(Search, StringToFind); + *StringsLength += strlen(StringToFind) + 1; + + return Search - (char *) StringsBase; +} + +static int +ConvertStabs(ULONG *SymbolsCount, PROSSYM_ENTRY *SymbolsBase, + ULONG *StringsLength, void *StringsBase, + ULONG StabSymbolsLength, void *StabSymbolsBase, + ULONG StabStringsLength, void *StabStringsBase, + ULONG_PTR ImageBase, PIMAGE_FILE_HEADER PEFileHeader, + PIMAGE_SECTION_HEADER PESectionHeaders) +{ + PSTAB_ENTRY StabEntry; + ULONG Count, i; + ULONG_PTR Address, LastFunctionAddress; + int First = 1; + char *Name; + ULONG NameLen; + char FuncName[256]; + PROSSYM_ENTRY Current; + + StabEntry = StabSymbolsBase; + Count = StabSymbolsLength / sizeof(STAB_ENTRY); + *SymbolsCount = 0; + if (Count == 0) + { + /* No symbol info */ + *SymbolsBase = NULL; + return 0; + } + + *SymbolsBase = malloc(Count * sizeof(ROSSYM_ENTRY)); + if (NULL == *SymbolsBase) + { + fprintf(stderr, "Failed to allocate memory for converted .stab symbols\n"); + return 1; + } + Current = *SymbolsBase; + memset ( Current, 0, sizeof(*Current) ); + + LastFunctionAddress = 0; + for (i = 0; i < Count; i++) + { + if ( 0 == LastFunctionAddress ) + { + Address = StabEntry[i].n_value - ImageBase; + } + else + { + Address = LastFunctionAddress + StabEntry[i].n_value; + } + switch (StabEntry[i].n_type) + { + case N_SO: + case N_SOL: + case N_BINCL: + Name = (char *) StabStringsBase + StabEntry[i].n_strx; + if (StabStringsLength < StabEntry[i].n_strx + ||'\0' == *Name || '/' == Name[strlen(Name) - 1] + || '\\' == Name[strlen(Name) - 1] + || StabEntry[i].n_value < ImageBase) + { + continue; + } + if ( First || Address != Current->Address ) + { + if ( !First ) + { + memset ( ++Current, 0, sizeof(*Current) ); + Current->FunctionOffset = Current[-1].FunctionOffset; + } + else + First = 0; + Current->Address = Address; + } + Current->FileOffset = FindOrAddString((char *)StabStringsBase + + StabEntry[i].n_strx, + StringsLength, + StringsBase); + break; + case N_FUN: + if (0 == StabEntry[i].n_desc || StabEntry[i].n_value < ImageBase) + { + LastFunctionAddress = 0; /* line # 0 = end of function */ + continue; + } + if ( First || Address != Current->Address ) + { + if ( !First ) + memset ( ++Current, 0, sizeof(*Current) ); + else + First = 0; + Current->Address = Address; + Current->FileOffset = Current[-1].FileOffset; + } + Name = (char *) StabStringsBase + StabEntry[i].n_strx; + NameLen = strcspn(Name, ":"); + if (sizeof(FuncName) <= NameLen) + { + free(*SymbolsBase); + fprintf(stderr, "Function name too long\n"); + return 1; + } + memcpy(FuncName, Name, NameLen); + FuncName[NameLen] = '\0'; + Current->FunctionOffset = FindOrAddString(FuncName, + StringsLength, + StringsBase); + Current->SourceLine = 0; + LastFunctionAddress = Address; + break; + case N_SLINE: + if ( First || Address != Current->Address ) + { + if ( !First ) + { + memset ( ++Current, 0, sizeof(*Current) ); + Current->FileOffset = Current[-1].FileOffset; + Current->FunctionOffset = Current[-1].FunctionOffset; + } + else + First = 0; + Current->Address = Address; + } + Current->SourceLine = StabEntry[i].n_desc; + break; + default: + continue; + } + } + *SymbolsCount = (Current - *SymbolsBase + 1); + + qsort(*SymbolsBase, *SymbolsCount, sizeof(ROSSYM_ENTRY), (int (*)(const void *, const void *)) CompareSymEntry); + + return 0; +} + +static int +ConvertCoffs(ULONG *SymbolsCount, PROSSYM_ENTRY *SymbolsBase, + ULONG *StringsLength, void *StringsBase, + ULONG CoffSymbolsLength, void *CoffSymbolsBase, + ULONG CoffStringsLength, void *CoffStringsBase, + ULONG_PTR ImageBase, PIMAGE_FILE_HEADER PEFileHeader, + PIMAGE_SECTION_HEADER PESectionHeaders) +{ + ULONG Count, i; + PCOFF_SYMENT CoffEntry; + char FuncName[256]; + char *p; + PROSSYM_ENTRY Current; + + CoffEntry = (PCOFF_SYMENT) CoffSymbolsBase; + Count = CoffSymbolsLength / sizeof(COFF_SYMENT); + *SymbolsBase = malloc(Count * sizeof(ROSSYM_ENTRY)); + if (NULL == *SymbolsBase) + { + fprintf(stderr, "Unable to allocate memory for converted COFF symbols\n"); + return 1; + } + *SymbolsCount = 0; + Current = *SymbolsBase; + + for (i = 0; i < Count; i++) + { + if (ISFCN(CoffEntry[i].e_type) || C_EXT == CoffEntry[i].e_sclass) + { + Current->Address = CoffEntry[i].e_value; + if (0 < CoffEntry[i].e_scnum) + { + if (PEFileHeader->NumberOfSections < CoffEntry[i].e_scnum) + { + free(*SymbolsBase); + fprintf(stderr, "Invalid section number %d in COFF symbols (only %d sections present)\n", + CoffEntry[i].e_scnum, PEFileHeader->NumberOfSections); + return 1; + } + Current->Address += PESectionHeaders[CoffEntry[i].e_scnum - 1].VirtualAddress; + } + Current->FileOffset = 0; + if (0 == CoffEntry[i].e.e.e_zeroes) + { + if (sizeof(FuncName) <= strlen((char *) CoffStringsBase + CoffEntry[i].e.e.e_offset)) + { + free(*SymbolsBase); + fprintf(stderr, "Function name too long\n"); + return 1; + } + strcpy(FuncName, (char *) CoffStringsBase + CoffEntry[i].e.e.e_offset); + } + else + { + memcpy(FuncName, CoffEntry[i].e.e_name, E_SYMNMLEN); + FuncName[E_SYMNMLEN] = '\0'; + } + + /* Name demangling: stdcall */ + p = strrchr(FuncName, '@'); + if (NULL != p) + { + *p = '\0'; + } + p = ('_' == FuncName[0] || '@' == FuncName[0] ? FuncName + 1 : FuncName); + Current->FunctionOffset = FindOrAddString(p, + StringsLength, + StringsBase); + Current->SourceLine = 0; + memset ( ++Current, 0, sizeof(*Current) ); + } + i += CoffEntry[i].e_numaux; + } + + *SymbolsCount = (Current - *SymbolsBase + 1); + qsort(*SymbolsBase, *SymbolsCount, sizeof(ROSSYM_ENTRY), (int (*)(const void *, const void *)) CompareSymEntry); + + return 0; +} + +static int +MergeStabsAndCoffs(ULONG *MergedSymbolCount, PROSSYM_ENTRY *MergedSymbols, + ULONG StabSymbolsCount, PROSSYM_ENTRY StabSymbols, + ULONG CoffSymbolsCount, PROSSYM_ENTRY CoffSymbols) +{ + ULONG StabIndex, j; + ULONG CoffIndex; + ULONG_PTR StabFunctionStartAddress; + ULONG StabFunctionStringOffset, NewStabFunctionStringOffset; + + *MergedSymbolCount = 0; + if (StabSymbolsCount == 0) + { + *MergedSymbols = NULL; + return 0; + } + *MergedSymbols = malloc(StabSymbolsCount * sizeof(ROSSYM_ENTRY)); + if (NULL == *MergedSymbols) + { + fprintf(stderr, "Unable to allocate memory for merged symbols\n"); + return 1; + } + + StabFunctionStartAddress = 0; + StabFunctionStringOffset = 0; + CoffIndex = 0; + for (StabIndex = 0; StabIndex < StabSymbolsCount; StabIndex++) + { + (*MergedSymbols)[*MergedSymbolCount] = StabSymbols[StabIndex]; + for (j = StabIndex + 1; + j < StabSymbolsCount && StabSymbols[j].Address == StabSymbols[StabIndex].Address; + j++) + { + if (0 != StabSymbols[j].FileOffset && 0 == (*MergedSymbols)[*MergedSymbolCount].FileOffset) + { + (*MergedSymbols)[*MergedSymbolCount].FileOffset = StabSymbols[j].FileOffset; + } + if (0 != StabSymbols[j].FunctionOffset && 0 == (*MergedSymbols)[*MergedSymbolCount].FunctionOffset) + { + (*MergedSymbols)[*MergedSymbolCount].FunctionOffset = StabSymbols[j].FunctionOffset; + } + if (0 != StabSymbols[j].SourceLine && 0 == (*MergedSymbols)[*MergedSymbolCount].SourceLine) + { + (*MergedSymbols)[*MergedSymbolCount].SourceLine = StabSymbols[j].SourceLine; + } + } + StabIndex = j - 1; + while (CoffIndex < CoffSymbolsCount + && CoffSymbols[CoffIndex + 1].Address <= (*MergedSymbols)[*MergedSymbolCount].Address) + { + CoffIndex++; + } + NewStabFunctionStringOffset = (*MergedSymbols)[*MergedSymbolCount].FunctionOffset; + if (CoffSymbolsCount > 0 && + CoffSymbols[CoffIndex].Address < (*MergedSymbols)[*MergedSymbolCount].Address + && StabFunctionStartAddress < CoffSymbols[CoffIndex].Address + && 0 != CoffSymbols[CoffIndex].FunctionOffset) + { + (*MergedSymbols)[*MergedSymbolCount].FunctionOffset = CoffSymbols[CoffIndex].FunctionOffset; + } + if (StabFunctionStringOffset != NewStabFunctionStringOffset) + { + StabFunctionStartAddress = (*MergedSymbols)[*MergedSymbolCount].Address; + } + StabFunctionStringOffset = NewStabFunctionStringOffset; + (*MergedSymbolCount)++; + } + + return 0; +} + +static PIMAGE_SECTION_HEADER +FindSectionForRVA(DWORD RVA, unsigned NumberOfSections, PIMAGE_SECTION_HEADER SectionHeaders) +{ + unsigned Section; + + for (Section = 0; Section < NumberOfSections; Section++) + { + if (SectionHeaders[Section].VirtualAddress <= RVA && + RVA < SectionHeaders[Section].VirtualAddress + SectionHeaders[Section].Misc.VirtualSize) + { + return SectionHeaders + Section; + } + } + + return NULL; +} + +static int +IncludeRelocationsForSection(PIMAGE_SECTION_HEADER SectionHeader) +{ + static char *BlacklistedSections[] = + { + ".edata", + ".idata", + ".reloc" + }; + char SectionName[IMAGE_SIZEOF_SHORT_NAME]; + unsigned i; + + if (0 != (SectionHeader->Characteristics & IMAGE_SCN_LNK_REMOVE)) + { + return 0; + } + + for (i = 0; i < sizeof(BlacklistedSections) / sizeof(BlacklistedSections[0]); i++) + { + strncpy(SectionName, BlacklistedSections[i], IMAGE_SIZEOF_SHORT_NAME); + if (0 == memcmp(SectionName, SectionHeader->Name, IMAGE_SIZEOF_SHORT_NAME)) + { + return 0; + } + } + + return 1; +} + +static int +ProcessRelocations(ULONG *ProcessedRelocsLength, void **ProcessedRelocs, + void *RawData, PIMAGE_OPTIONAL_HEADER OptHeader, + unsigned NumberOfSections, PIMAGE_SECTION_HEADER SectionHeaders) +{ + PIMAGE_SECTION_HEADER RelocSectionHeader, TargetSectionHeader; + PIMAGE_BASE_RELOCATION BaseReloc, End, AcceptedRelocs; + int Found; + + if (OptHeader->NumberOfRvaAndSizes < IMAGE_DIRECTORY_ENTRY_BASERELOC + || 0 == OptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress) + { + /* No relocation entries */ + *ProcessedRelocsLength = 0; + *ProcessedRelocs = NULL; + return 0; + } + + RelocSectionHeader = FindSectionForRVA(OptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress, + NumberOfSections, SectionHeaders); + if (NULL == RelocSectionHeader) + { + fprintf(stderr, "Can't find section header for relocation data\n"); + return 1; + } + + *ProcessedRelocs = malloc(RelocSectionHeader->SizeOfRawData); + if (NULL == *ProcessedRelocs) + { + fprintf(stderr, "Failed to allocate %u bytes for relocations\n", (unsigned int)RelocSectionHeader->SizeOfRawData); + return 1; + } + *ProcessedRelocsLength = 0; + + BaseReloc = (PIMAGE_BASE_RELOCATION) ((char *) RawData + + RelocSectionHeader->PointerToRawData + + (OptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress - + RelocSectionHeader->VirtualAddress)); + End = (PIMAGE_BASE_RELOCATION) ((char *) BaseReloc + + OptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size); + + while (BaseReloc < End && 0 < BaseReloc->SizeOfBlock) + { + TargetSectionHeader = FindSectionForRVA(BaseReloc->VirtualAddress, NumberOfSections, + SectionHeaders); + if (NULL != TargetSectionHeader && IncludeRelocationsForSection(TargetSectionHeader)) + { + AcceptedRelocs = *ProcessedRelocs; + Found = 0; + while (AcceptedRelocs < (PIMAGE_BASE_RELOCATION) ((char *) *ProcessedRelocs + + *ProcessedRelocsLength) + && ! Found) + { + Found = BaseReloc->SizeOfBlock == AcceptedRelocs->SizeOfBlock + && 0 == memcmp(BaseReloc, AcceptedRelocs, AcceptedRelocs->SizeOfBlock); + AcceptedRelocs= (PIMAGE_BASE_RELOCATION) ((char *) AcceptedRelocs + + AcceptedRelocs->SizeOfBlock); + } + if (! Found) + { + memcpy((char *) *ProcessedRelocs + *ProcessedRelocsLength, + BaseReloc, BaseReloc->SizeOfBlock); + *ProcessedRelocsLength += BaseReloc->SizeOfBlock; + } + } + BaseReloc = (PIMAGE_BASE_RELOCATION)((char *) BaseReloc + BaseReloc->SizeOfBlock); + } + + return 0; +} + +static int +CreateOutputFile(FILE *OutFile, void *InData, + PIMAGE_DOS_HEADER InDosHeader, PIMAGE_FILE_HEADER InFileHeader, + PIMAGE_OPTIONAL_HEADER InOptHeader, PIMAGE_SECTION_HEADER InSectionHeaders, + ULONG RosSymLength, void *RosSymSection) +{ + ULONG StartOfRawData; + unsigned Section; + void *OutHeader, *ProcessedRelocs, *PaddedRosSym, *Data; + PIMAGE_DOS_HEADER OutDosHeader; + PIMAGE_FILE_HEADER OutFileHeader; + PIMAGE_OPTIONAL_HEADER OutOptHeader; + PIMAGE_SECTION_HEADER OutSectionHeaders, CurrentSectionHeader; + DWORD CheckSum; + ULONG Length, i; + ULONG ProcessedRelocsLength; + ULONG RosSymOffset, RosSymFileLength; + int InRelocSectionIndex; + PIMAGE_SECTION_HEADER OutRelocSection; + + StartOfRawData = 0; + for (Section = 0; Section < InFileHeader->NumberOfSections; Section++) + { + if ((0 == StartOfRawData + || InSectionHeaders[Section].PointerToRawData < StartOfRawData) + && 0 != InSectionHeaders[Section].PointerToRawData + && 0 == (InSectionHeaders[Section].Characteristics & IMAGE_SCN_LNK_REMOVE)) + { + StartOfRawData = InSectionHeaders[Section].PointerToRawData; + } + } + OutHeader = malloc(StartOfRawData); + if (NULL == OutHeader) + { + fprintf(stderr, "Failed to allocate %u bytes for output file header\n", (unsigned int)StartOfRawData); + return 1; + } + memset(OutHeader, '\0', StartOfRawData); + + OutDosHeader = (PIMAGE_DOS_HEADER) OutHeader; + memcpy(OutDosHeader, InDosHeader, InDosHeader->e_lfanew + sizeof(ULONG)); + + OutFileHeader = (PIMAGE_FILE_HEADER)((char *) OutHeader + OutDosHeader->e_lfanew + sizeof(ULONG)); + memcpy(OutFileHeader, InFileHeader, sizeof(IMAGE_FILE_HEADER)); + OutFileHeader->PointerToSymbolTable = 0; + OutFileHeader->NumberOfSymbols = 0; + OutFileHeader->Characteristics &= ~(IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_LOCAL_SYMS_STRIPPED | + IMAGE_FILE_DEBUG_STRIPPED); + + OutOptHeader = (PIMAGE_OPTIONAL_HEADER)(OutFileHeader + 1); + memcpy(OutOptHeader, InOptHeader, sizeof(IMAGE_OPTIONAL_HEADER)); + OutOptHeader->CheckSum = 0; + + OutSectionHeaders = (PIMAGE_SECTION_HEADER)((char *) OutOptHeader + OutFileHeader->SizeOfOptionalHeader); + + if (ProcessRelocations(&ProcessedRelocsLength, &ProcessedRelocs, InData, InOptHeader, + InFileHeader->NumberOfSections, InSectionHeaders)) + { + return 1; + } + if (InOptHeader->NumberOfRvaAndSizes < IMAGE_DIRECTORY_ENTRY_BASERELOC + || 0 == InOptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress) + { + InRelocSectionIndex = -1; + } + else + { + InRelocSectionIndex = FindSectionForRVA(InOptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress, + InFileHeader->NumberOfSections, InSectionHeaders) - InSectionHeaders; + } + + OutFileHeader->NumberOfSections = 0; + CurrentSectionHeader = OutSectionHeaders; + OutOptHeader->SizeOfImage = 0; + RosSymOffset = 0; + OutRelocSection = NULL; + for (Section = 0; Section < InFileHeader->NumberOfSections; Section++) + { + if (0 == (InSectionHeaders[Section].Characteristics & IMAGE_SCN_LNK_REMOVE)) + { + *CurrentSectionHeader = InSectionHeaders[Section]; + CurrentSectionHeader->PointerToLinenumbers = 0; + CurrentSectionHeader->NumberOfLinenumbers = 0; + if (OutOptHeader->SizeOfImage < CurrentSectionHeader->VirtualAddress + + CurrentSectionHeader->Misc.VirtualSize) + { + OutOptHeader->SizeOfImage = ROUND_UP(CurrentSectionHeader->VirtualAddress + + CurrentSectionHeader->Misc.VirtualSize, + OutOptHeader->SectionAlignment); + } + if (RosSymOffset < CurrentSectionHeader->PointerToRawData + CurrentSectionHeader->SizeOfRawData) + { + RosSymOffset = CurrentSectionHeader->PointerToRawData + CurrentSectionHeader->SizeOfRawData; + } + if (Section == (ULONG)InRelocSectionIndex) + { + OutRelocSection = CurrentSectionHeader; + } + (OutFileHeader->NumberOfSections) ++; + CurrentSectionHeader++; + } + } + + if (OutRelocSection == CurrentSectionHeader - 1) + { + OutOptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = ProcessedRelocsLength; + if (OutOptHeader->SizeOfImage == OutRelocSection->VirtualAddress + + ROUND_UP(OutRelocSection->Misc.VirtualSize, + OutOptHeader->SectionAlignment)) + { + OutOptHeader->SizeOfImage = OutRelocSection->VirtualAddress + + ROUND_UP(ProcessedRelocsLength, + OutOptHeader->SectionAlignment); + } + OutRelocSection->Misc.VirtualSize = ProcessedRelocsLength; + if (RosSymOffset == OutRelocSection->PointerToRawData + + OutRelocSection->SizeOfRawData) + { + RosSymOffset = OutRelocSection->PointerToRawData + + ROUND_UP(ProcessedRelocsLength, OutOptHeader->FileAlignment); + } + OutRelocSection->SizeOfRawData = ROUND_UP(ProcessedRelocsLength, + OutOptHeader->FileAlignment); + } + + if (RosSymLength > 0) + { + RosSymFileLength = ROUND_UP(RosSymLength, OutOptHeader->FileAlignment); + memcpy(CurrentSectionHeader->Name, ".rossym", 8); /* We're lucky: string is exactly 8 bytes long */ + CurrentSectionHeader->Misc.VirtualSize = RosSymLength; + CurrentSectionHeader->VirtualAddress = OutOptHeader->SizeOfImage; + CurrentSectionHeader->SizeOfRawData = RosSymFileLength; + CurrentSectionHeader->PointerToRawData = RosSymOffset; + CurrentSectionHeader->PointerToRelocations = 0; + CurrentSectionHeader->PointerToLinenumbers = 0; + CurrentSectionHeader->NumberOfRelocations = 0; + CurrentSectionHeader->NumberOfLinenumbers = 0; + CurrentSectionHeader->Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE + | IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_TYPE_NOLOAD; + OutOptHeader->SizeOfImage = ROUND_UP(CurrentSectionHeader->VirtualAddress + + CurrentSectionHeader->Misc.VirtualSize, + OutOptHeader->SectionAlignment); + (OutFileHeader->NumberOfSections)++; + + PaddedRosSym = malloc(RosSymFileLength); + if (NULL == PaddedRosSym) + { + fprintf(stderr, "Failed to allocate %u bytes for padded .rossym\n", (unsigned int)RosSymFileLength); + return 1; + } + memcpy(PaddedRosSym, RosSymSection, RosSymLength); + memset((char *) PaddedRosSym + RosSymLength, '\0', RosSymFileLength - RosSymLength); + } + else + { + PaddedRosSym = NULL; + } + CheckSum = 0; + for (i = 0; i < StartOfRawData / 2; i++) + { + CheckSum += ((unsigned short*) OutHeader)[i]; + CheckSum = 0xffff & (CheckSum + (CheckSum >> 16)); + } + Length = StartOfRawData; + for (Section = 0; Section < OutFileHeader->NumberOfSections; Section++) + { + DWORD SizeOfRawData; + if (OutRelocSection == OutSectionHeaders + Section) + { + Data = (void *) ProcessedRelocs; + SizeOfRawData = ProcessedRelocsLength; + } + else if (RosSymLength > 0 && Section + 1 == OutFileHeader->NumberOfSections) + { + Data = (void *) PaddedRosSym; + SizeOfRawData = OutSectionHeaders[Section].SizeOfRawData; + } + else + { + Data = (void *) ((char *) InData + OutSectionHeaders[Section].PointerToRawData); + SizeOfRawData = OutSectionHeaders[Section].SizeOfRawData; + } + for (i = 0; i < SizeOfRawData / 2; i++) + { + CheckSum += ((unsigned short*) Data)[i]; + CheckSum = 0xffff & (CheckSum + (CheckSum >> 16)); + } + Length += OutSectionHeaders[Section].SizeOfRawData; + } + CheckSum += Length; + OutOptHeader->CheckSum = CheckSum; + + if (fwrite(OutHeader, 1, StartOfRawData, OutFile) != StartOfRawData) + { + perror("Error writing output header\n"); + free(OutHeader); + return 1; + } + + for (Section = 0; Section < OutFileHeader->NumberOfSections; Section++) + { + if (0 != OutSectionHeaders[Section].SizeOfRawData) + { + DWORD SizeOfRawData; + fseek(OutFile, OutSectionHeaders[Section].PointerToRawData, SEEK_SET); + if (OutRelocSection == OutSectionHeaders + Section) + { + Data = (void *) ProcessedRelocs; + SizeOfRawData = ProcessedRelocsLength; + } + else if (RosSymLength > 0 && Section + 1 == OutFileHeader->NumberOfSections) + { + Data = (void *) PaddedRosSym; + SizeOfRawData = OutSectionHeaders[Section].SizeOfRawData; + } + else + { + Data = (void *) ((char *) InData + OutSectionHeaders[Section].PointerToRawData); + SizeOfRawData = OutSectionHeaders[Section].SizeOfRawData; + } + if (fwrite(Data, 1, SizeOfRawData, OutFile) != SizeOfRawData) + { + perror("Error writing section data\n"); + free(PaddedRosSym); + free(OutHeader); + return 1; + } + } + } + + if (PaddedRosSym) + { + free(PaddedRosSym); + } + free(OutHeader); + + return 0; +} + +int main(int argc, char* argv[]) +{ + PSYMBOLFILE_HEADER SymbolFileHeader; + PIMAGE_DOS_HEADER PEDosHeader; + PIMAGE_FILE_HEADER PEFileHeader; + PIMAGE_OPTIONAL_HEADER PEOptHeader; + PIMAGE_SECTION_HEADER PESectionHeaders; + ULONG ImageBase; + void *StabBase; + ULONG StabsLength; + void *StabStringBase; + ULONG StabStringsLength; + void *CoffBase = NULL; + ULONG CoffsLength; + void *CoffStringBase = NULL; + ULONG CoffStringsLength; + char* path1; + char* path2; + FILE* out; + void *StringBase; + ULONG StringsLength; + ULONG StabSymbolsCount; + PROSSYM_ENTRY StabSymbols; + ULONG CoffSymbolsCount; + PROSSYM_ENTRY CoffSymbols; + ULONG MergedSymbolsCount; + PROSSYM_ENTRY MergedSymbols; + size_t FileSize; + void *FileData; + ULONG RosSymLength; + void *RosSymSection; + char elfhdr[4] = { '\177', 'E', 'L', 'F' }; + + if (3 != argc) + { + fprintf(stderr, "Usage: rsym \n"); + exit(1); + } + + path1 = convert_path(argv[1]); + path2 = convert_path(argv[2]); + + FileData = load_file ( path1, &FileSize ); + if ( !FileData ) + { + fprintf ( stderr, "An error occured loading '%s'\n", path1 ); + exit(1); + } + + /* Check if MZ header exists */ + PEDosHeader = (PIMAGE_DOS_HEADER) FileData; + if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || PEDosHeader->e_lfanew == 0L) + { + /* Ignore elf */ + if (!memcmp(PEDosHeader, elfhdr, sizeof(elfhdr))) + exit(0); + perror("Input file is not a PE image.\n"); + free(FileData); + exit(1); + } + + /* Locate PE file header */ + /* sizeof(ULONG) = sizeof(MAGIC) */ + PEFileHeader = (PIMAGE_FILE_HEADER)((char *) FileData + PEDosHeader->e_lfanew + sizeof(ULONG)); + + /* Locate optional header */ + assert(sizeof(ULONG) == 4); + PEOptHeader = (PIMAGE_OPTIONAL_HEADER)(PEFileHeader + 1); + ImageBase = PEOptHeader->ImageBase; + + /* Locate PE section headers */ + PESectionHeaders = (PIMAGE_SECTION_HEADER)((char *) PEOptHeader + PEFileHeader->SizeOfOptionalHeader); + + if (GetStabInfo(FileData, PEFileHeader, PESectionHeaders, &StabsLength, &StabBase, + &StabStringsLength, &StabStringBase)) + { + free(FileData); + exit(1); + } + + if (GetCoffInfo(FileData, PEFileHeader, PESectionHeaders, &CoffsLength, &CoffBase, + &CoffStringsLength, &CoffStringBase)) + { + free(FileData); + exit(1); + } + + StringBase = malloc(1 + StabStringsLength + CoffStringsLength + + (CoffsLength / sizeof(ROSSYM_ENTRY)) * (E_SYMNMLEN + 1)); + if (NULL == StringBase) + { + free(FileData); + fprintf(stderr, "Failed to allocate memory for strings table\n"); + exit(1); + } + /* Make offset 0 into an empty string */ + *((char *) StringBase) = '\0'; + StringsLength = 1; + + if (ConvertStabs(&StabSymbolsCount, &StabSymbols, &StringsLength, StringBase, + StabsLength, StabBase, StabStringsLength, StabStringBase, + ImageBase, PEFileHeader, PESectionHeaders)) + { + free(StringBase); + free(FileData); + fprintf(stderr, "Failed to allocate memory for strings table\n"); + exit(1); + } + + if (ConvertCoffs(&CoffSymbolsCount, &CoffSymbols, &StringsLength, StringBase, + CoffsLength, CoffBase, CoffStringsLength, CoffStringBase, + ImageBase, PEFileHeader, PESectionHeaders)) + { + if (StabSymbols) + { + free(StabSymbols); + } + free(StringBase); + free(FileData); + exit(1); + } + + if (MergeStabsAndCoffs(&MergedSymbolsCount, &MergedSymbols, + StabSymbolsCount, StabSymbols, + CoffSymbolsCount, CoffSymbols)) + { + if (CoffSymbols) + { + free(CoffSymbols); + } + if (StabSymbols) + { + free(StabSymbols); + } + free(StringBase); + free(FileData); + exit(1); + } + + if (CoffSymbols) + { + free(CoffSymbols); + } + if (StabSymbols) + { + free(StabSymbols); + } + if (MergedSymbolsCount == 0) + { + RosSymLength = 0; + RosSymSection = NULL; + } + else + { + RosSymLength = sizeof(SYMBOLFILE_HEADER) + MergedSymbolsCount * sizeof(ROSSYM_ENTRY) + + StringsLength; + RosSymSection = malloc(RosSymLength); + if (NULL == RosSymSection) + { + free(MergedSymbols); + free(StringBase); + free(FileData); + fprintf(stderr, "Unable to allocate memory for .rossym section\n"); + exit(1); + } + memset(RosSymSection, '\0', RosSymLength); + + SymbolFileHeader = (PSYMBOLFILE_HEADER) RosSymSection; + SymbolFileHeader->SymbolsOffset = sizeof(SYMBOLFILE_HEADER); + SymbolFileHeader->SymbolsLength = MergedSymbolsCount * sizeof(ROSSYM_ENTRY); + SymbolFileHeader->StringsOffset = SymbolFileHeader->SymbolsOffset + SymbolFileHeader->SymbolsLength; + SymbolFileHeader->StringsLength = StringsLength; + + memcpy((char *) RosSymSection + SymbolFileHeader->SymbolsOffset, MergedSymbols, + SymbolFileHeader->SymbolsLength); + memcpy((char *) RosSymSection + SymbolFileHeader->StringsOffset, StringBase, + SymbolFileHeader->StringsLength); + + free(MergedSymbols); + } + free(StringBase); + out = fopen(path2, "wb"); + if (out == NULL) + { + perror("Cannot open output file"); + free(RosSymSection); + free(FileData); + exit(1); + } + + if (CreateOutputFile(out, FileData, PEDosHeader, PEFileHeader, PEOptHeader, + PESectionHeaders, RosSymLength, RosSymSection)) + { + fclose(out); + if (RosSymSection) + { + free(RosSymSection); + } + free(FileData); + exit(1); + } + + fclose(out); + if (RosSymSection) + { + free(RosSymSection); + } + free(FileData); + + return 0; +} + +/* EOF */