| OLD | NEW |
| 1 // Copyright 2015 Google Inc. All Rights Reserved. | 1 // Copyright 2015 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 int RunLaaApp::Run() { | 183 int RunLaaApp::Run() { |
| 184 // If an expected mode has been specified then run a self-test and return | 184 // If an expected mode has been specified then run a self-test and return |
| 185 // the result. | 185 // the result. |
| 186 if (!expect_mode_.empty()) { | 186 if (!expect_mode_.empty()) { |
| 187 if (SelfTest(expect_mode_)) | 187 if (SelfTest(expect_mode_)) |
| 188 return 0; | 188 return 0; |
| 189 return 1; | 189 return 1; |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool is_laa = false; | 192 bool was_laa = false; |
| 193 if (!GetLaaBit(image_, &is_laa)) | 193 if (!GetLaaBit(image_, &was_laa)) |
| 194 return 1; | 194 return 1; |
| 195 | 195 |
| 196 base::ScopedTempDir scoped_temp_dir; | 196 base::ScopedTempDir scoped_temp_dir; |
| 197 base::FilePath child_image(image_); | 197 base::FilePath child_image(image_); |
| 198 bool toggle_back = false; | 198 bool toggle_back = false; |
| 199 | 199 |
| 200 if (is_laa == is_laa_) { | 200 if (was_laa == is_laa_) { |
| 201 LOG(INFO) << "Image already in desired mode, running directly."; | 201 LOG(INFO) << "Image already in desired mode, running directly."; |
| 202 } else { | 202 } else { |
| 203 // The image is not in the desired mode. It needs to be toggled. | 203 // The image is not in the desired mode. It needs to be toggled. |
| 204 if (in_place_) { | 204 if (in_place_) { |
| 205 // Try our best not to modify the currently running executable. | 205 // Try our best not to modify the currently running executable. |
| 206 base::FilePath exe_path; | 206 base::FilePath exe_path; |
| 207 if (PathService::Get(base::FILE_EXE, &exe_path)) { | 207 if (PathService::Get(base::FILE_EXE, &exe_path)) { |
| 208 exe_path = base::MakeAbsoluteFilePath(exe_path); | 208 exe_path = base::MakeAbsoluteFilePath(exe_path); |
| 209 core::FilePathCompareResult result = | 209 core::FilePathCompareResult result = |
| 210 core::CompareFilePaths(exe_path, image_); | 210 core::CompareFilePaths(exe_path, image_); |
| 211 if (result == core::kEquivalentFilePaths) { | 211 if (result == core::kEquivalentFilePaths) { |
| 212 LOG(ERROR) << "Unable to modify running executable in-place."; | 212 LOG(ERROR) << "Unable to modify running executable in-place."; |
| 213 return 1; | 213 return 1; |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 // The work is occurring in place and the image needs to be toggled back. | 217 // The work is occurring in place and the image needs to be toggled back. |
| 218 toggle_back = true; | 218 toggle_back = true; |
| 219 } else { | 219 } else { |
| 220 // The work is not to happen in place. Create a temp directory and copy | 220 // The work is not to happen in place. Create a temp directory and copy |
| 221 // the | 221 // the image. |
| 222 // image. | |
| 223 if (!scoped_temp_dir.CreateUniqueTempDir()) { | 222 if (!scoped_temp_dir.CreateUniqueTempDir()) { |
| 224 LOG(ERROR) << "Failed to create temp directory."; | 223 LOG(ERROR) << "Failed to create temp directory."; |
| 225 return 1; | 224 return 1; |
| 226 } | 225 } |
| 227 | 226 |
| 228 // Take ownership of the temp directory if it is to be left around. | 227 // Take ownership of the temp directory if it is to be left around. |
| 229 base::FilePath temp_dir = scoped_temp_dir.path(); | 228 base::FilePath temp_dir = scoped_temp_dir.path(); |
| 230 if (keep_temp_dir_) { | 229 if (keep_temp_dir_) { |
| 231 temp_dir = scoped_temp_dir.Take(); | 230 temp_dir = scoped_temp_dir.Take(); |
| 232 LOG(INFO) << "Temporary directory will be preserved: " | 231 LOG(INFO) << "Temporary directory will be preserved: " |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 LOG(INFO) << "Toggling back LargeAddressAware bit."; | 269 LOG(INFO) << "Toggling back LargeAddressAware bit."; |
| 271 if (!ToggleLaaBit(child_image)) | 270 if (!ToggleLaaBit(child_image)) |
| 272 return 1; | 271 return 1; |
| 273 } | 272 } |
| 274 | 273 |
| 275 // Return the exit code of the child process. | 274 // Return the exit code of the child process. |
| 276 return exit_code; | 275 return exit_code; |
| 277 } | 276 } |
| 278 | 277 |
| 279 } // namespace runlaa | 278 } // namespace runlaa |
| OLD | NEW |