Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

316 lines
11 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM ntrebase.cmd - BryanT
  4. @REM rebase NT binaries
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @if defined _CPCMAGIC goto CPCBegin
  10. @perl -x "%~f0" %*
  11. @goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use ParseArgs;
  18. use Logmsg;
  19. sub Usage { print<<USAGE; exit(1) }
  20. ntrebase [-l <language>]
  21. Rebase NT binaries
  22. USAGE
  23. sub Dependencies {
  24. if ( !open DEPEND, ">>$ENV{_NTPOSTBLD}\\..\\build_logs\\dependencies.txt" ) {
  25. errmsg("Unable to open dependency list file.");
  26. die;
  27. }
  28. print DEPEND<<DEPENDENCIES;
  29. \[$0\]
  30. IF {...} ADD {}
  31. DEPENDENCIES
  32. close DEPEND;
  33. exit;
  34. }
  35. my $qfe;
  36. parseargs('?' => \&Usage,
  37. 'plan' => \&Dependencies,
  38. 'qfe:' => \$qfe);
  39. if ( -f "$ENV{_NTPOSTBLD}\\..\\build_logs\\skip.txt" ) {
  40. if ( !open SKIP, "$ENV{_NTPOSTBLD}\\..\\build_logs\\skip.txt" ) {
  41. errmsg("Unable to open skip list file.");
  42. die;
  43. }
  44. while (<SKIP>) {
  45. chomp;
  46. exit if lc$_ eq lc$0;
  47. }
  48. close SKIP;
  49. }
  50. # *** TEMPLATE CODE ***
  51. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  52. __END__
  53. @:CPCBegin
  54. @set _CPCMAGIC=
  55. @setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  56. @if not defined DEBUG echo off
  57. @REM *** CMD SCRIPT BELOW ***
  58. set DO_WOW6432=FALSE
  59. set REBASE_OS_HIGH=FALSE
  60. set _REBASE_FLAGS=%_NTREBASE_FLAGS%
  61. if not "%_REBASE_FLAGS%" == "" echo Using flags from _NTREBASE_FLAGS == "%_NTREBASE_FLAGS%"
  62. if "%_REBASE_FLAGS%" == "" set _REBASE_FLAGS=-v
  63. if not "%1" == "" set _REBASE_FLAGS=%1 %2 %3 %4 %5 %6 %7 %8 %9
  64. if "%_NTPostBld%" == "" echo _NTPostBld not defined && goto :EOF
  65. set _TREE=%_NTPostBld%
  66. if not "!386!"=="" goto X86
  67. if not "!IA64!"=="" goto IA64
  68. if not "!AMD64!"=="" goto AMD64
  69. echo Unknown Build Architecture
  70. goto :EOF
  71. :X86
  72. set _SESSION_REBASE_ADDRESS=0xBFFF0000
  73. set _OS_DLL_REBASE_ADDRESS=0x78000000
  74. rem set DO_WOW6432=FALSE
  75. set DO_WOW6432=TRUE
  76. if defined _COVERAGE_BUILD (
  77. rem KenMa was using 0x28000000
  78. set _OS_DLL_REBASE_ADDRESS=0x28000000
  79. call logmsg.cmd "Coverage build rebase"
  80. )
  81. goto :OK
  82. :IA64
  83. set _SESSION_REBASE_ADDRESS=0x20000001FFFF0000
  84. set _OS_DLL_REBASE_ADDRESS=0x000006fb7FFF0000
  85. set _WOW64_DLL_REBASE_ADDRESS=0x0000000078000000
  86. set REBASE_OS_HIGH=TRUE
  87. goto :OK
  88. :AMD64
  89. set _SESSION_REBASE_ADDRESS=0x00000001FFFF0000
  90. set _OS_DLL_REBASE_ADDRESS=0x000007FFFFFF0000
  91. set _WOW64_DLL_REBASE_ADDRESS=0x0000000078000000
  92. set REBASE_OS_HIGH=TRUE
  93. goto :OK
  94. :OK
  95. call logmsg.cmd "Session rebase addr = %_SESSION_REBASE_ADDRESS%
  96. call logmsg.cmd "OS dll rebase addr = %_OS_DLL_REBASE_ADDRESS%
  97. set QFE_BADDR=%RazzleToolPath%\sp\data\baseaddress.%_BuildArch%.%_BuildType%.%Lang%
  98. if defined _COVERAGE_BUILD (
  99. REM Set QFE_BADDR to some bogus value for coverage scripts
  100. set QFE_BADDR=%temp%\rebasefoobarbaz.txt
  101. if exist %QFE_BADDR% del %QFE_BADDR%
  102. )
  103. if not exist %_TREE%\build_logs md %_TREE%\build_logs
  104. set REBASE_ADDR_FILE=%_TREE%\build_logs\rebase.addresses.txt
  105. if exist %QFE_BADDR% (
  106. call logmsg.cmd "Processing rebase addr file"
  107. set NO_REBASE_FUDGE=1
  108. @if exist %REBASE_ADDR_FILE% del %REBASE_ADDR_FILE%
  109. @for /f "tokens=1,2,3" %%i in (%QFE_BADDR%) do @(
  110. if /I NOT "%%k" == "OPEN" (
  111. if exist %_TREE%\%%k echo %%i %%j %_TREE%\%%k>>%REBASE_ADDR_FILE%
  112. )
  113. )
  114. )
  115. if defined NtRebase_SkipImageCfg goto ImageCfgFinished
  116. REM ------------------------------------------------
  117. REM Mark Winnt32 binaries as net run from swapfile and cd run from swapfile
  118. REM ------------------------------------------------
  119. for /f %%i in ('dir /s /b %_TREE%\winnt32\*.dll %_TREE%\winnt32\*.exe') do imagecfg /q -x -y %%i
  120. for /f %%i in ('dir /s /b %_TREE%\winnt32\winntupg\*.dll %_TREE%\winnt32\winntupg\*.exe') do imagecfg /q -x -y %%i
  121. REM ------------------------------------------------
  122. REM Set Terminal Server compatible bit on all exes
  123. REM ------------------------------------------------
  124. set _TSCOMPAT_PATHS=
  125. REM set _TSCOMPAT_SYMBOL_TREES=%_TREE%\Symbols\retail;%_TREE%\Symbols\system32;%_TREE%\Symbols\mstools;%_TREE%\Symbols\idw;%_TREE%\Symbols\winnt32
  126. REM set _TSCOMPAT_PATHS=%_TSCOMPAT_PATHS% %_TREE%\*.exe %_TREE%\system32\*.exe %_TREE%\mstools\*.exe %_TREE%\idw\*.exe %_TREE%\winnt32\*.exe
  127. set _TSCOMPAT_SYMBOL_TREES=%_TREE%\Symbols\retail
  128. set _TSCOMPAT_PATHS=%_TREE%\*.exe
  129. imagecfg /q /S %_TSCOMPAT_SYMBOL_TREES% /h 1 %_TSCOMPAT_PATHS%
  130. REM Do not set bit on the following exes
  131. if exist %_TREE%\ntvdm.exe imagecfg /q /S %_TSCOMPAT_SYMBOL_TREES% /h 0 %_TREE%\ntvdm.exe
  132. if exist %_TREE%\regini.exe imagecfg /q /S %_TSCOMPAT_SYMBOL_TREES% /h 0 %_TREE%\regini.exe
  133. if exist %_TREE%\idw\regini.exe imagecfg /q /S %_TSCOMPAT_SYMBOL_TREES% /h 0 %_TREE%\idw\regini.exe
  134. if exist %_TREE%\winhlp32.exe imagecfg /q /S %_TSCOMPAT_SYMBOL_TREES% /h 0 %_TREE%\winhlp32.exe
  135. if exist %_TREE%\winhstb.exe imagecfg /q /S %_TSCOMPAT_SYMBOL_TREES% /h 0 %_TREE%\winhstb.exe
  136. if exist %_TREE%\acregl.exe imagecfg /q /S %_TSCOMPAT_SYMBOL_TREES% /h 0 %_TREE%\acregl.exe
  137. :ImageCfgFinished
  138. echo Rebasing images in %_TREE%
  139. set _REBASE_SYMS=
  140. set _REBASE_LOG=%_TREE%\build_logs\rebase.log
  141. mkdir %_TREE%\build_logs >nul 2>&1
  142. set _REBDIR=%RazzleToolPath%\sp\data
  143. set _REBASE_SYMBOL_TREES=%_TREE%\Symbols\retail;%_TREE%\Symbols\winnt32
  144. REM
  145. REM only rebase usa asms (they are all actually world wide)
  146. REM
  147. if /i "%LANG%" neq "usa" set FilterOutAsmsIfNotUsa=asms\
  148. :CalculateRebaseTargets
  149. set RebaseList=%_TREE%\build_logs\rebase.targets.txt
  150. if exist %RebaseList% del %RebaseList%
  151. REM for %%i in (dll drv cpl ocx acm ax tsp) do @(
  152. REM for /f %%x in ('findstr /v "dotnetfx win9xupg win9xmig %FilterOutAsmsIfNotUsa% " %_TREE%\congeal_scripts\exts\%%i_files.lst ^| sort') do @(
  153. REM echo %_TREE%\%%x>>%RebaseList%
  154. REM )
  155. REM )
  156. set _REBPATHS=
  157. if exist %RebaseList% set _REBPATHS=@%RebaseList%
  158. REM -------------------------------------------------------
  159. REM There are duplications between binaries and the tools directories.
  160. REM So, rebase the tools separately.
  161. REM -------------------------------------------------------
  162. set _REBPATHS_SYS32=%_TREE%\system32\*.dll
  163. set _REBPATHS_MSTOOLS=%_TREE%\mstools\*.dll
  164. set _REBPATHS_IDW=%_TREE%\idw\*.dll
  165. set _REBASE_SYMS_SYS32=-u %_TREE%\symbols\system32
  166. set _REBASE_SYMS_MSTOOLS=-u %_TREE%\symbols\mstools
  167. set _REBASE_SYMS_IDW=-u %_TREE%\symbols\idw
  168. REM set _REBPATHS=%_REBPATHS% %_TREE%\dump\*.dll
  169. REM set _REBASE_SYMBOL_TREES=%_REBASE_SYMBOL_TREES%;%_TREE%\Symbols\dump
  170. if NOT EXIST %_TREE%\Symbols\nul goto nodbgfiles
  171. set _REBASE_SYMS=-u %_REBASE_SYMBOL_TREES%
  172. REM
  173. REM Added by wadela to help debug incremental postbuild
  174. REM
  175. set _REBASE_LOG_BAK=%_TREE%\build_logs\"rebase.bak-%DATE:/=.% %TIME::=.%"
  176. set _REBASE_LOG_BAK=%_REBASE_LOG_BAK: =_%
  177. if exist %_REBASE_LOG% copy %_REBASE_LOG% %_REBASE_LOG_BAK%
  178. echo ... updating .DBG files in %_REBASE_SYMBOL_TREES%
  179. :nodbgfiles
  180. erase %_REBASE_LOG%
  181. set _REBASE_FLAGS=%_REBASE_FLAGS% -l %_REBASE_LOG%
  182. REM
  183. REM Allow at least 8k of growth in the image size
  184. REM
  185. if "%NO_REBASE_FUDGE%" == "" (
  186. set _REBASE_FLAGS=%_REBASE_FLAGS% -e 0x2000
  187. )
  188. REM ------------------------------------------------
  189. REM rebase the dlls.
  190. REM ------------------------------------------------
  191. REM do not rebase the csr, wow, or mail dlls.
  192. set _REBASE_EXCLUDES=
  193. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\kbd.reb
  194. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\ntvdm.reb
  195. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\never.reb
  196. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\ts.reb
  197. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\csp.reb
  198. rem this file doesn't exist & causes rebase.exe to stop
  199. rem set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\frozen_asms.reb
  200. if "%REBASE_OS_HIGH%" == "TRUE" (
  201. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\wow64.reb
  202. )
  203. REM Weed out known files that don't exist on this architecture.
  204. set KnownFiles=%_TREE%\build_logs\rebase.known.reb
  205. del %KnownFiles% >nul 2>&1
  206. for /f %%i in (%_REBDIR%\known.reb) do (
  207. if exist %_TREE%\%%i echo %%i>> %KnownFiles%
  208. )
  209. set _REBASE_GROUPS=-G %KnownFiles%
  210. REM asms are only rebased for usa (since they are all actually "world wide")
  211. REM -G is for grouping together "popular" .dlls, like comctl v6, to conserve address space.
  212. if /i "%LANG%" equ "usa" set _REBASE_GROUPS=%_REBASE_GROUPS% -G %_REBDIR%\known_asms.reb
  213. if exist %QFE_BADDR% (
  214. call logmsg.cmd "Rebase with QFE file"
  215. rebase %_REBASE_SYMS% %_REBASE_FLAGS% @@%REBASE_ADDR_FILE%
  216. ) else (
  217. call logmsg.cmd "Rebase without QFE file"
  218. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -d -b %_OS_DLL_REBASE_ADDRESS% -R %_TREE% %_REBASE_EXCLUDES% %_REBASE_GROUPS% %_REBPATHS%
  219. if "%REBASE_OS_HIGH%" == "TRUE" (
  220. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -d -b %_WOW64_DLL_REBASE_ADDRESS% -R %_TREE% -G %_REBDIR%\wow64.reb
  221. )
  222. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -d -b 0x60000000 -R %_TREE% -O %_REBDIR%\kbd.reb
  223. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -d -b 0x10000000 -R %_TREE% -G %_REBDIR%\ntvdm.reb
  224. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -d -b 0x10000000 -R %_TREE% -G %_REBDIR%\csp.reb
  225. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -z -d -b %_SESSION_REBASE_ADDRESS% -R %_TREE% %_TREE%\atmfd.dll %_TREE%\dxg.sys %_TREE%\rdpdd.dll -O %_REBDIR%\ts.reb
  226. )
  227. REM rebase %_REBASE_SYMS_SYS32% %_REBASE_FLAGS% -d -b 0x50000000 -R %_TREE% %_REBPATHS_SYS32%
  228. REM rebase %_REBASE_SYMS_MSTOOLS% %_REBASE_FLAGS% -d -b 0x4c000000 -R %_TREE% %_REBPATHS_MSTOOLS%
  229. REM rebase %_REBASE_SYMS_IDW% %_REBASE_FLAGS% -d -b 0x48000000 -R %_TREE% %_REBPATHS_IDW%
  230. REM
  231. REM --------------------------------------------------------------------
  232. REM Rebase Wow6432 binaries higher to avoid overlap with native X86 binaries
  233. REM --------------------------------------------------------------------
  234. if "%DO_WOW6432%" == "FALSE" goto SkipWow6432
  235. REM Sleep to keep timestamps of wow6432 binaries different than native binaries
  236. REM so that binding doesn't get confused.
  237. sleep 2
  238. rem if exist %QFE_BADDR% goto SkipWOW6432
  239. REM rebasing Keyboard files regardless of the QFE mode
  240. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -d -b 0x60000000 -R %_TREE%\wow6432 -O %_REBDIR%\kbd.reb
  241. goto SkipWow6432
  242. set _REBASE_EXCLUDES=
  243. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\kbd.reb
  244. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\ntvdm.reb
  245. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\never.reb
  246. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\ts.reb
  247. set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\csp.reb
  248. rem set _REBASE_EXCLUDES=%_REBASE_EXCLUDES% -N %_REBDIR%\frozen_asms.reb
  249. set _REBPATHS=%_TREE%\wow6432\*.dll
  250. if /i "%LANG%" equ "usa" for /f %%i in ('dir /s/b/ad %_TREE%\wow6432\asms') do set _REBPATHS=!_REBPATHS! %%i\*.dll
  251. rebase %_REBASE_SYMS% %_REBASE_FLAGS% -d -b 0x7E000000 -R %_TREE%\wow6432 %_REBASE_EXCLUDES% %_REBPATHS%
  252. :SkipWow6432
  253. :end
  254. seterror.exe "%errors%"& goto :EOF