Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Side by Side Diff: chrome/installer/mini_installer/mini_installer.cc

Issue 2661463003: Extract the mini_installer's entrypoint into its own source file. (Closed)
Patch Set: shrink memset Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 appropriate flags. 9 // 2) run the real installer (setup.exe) with appropriate flags.
10 // 10 //
11 // In order to be really small the app doesn't link against the CRT and 11 // In order to be really small the app doesn't link against the CRT and
12 // defines the 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" linker: /OPT:NOWIN98 18 // OptimizeForWindows98="1" linker: /OPT:NOWIN98
19 // linker: /SAFESEH:NO 19 // linker: /SAFESEH:NO
20 20
21 // have the linker merge the sections, saving us ~500 bytes. 21 // have the linker merge the sections, saving us ~500 bytes.
22 #pragma comment(linker, "/MERGE:.rdata=.text") 22 #pragma comment(linker, "/MERGE:.rdata=.text")
23 23
24 #include "chrome/installer/mini_installer/mini_installer.h"
25
24 #include <windows.h> 26 #include <windows.h>
25 27
26 // #define needed to link in RtlGenRandom(), a.k.a. SystemFunction036. See the 28 // #define needed to link in RtlGenRandom(), a.k.a. SystemFunction036. See the
27 // "Community Additions" comment on MSDN here: 29 // "Community Additions" comment on MSDN here:
28 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx 30 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx
29 #define SystemFunction036 NTAPI SystemFunction036 31 #define SystemFunction036 NTAPI SystemFunction036
30 #include <NTSecAPI.h> 32 #include <NTSecAPI.h>
31 #undef SystemFunction036 33 #undef SystemFunction036
32 34
33 #include <sddl.h> 35 #include <sddl.h>
34 #include <shellapi.h> 36 #include <shellapi.h>
35 #include <stdlib.h> 37 #include <stdlib.h>
36 #include <stddef.h> 38 #include <stddef.h>
37 39
38 #include "chrome/installer/mini_installer/appid.h" 40 #include "chrome/installer/mini_installer/appid.h"
39 #include "chrome/installer/mini_installer/configuration.h" 41 #include "chrome/installer/mini_installer/configuration.h"
40 #include "chrome/installer/mini_installer/decompress.h" 42 #include "chrome/installer/mini_installer/decompress.h"
41 #include "chrome/installer/mini_installer/exit_code.h"
42 #include "chrome/installer/mini_installer/mini_installer_constants.h" 43 #include "chrome/installer/mini_installer/mini_installer_constants.h"
43 #include "chrome/installer/mini_installer/mini_string.h" 44 #include "chrome/installer/mini_installer/mini_string.h"
44 #include "chrome/installer/mini_installer/pe_resource.h" 45 #include "chrome/installer/mini_installer/pe_resource.h"
45 #include "chrome/installer/mini_installer/regkey.h" 46 #include "chrome/installer/mini_installer/regkey.h"
46 47
47 namespace mini_installer { 48 namespace mini_installer {
48 49
49 typedef StackString<MAX_PATH> PathString; 50 typedef StackString<MAX_PATH> PathString;
50 typedef StackString<MAX_PATH * 4> CommandString; 51 typedef StackString<MAX_PATH * 4> CommandString;
51 52
52 struct ProcessExitResult {
53 DWORD exit_code;
54 DWORD windows_error;
55
56 explicit ProcessExitResult(DWORD exit) : exit_code(exit), windows_error(0) {}
57 ProcessExitResult(DWORD exit, DWORD win)
58 : exit_code(exit), windows_error(win) {
59 }
60
61 bool IsSuccess() {
62 return exit_code == SUCCESS_EXIT_CODE;
63 }
64 };
65
66 // This structure passes data back and forth for the processing 53 // This structure passes data back and forth for the processing
67 // of resource callbacks. 54 // of resource callbacks.
68 struct Context { 55 struct Context {
69 // Input to the call back method. Specifies the dir to save resources. 56 // Input to the call back method. Specifies the dir to save resources.
70 const wchar_t* base_path; 57 const wchar_t* base_path;
71 // First output from call back method. Full path of Chrome archive. 58 // First output from call back method. Full path of Chrome archive.
72 PathString* chrome_resource_path; 59 PathString* chrome_resource_path;
73 // Second output from call back method. Full path of Setup archive/exe. 60 // Second output from call back method. Full path of Setup archive/exe.
74 PathString* setup_resource_path; 61 PathString* setup_resource_path;
75 }; 62 };
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 wchar_t value[2] = {0}; 803 wchar_t value[2] = {0};
817 if (RegKey::ReadSZValue(HKEY_CURRENT_USER, kCleanupRegistryKey, 804 if (RegKey::ReadSZValue(HKEY_CURRENT_USER, kCleanupRegistryKey,
818 kCleanupRegistryValue, value, _countof(value)) && 805 kCleanupRegistryValue, value, _countof(value)) &&
819 value[0] == L'0') { 806 value[0] == L'0') {
820 return false; 807 return false;
821 } 808 }
822 809
823 return true; 810 return true;
824 } 811 }
825 812
826 // Main function. First gets a working dir, unpacks the resources and finally
827 // executes setup.exe to do the install/upgrade.
828 ProcessExitResult WMain(HMODULE module) { 813 ProcessExitResult WMain(HMODULE module) {
829 // Always start with deleting potential leftovers from previous installations. 814 // Always start with deleting potential leftovers from previous installations.
830 // This can make the difference between success and failure. We've seen 815 // This can make the difference between success and failure. We've seen
831 // many installations out in the field fail due to out of disk space problems 816 // many installations out in the field fail due to out of disk space problems
832 // so this could buy us some space. 817 // so this could buy us some space.
833 DeleteOldChromeTempDirectories(); 818 DeleteOldChromeTempDirectories();
834 819
835 ProcessExitResult exit_code = ProcessExitResult(SUCCESS_EXIT_CODE); 820 ProcessExitResult exit_code = ProcessExitResult(SUCCESS_EXIT_CODE);
836 821
837 // Parse configuration from the command line and resources. 822 // Parse configuration from the command line and resources.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 DeleteExtractedFiles(base_path.get(), archive_path.get(), setup_path.get()); 865 DeleteExtractedFiles(base_path.get(), archive_path.get(), setup_path.get());
881 866
882 #if defined(GOOGLE_CHROME_BUILD) 867 #if defined(GOOGLE_CHROME_BUILD)
883 WriteInstallResults(configuration, exit_code); 868 WriteInstallResults(configuration, exit_code);
884 #endif 869 #endif
885 870
886 return exit_code; 871 return exit_code;
887 } 872 }
888 873
889 } // namespace mini_installer 874 } // namespace mini_installer
890
891 int MainEntryPoint() {
892 mini_installer::ProcessExitResult result =
893 mini_installer::WMain(::GetModuleHandle(NULL));
894
895 ::ExitProcess(result.exit_code);
896 }
897
898 #if defined(ADDRESS_SANITIZER)
899 // Executables instrumented with ASAN need CRT functions. We do not use
900 // the /ENTRY switch for ASAN instrumented executable and a "main" function
901 // is required.
902 int WINAPI WinMain(HINSTANCE hInstance,
903 HINSTANCE hPrevInstance,
904 LPSTR lpCmdLine,
905 int nCmdShow) {
906 MainEntryPoint();
907 return 0;
908 }
909 #endif
910
911 // VC Express editions don't come with the memset CRT obj file and linking to
912 // the obj files between versions becomes a bit problematic. Therefore,
913 // simply implement memset.
914 //
915 // This also avoids having to explicitly set the __sse2_available hack when
916 // linking with both the x64 and x86 obj files which is required when not
917 // linking with the std C lib in certain instances (including Chromium) with
918 // MSVC. __sse2_available determines whether to use SSE2 intructions with
919 // std C lib routines, and is set by MSVC's std C lib implementation normally.
920 extern "C" {
921 #pragma function(memset)
922 void* memset(void* dest, int c, size_t count) {
923 void* start = dest;
924 while (count--) {
925 *reinterpret_cast<char*>(dest) = static_cast<char>(c);
926 dest = reinterpret_cast<char*>(dest) + 1;
927 }
928 return start;
929 }
930 } // extern "C"
OLDNEW
« no previous file with comments | « chrome/installer/mini_installer/mini_installer.h ('k') | chrome/installer/mini_installer/mini_installer_exe_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698