Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 5 #ifndef CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
| 6 #define CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 6 #define CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 namespace IPC { | 26 namespace IPC { |
| 27 class Message; | 27 class Message; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Provides common functionality for hosting a child process and processing IPC | 30 // Provides common functionality for hosting a child process and processing IPC |
| 31 // messages between the host and the child process. Subclasses are responsible | 31 // messages between the host and the child process. Subclasses are responsible |
| 32 // for the actual launching and terminating of the child processes. | 32 // for the actual launching and terminating of the child processes. |
| 33 class ChildProcessHost : public IPC::Channel::Listener, | 33 class ChildProcessHost : public IPC::Channel::Listener, |
| 34 public IPC::Message::Sender { | 34 public IPC::Message::Sender { |
| 35 public: | 35 public: |
| 36 | |
| 37 // These flags may be passed to GetChildPath in order to alter its behavior, | |
| 38 // causing it to return a child path more suited to a specific task. | |
| 39 enum { | |
| 40 // No special behavior requested. | |
| 41 CHILD_NORMAL = 0, | |
| 42 | |
| 43 #if defined(OS_LINUX) | |
| 44 // Indicates that the child execed after forking may be execced from | |
| 45 // /proc/self/exe rather than using the "real" app path. This prevents | |
| 46 // autoupdate from confusing us if it changes the file out from under us. | |
| 47 // You will generally want to set this to true, except when there is an | |
|
TVL
2011/08/24 01:21:34
"to true" here isn't right. needs a tweak since i
| |
| 48 // override to the command line (for example, we're forking a renderer in | |
| 49 // gdb). In this case, you'd use GetChildPath to get the real executable | |
| 50 // file name, and then prepend the GDB command to the command line. | |
| 51 CHILD_ALLOW_SELF = 1 << 0, | |
| 52 #elif defined(OS_MACOSX) | |
| 53 | |
| 54 // Requests that the child run in a process that does not have the | |
| 55 // PIE (position-independent executable) bit set, effectively disabling | |
| 56 // ASLR. For process types that need to allocate a large contiguous | |
| 57 // region, ASLR may not leave a large enough "hole" for the purpose. This | |
| 58 // This option should be used sparingly, and only when absolutely | |
| 59 // necessary. This option is currently incompatible with | |
| 60 // CHILD_ALLOW_HEAP_EXECUTION. | |
| 61 CHILD_NO_PIE = 1 << 1, | |
| 62 | |
| 63 // Requests that the child run in a process that does not protect the | |
| 64 // heap against execution. Normally, heap pages may be made executable | |
| 65 // with mprotect, so this mode should be used sparingly. It is intended | |
| 66 // for processes that may host plug-ins that expect an executable heap | |
| 67 // without having to call mprotect. This option is currently incompatible | |
| 68 // with CHILD_NO_PIE. | |
| 69 CHILD_ALLOW_HEAP_EXECUTION = 1 << 2, | |
| 70 #endif | |
| 71 }; | |
| 72 | |
| 36 virtual ~ChildProcessHost(); | 73 virtual ~ChildProcessHost(); |
| 37 | 74 |
| 38 // Returns the pathname to be used for a child process. If a subprocess | 75 // Returns the pathname to be used for a child process. If a subprocess |
| 39 // pathname was specified on the command line, that will be used. Otherwise, | 76 // pathname was specified on the command line, that will be used. Otherwise, |
| 40 // the default child process pathname will be returned. On most platforms, | 77 // the default child process pathname will be returned. On most platforms, |
| 41 // this will be the same as the currently-executing process. | 78 // this will be the same as the currently-executing process. |
| 42 // | 79 // |
| 43 // The argument allow_self is used on Linux to indicate that we allow us to | 80 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF |
| 44 // fork from /proc/self/exe rather than using the "real" app path. This | 81 // CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL if |
| 45 // prevents autoupdate from confusing us if it changes the file out from | 82 // none of these special behaviors are required. |
| 46 // under us. You will generally want to set this to true, except when there | |
| 47 // is an override to the command line (for example, we're forking a renderer | |
| 48 // in gdb). In this case, you'd use GetChildPath to get the real executable | |
| 49 // file name, and then prepend the GDB command to the command line. | |
| 50 // | 83 // |
| 51 // On failure, returns an empty FilePath. | 84 // On failure, returns an empty FilePath. |
| 52 static FilePath GetChildPath(bool allow_self); | 85 static FilePath GetChildPath(int flags); |
| 53 | 86 |
| 54 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
| 55 // See comments in the cc file. This is a common hack needed for a process | 88 // See comments in the cc file. This is a common hack needed for a process |
| 56 // hosting a sandboxed child process. Hence it lives in this file. | 89 // hosting a sandboxed child process. Hence it lives in this file. |
| 57 static void PreCacheFont(LOGFONT font); | 90 static void PreCacheFont(LOGFONT font); |
| 58 #endif // defined(OS_WIN) | 91 #endif // defined(OS_WIN) |
| 59 | 92 |
| 60 // IPC::Message::Sender implementation. | 93 // IPC::Message::Sender implementation. |
| 61 virtual bool Send(IPC::Message* message); | 94 virtual bool Send(IPC::Message* message); |
| 62 | 95 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 150 |
| 118 // Holds all the IPC message filters. Since this object lives on the IO | 151 // Holds all the IPC message filters. Since this object lives on the IO |
| 119 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 152 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
| 120 // manually. | 153 // manually. |
| 121 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 154 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
| 122 | 155 |
| 123 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 156 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
| 124 }; | 157 }; |
| 125 | 158 |
| 126 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 159 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
| OLD | NEW |