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/common/sandbox_util.h" | 5 #include "content/common/sandbox_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "content/public/common/sandbox_init.h" | 8 #include "content/public/common/sandbox_init.h" |
9 | 9 |
| 10 #if defined(OS_WIN) |
| 11 #include "content/common/sandbox_win.h" |
| 12 #endif |
| 13 |
10 #if defined(OS_POSIX) | 14 #if defined(OS_POSIX) |
11 #include <unistd.h> | 15 #include <unistd.h> |
12 #endif | 16 #endif |
13 | 17 |
14 namespace content { | 18 namespace content { |
15 | 19 |
16 IPC::PlatformFileForTransit BrokerGetFileHandleForProcess( | 20 IPC::PlatformFileForTransit BrokerGetFileHandleForProcess( |
17 base::PlatformFile handle, | 21 base::PlatformFile handle, |
18 base::ProcessId target_process_id, | 22 base::ProcessId target_process_id, |
19 bool should_close_source) { | 23 bool should_close_source) { |
20 IPC::PlatformFileForTransit out_handle; | 24 IPC::PlatformFileForTransit out_handle; |
21 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
22 DWORD options = DUPLICATE_SAME_ACCESS; | 26 DWORD options = DUPLICATE_SAME_ACCESS; |
23 if (should_close_source) | 27 if (should_close_source) |
24 options |= DUPLICATE_CLOSE_SOURCE; | 28 options |= DUPLICATE_CLOSE_SOURCE; |
25 HANDLE raw_handle = INVALID_HANDLE_VALUE; | 29 HANDLE raw_handle = INVALID_HANDLE_VALUE; |
26 if (content::BrokerDuplicateHandle(handle, target_process_id, &raw_handle, 0, | 30 if (BrokerDuplicateHandle(handle, target_process_id, &raw_handle, 0, options))
{ |
27 options)) { | |
28 out_handle = IPC::PlatformFileForTransit(raw_handle, target_process_id); | 31 out_handle = IPC::PlatformFileForTransit(raw_handle, target_process_id); |
29 } else { | 32 } else { |
30 out_handle = IPC::InvalidPlatformFileForTransit(); | 33 out_handle = IPC::InvalidPlatformFileForTransit(); |
31 } | 34 } |
32 #elif defined(OS_POSIX) | 35 #elif defined(OS_POSIX) |
33 // If asked to close the source, we can simply re-use the source fd instead of | 36 // If asked to close the source, we can simply re-use the source fd instead of |
34 // dup()ing and close()ing. | 37 // dup()ing and close()ing. |
35 // When we're not closing the source, we need to duplicate the handle and take | 38 // When we're not closing the source, we need to duplicate the handle and take |
36 // ownership of that. The reason is that this function is often used to | 39 // ownership of that. The reason is that this function is often used to |
37 // generate IPC messages, and the handle must remain valid until it's sent to | 40 // generate IPC messages, and the handle must remain valid until it's sent to |
38 // the other process from the I/O thread. Without the dup, calling code might | 41 // the other process from the I/O thread. Without the dup, calling code might |
39 // close the source handle before the message is sent, creating a race | 42 // close the source handle before the message is sent, creating a race |
40 // condition. | 43 // condition. |
41 int fd = should_close_source ? handle : ::dup(handle); | 44 int fd = should_close_source ? handle : ::dup(handle); |
42 out_handle = base::FileDescriptor(fd, true); | 45 out_handle = base::FileDescriptor(fd, true); |
43 #else | 46 #else |
44 #error Not implemented. | 47 #error Not implemented. |
45 #endif | 48 #endif |
46 return out_handle; | 49 return out_handle; |
47 } | 50 } |
48 | 51 |
49 } // namespace content | 52 } // namespace content |
50 | 53 |
OLD | NEW |