OLD | NEW |
---|---|
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // mini_installer.exe is the first exe that is run when chrome is being | 5 // mini_installer.exe is the first exe that is run when chrome is being |
6 // installed or upgraded. It is designed to be extremely small (~5KB with no | 6 // installed or upgraded. It is designed to be extremely small (~5KB with no |
7 // extra resources linked) and it has two main jobs: | 7 // extra resources linked) and it has two main jobs: |
8 // 1) unpack the resources (possibly decompressing some) | 8 // 1) unpack the resources (possibly decompressing some) |
9 // 2) run the real installer (setup.exe) with appropiate flags. | 9 // 2) run the real installer (setup.exe) with appropriate flags. |
10 // | 10 // |
11 // In order to be really small we don't link against the CRT and we define the | 11 // In order to be really small the app doesn't link against the CRT and |
12 // following compiler/linker flags: | 12 // defines the following compiler/linker flags: |
13 // EnableIntrinsicFunctions="true" compiler: /Oi | 13 // EnableIntrinsicFunctions="true" compiler: /Oi |
14 // BasicRuntimeChecks="0" | 14 // BasicRuntimeChecks="0" |
15 // BufferSecurityCheck="false" compiler: /GS- | 15 // BufferSecurityCheck="false" compiler: /GS- |
16 // EntryPointSymbol="MainEntryPoint" linker: /ENTRY | 16 // EntryPointSymbol="MainEntryPoint" linker: /ENTRY |
17 // IgnoreAllDefaultLibraries="true" linker: /NODEFAULTLIB | 17 // IgnoreAllDefaultLibraries="true" linker: /NODEFAULTLIB |
18 // OptimizeForWindows98="1" liker: /OPT:NOWIN98 | 18 // OptimizeForWindows98="1" liker: /OPT:NOWIN98 |
19 // linker: /SAFESEH:NO | 19 // linker: /SAFESEH:NO |
20 // Also some built-in code that the compiler relies on is not defined so we | |
21 // are forced to manually link against it. It comes in the form of two | |
22 // object files that exist in $(VCInstallDir)\crt\src which are memset.obj and | |
23 // P4_memset.obj. These two object files rely on the existence of a static | |
24 // variable named __sse2_available which indicates the presence of intel sse2 | |
25 // extensions. We define it to false which causes a slower but safe code for | |
26 // memcpy and memset intrinsics. | |
27 | 20 |
28 // having the linker merge the sections is saving us ~500 bytes. | 21 // have the linker merge the sections, saving us ~500 bytes. |
29 #pragma comment(linker, "/MERGE:.rdata=.text") | 22 #pragma comment(linker, "/MERGE:.rdata=.text") |
30 | 23 |
31 #include <windows.h> | 24 #include <windows.h> |
32 #include <setupapi.h> | 25 #include <setupapi.h> |
33 #include <shellapi.h> | 26 #include <shellapi.h> |
34 | 27 |
35 #include "chrome/installer/mini_installer/appid.h" | 28 #include "chrome/installer/mini_installer/appid.h" |
36 #include "chrome/installer/mini_installer/decompress.h" | 29 #include "chrome/installer/mini_installer/decompress.h" |
37 #include "chrome/installer/mini_installer/mini_installer.h" | 30 #include "chrome/installer/mini_installer/mini_installer.h" |
38 #include "chrome/installer/mini_installer/mini_string.h" | 31 #include "chrome/installer/mini_installer/mini_string.h" |
39 #include "chrome/installer/mini_installer/pe_resource.h" | 32 #include "chrome/installer/mini_installer/pe_resource.h" |
40 | 33 |
41 // arraysize borrowed from basictypes.h | 34 // arraysize borrowed from basictypes.h |
42 template <typename T, size_t N> | 35 template <typename T, size_t N> |
43 char (&ArraySizeHelper(T (&array)[N]))[N]; | 36 char (&ArraySizeHelper(T (&array)[N]))[N]; |
44 #define arraysize(array) (sizeof(ArraySizeHelper(array))) | 37 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
45 | 38 |
46 // Required linker symbol. See remarks above. | |
47 extern "C" unsigned int __sse2_available = 0; | |
48 | |
49 namespace mini_installer { | 39 namespace mini_installer { |
50 | 40 |
51 typedef StackString<MAX_PATH> PathString; | 41 typedef StackString<MAX_PATH> PathString; |
52 typedef StackString<MAX_PATH * 4> CommandString; | 42 typedef StackString<MAX_PATH * 4> CommandString; |
53 | 43 |
54 // This structure passes data back and forth for the processing | 44 // This structure passes data back and forth for the processing |
55 // of resource callbacks. | 45 // of resource callbacks. |
56 struct Context { | 46 struct Context { |
57 // Input to the call back method. Specifies the dir to save resources. | 47 // Input to the call back method. Specifies the dir to save resources. |
58 const wchar_t* base_path; | 48 const wchar_t* base_path; |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 | 805 |
816 return exit_code; | 806 return exit_code; |
817 } | 807 } |
818 | 808 |
819 } // namespace mini_installer | 809 } // namespace mini_installer |
820 | 810 |
821 int MainEntryPoint() { | 811 int MainEntryPoint() { |
822 int result = mini_installer::WMain(::GetModuleHandle(NULL)); | 812 int result = mini_installer::WMain(::GetModuleHandle(NULL)); |
823 ::ExitProcess(result); | 813 ::ExitProcess(result); |
824 } | 814 } |
815 | |
816 // VC Express editions don't come with the memset CRT obj file | |
817 // and linking to the obj files between versions becomes a bit | |
818 // problematic. Therefore, simply implement memset. | |
819 // | |
820 // This also avoids having to use the __sse2_available hack when | |
821 // linking with linking to the dual x64 and x86 obj files. | |
Mark Mentovai
2011/03/17 20:43:42
Revise “linking with linking to”—pick one. :)
RN
2011/03/18 09:34:24
Yeah.... rewrote that comment and explained it a b
| |
822 // extern "C" __sse2_available = | |
Mark Mentovai
2011/03/17 20:43:42
This comment looks like code but it’s not. defined
RN
2011/03/18 09:34:24
Done.
| |
823 // defined(_M_IX86) || defined(_M_AMD64); | |
824 extern "C" { | |
825 | |
826 #pragma function(memset) | |
827 void* memset(void* dest, int c, size_t count) { | |
828 // Typical 32-bit memset c implementation | |
Mark Mentovai
2011/03/17 20:43:42
This assumes that dest is properly aligned. It’ll
RN
2011/03/18 09:34:24
Put in more comments about this (even if isn't tha
| |
829 size_t adjcount = count>>2; | |
Mark Mentovai
2011/03/17 20:43:42
Style nit: spaces around operators like >>.
RN
2011/03/18 09:34:24
Done.
| |
830 UINT32 fill = (c<<24|c<<16|c<<8|c); | |
Mark Mentovai
2011/03/17 20:43:42
Here too. (c << 24 | c << 16 | c << 8 | c)
RN
2011/03/18 09:34:24
Done.
| |
831 UINT32* dest32 = (unsigned __int32*)dest; | |
832 UINT8* dest8 = (unsigned __int8*)dest; | |
Mark Mentovai
2011/03/17 20:43:42
No need to line up dest8 and dest32, especially wh
RN
2011/03/18 09:34:24
Nice catch, done.
| |
833 | |
834 // Take care of the ending 0-3 bytes (binary 11 = 3) | |
835 switch (count - (adjcount<<2)) { | |
Mark Mentovai
2011/03/17 20:43:42
Space around that << operator.
RN
2011/03/18 09:34:24
Done.
| |
836 case 3: dest8[count - 3] = c; | |
Mark Mentovai
2011/03/17 20:43:42
The assignments here really belong on the next lin
RN
2011/03/18 09:34:24
OK. Also added a longish comment about how it work
| |
837 case 2: dest8[count - 2] = c; | |
838 case 1: dest8[count - 1] = c; | |
839 } | |
840 | |
841 while (adjcount-- > 0) | |
842 *(dest32++) = fill; | |
Mark Mentovai
2011/03/17 20:43:42
Fix the indent.
RN
2011/03/18 09:34:24
Assuming the 2 spaces rule, done.
Mark Mentovai
2011/03/18 14:54:47
RN wrote:
| |
843 | |
844 return dest; | |
845 } | |
846 | |
847 } | |
Mark Mentovai
2011/03/17 20:43:42
} // extern "C"
RN
2011/03/18 09:34:24
Done.
| |
OLD | NEW |