OLD | NEW |
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 #include "content/zygote/zygote_main.h" | 5 #include "content/zygote/zygote_main.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <openssl/crypto.h> | 9 #include <openssl/crypto.h> |
10 #include <openssl/rand.h> | 10 #include <openssl/rand.h> |
11 #include <pthread.h> | 11 #include <pthread.h> |
12 #include <signal.h> | 12 #include <signal.h> |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 #include <string.h> | 15 #include <string.h> |
16 #include <sys/socket.h> | 16 #include <sys/socket.h> |
17 #include <sys/types.h> | 17 #include <sys/types.h> |
18 #include <unistd.h> | 18 #include <unistd.h> |
| 19 |
| 20 #include <memory> |
19 #include <utility> | 21 #include <utility> |
20 #include <vector> | 22 #include <vector> |
21 | 23 |
22 #include "base/bind.h" | 24 #include "base/bind.h" |
23 #include "base/command_line.h" | 25 #include "base/command_line.h" |
24 #include "base/compiler_specific.h" | 26 #include "base/compiler_specific.h" |
25 #include "base/memory/scoped_ptr.h" | |
26 #include "base/memory/scoped_vector.h" | 27 #include "base/memory/scoped_vector.h" |
27 #include "base/native_library.h" | 28 #include "base/native_library.h" |
28 #include "base/pickle.h" | 29 #include "base/pickle.h" |
29 #include "base/posix/eintr_wrapper.h" | 30 #include "base/posix/eintr_wrapper.h" |
30 #include "base/posix/unix_domain_socket_linux.h" | 31 #include "base/posix/unix_domain_socket_linux.h" |
31 #include "base/rand_util.h" | 32 #include "base/rand_util.h" |
32 #include "base/strings/safe_sprintf.h" | 33 #include "base/strings/safe_sprintf.h" |
33 #include "base/strings/string_number_conversions.h" | 34 #include "base/strings/string_number_conversions.h" |
34 #include "base/sys_info.h" | 35 #include "base/sys_info.h" |
35 #include "build/build_config.h" | 36 #include "build/build_config.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 base::RandUint64(); | 329 base::RandUint64(); |
329 | 330 |
330 base::SysInfo::AmountOfPhysicalMemory(); | 331 base::SysInfo::AmountOfPhysicalMemory(); |
331 base::SysInfo::MaxSharedMemorySize(); | 332 base::SysInfo::MaxSharedMemorySize(); |
332 base::SysInfo::NumberOfProcessors(); | 333 base::SysInfo::NumberOfProcessors(); |
333 | 334 |
334 // ICU DateFormat class (used in base/time_format.cc) needs to get the | 335 // ICU DateFormat class (used in base/time_format.cc) needs to get the |
335 // Olson timezone ID by accessing the zoneinfo files on disk. After | 336 // Olson timezone ID by accessing the zoneinfo files on disk. After |
336 // TimeZone::createDefault is called once here, the timezone ID is | 337 // TimeZone::createDefault is called once here, the timezone ID is |
337 // cached and there's no more need to access the file system. | 338 // cached and there's no more need to access the file system. |
338 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); | 339 std::unique_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); |
339 | 340 |
340 #if defined(ARCH_CPU_ARM_FAMILY) | 341 #if defined(ARCH_CPU_ARM_FAMILY) |
341 // On ARM, BoringSSL requires access to /proc/cpuinfo to determine processor | 342 // On ARM, BoringSSL requires access to /proc/cpuinfo to determine processor |
342 // features. Query this before entering the sandbox. | 343 // features. Query this before entering the sandbox. |
343 CRYPTO_library_init(); | 344 CRYPTO_library_init(); |
344 #endif | 345 #endif |
345 | 346 |
346 // Pass BoringSSL a copy of the /dev/urandom file descriptor so RAND_bytes | 347 // Pass BoringSSL a copy of the /dev/urandom file descriptor so RAND_bytes |
347 // will work inside the sandbox. | 348 // will work inside the sandbox. |
348 RAND_set_urandom_fd(base::GetUrandomFD()); | 349 RAND_set_urandom_fd(base::GetUrandomFD()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 CHECK(CreateInitProcessReaper(&callback)); | 449 CHECK(CreateInitProcessReaper(&callback)); |
449 } | 450 } |
450 } | 451 } |
451 | 452 |
452 #if defined(SANITIZER_COVERAGE) | 453 #if defined(SANITIZER_COVERAGE) |
453 static int g_sanitizer_message_length = 1 * 1024 * 1024; | 454 static int g_sanitizer_message_length = 1 * 1024 * 1024; |
454 | 455 |
455 // A helper process which collects code coverage data from the renderers over a | 456 // A helper process which collects code coverage data from the renderers over a |
456 // socket and dumps it to a file. See http://crbug.com/336212 for discussion. | 457 // socket and dumps it to a file. See http://crbug.com/336212 for discussion. |
457 static void SanitizerCoverageHelper(int socket_fd, int file_fd) { | 458 static void SanitizerCoverageHelper(int socket_fd, int file_fd) { |
458 scoped_ptr<char[]> buffer(new char[g_sanitizer_message_length]); | 459 std::unique_ptr<char[]> buffer(new char[g_sanitizer_message_length]); |
459 while (true) { | 460 while (true) { |
460 ssize_t received_size = HANDLE_EINTR( | 461 ssize_t received_size = HANDLE_EINTR( |
461 recv(socket_fd, buffer.get(), g_sanitizer_message_length, 0)); | 462 recv(socket_fd, buffer.get(), g_sanitizer_message_length, 0)); |
462 PCHECK(received_size >= 0); | 463 PCHECK(received_size >= 0); |
463 if (received_size == 0) | 464 if (received_size == 0) |
464 // All clients have closed the socket. We should die. | 465 // All clients have closed the socket. We should die. |
465 _exit(0); | 466 _exit(0); |
466 PCHECK(file_fd >= 0); | 467 PCHECK(file_fd >= 0); |
467 ssize_t written_size = 0; | 468 ssize_t written_size = 0; |
468 while (written_size < received_size) { | 469 while (written_size < received_size) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; | 644 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; |
644 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); | 645 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); |
645 | 646 |
646 Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children, | 647 Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children, |
647 extra_fds); | 648 extra_fds); |
648 // This function call can return multiple times, once per fork(). | 649 // This function call can return multiple times, once per fork(). |
649 return zygote.ProcessRequests(); | 650 return zygote.ProcessRequests(); |
650 } | 651 } |
651 | 652 |
652 } // namespace content | 653 } // namespace content |
OLD | NEW |