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 on Linux, except when there is an |
| 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 // option should be used sparingly, and only when absolutely necessary. |
| 59 // This option is currently incompatible with CHILD_ALLOW_HEAP_EXECUTION. |
| 60 CHILD_NO_PIE = 1 << 1, |
| 61 |
| 62 // Requests that the child run in a process that does not protect the |
| 63 // heap against execution. Normally, heap pages may be made executable |
| 64 // with mprotect, so this mode should be used sparingly. It is intended |
| 65 // for processes that may host plug-ins that expect an executable heap |
| 66 // without having to call mprotect. This option is currently incompatible |
| 67 // with CHILD_NO_PIE. |
| 68 CHILD_ALLOW_HEAP_EXECUTION = 1 << 2, |
| 69 #endif |
| 70 }; |
| 71 |
36 virtual ~ChildProcessHost(); | 72 virtual ~ChildProcessHost(); |
37 | 73 |
38 // Returns the pathname to be used for a child process. If a subprocess | 74 // 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, | 75 // pathname was specified on the command line, that will be used. Otherwise, |
40 // the default child process pathname will be returned. On most platforms, | 76 // the default child process pathname will be returned. On most platforms, |
41 // this will be the same as the currently-executing process. | 77 // this will be the same as the currently-executing process. |
42 // | 78 // |
43 // The argument allow_self is used on Linux to indicate that we allow us to | 79 // 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 | 80 // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL |
45 // prevents autoupdate from confusing us if it changes the file out from | 81 // if 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 // | 82 // |
51 // On failure, returns an empty FilePath. | 83 // On failure, returns an empty FilePath. |
52 static FilePath GetChildPath(bool allow_self); | 84 static FilePath GetChildPath(int flags); |
53 | 85 |
54 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
55 // See comments in the cc file. This is a common hack needed for a process | 87 // 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. | 88 // hosting a sandboxed child process. Hence it lives in this file. |
57 static void PreCacheFont(LOGFONT font); | 89 static void PreCacheFont(LOGFONT font); |
58 #endif // defined(OS_WIN) | 90 #endif // defined(OS_WIN) |
59 | 91 |
60 // IPC::Message::Sender implementation. | 92 // IPC::Message::Sender implementation. |
61 virtual bool Send(IPC::Message* message); | 93 virtual bool Send(IPC::Message* message); |
62 | 94 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 149 |
118 // Holds all the IPC message filters. Since this object lives on the IO | 150 // 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 | 151 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
120 // manually. | 152 // manually. |
121 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 153 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
122 | 154 |
123 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 155 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
124 }; | 156 }; |
125 | 157 |
126 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 158 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
OLD | NEW |