1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/win/src/sync_interception.h"
7 #include "sandbox/win/src/crosscall_client.h"
8 #include "sandbox/win/src/ipc_tags.h"
9 #include "sandbox/win/src/policy_params.h"
10 #include "sandbox/win/src/policy_target.h"
11 #include "sandbox/win/src/sandbox_factory.h"
12 #include "sandbox/win/src/sandbox_nt_util.h"
13 #include "sandbox/win/src/sharedmem_ipc_client.h"
14 #include "sandbox/win/src/target_services.h"
18 HANDLE WINAPI
TargetCreateEventW(CreateEventWFunction orig_CreateEvent
,
19 LPSECURITY_ATTRIBUTES security_attributes
,
20 BOOL manual_reset
, BOOL initial_state
,
22 // Check if the process can create it first.
23 HANDLE handle
= orig_CreateEvent(security_attributes
, manual_reset
,
25 DWORD original_error
= ::GetLastError();
29 // We don't trust that the IPC can work this early.
30 if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled())
34 if (security_attributes
)
37 void* memory
= GetGlobalIPCMemory();
41 CountedParameterSet
<NameBased
> params
;
42 params
[NameBased::NAME
] = ParamPickerMake(name
);
44 if (!QueryBroker(IPC_CREATEEVENT_TAG
, params
.GetBase()))
47 SharedMemIPCClient
ipc(memory
);
48 CrossCallReturn answer
= {0};
49 ResultCode code
= CrossCall(ipc
, IPC_CREATEEVENT_TAG
, name
, manual_reset
,
50 initial_state
, &answer
);
52 if (SBOX_ALL_OK
!= code
)
55 ::SetLastError(answer
.win32_result
);
59 ::SetLastError(original_error
);
63 // Interception of OpenEventW on the child process.
64 // It should never be called directly
65 HANDLE WINAPI
TargetOpenEventW(OpenEventWFunction orig_OpenEvent
,
66 ACCESS_MASK desired_access
, BOOL inherit_handle
,
68 // Check if the process can open it first.
69 HANDLE handle
= orig_OpenEvent(desired_access
, inherit_handle
, name
);
70 DWORD original_error
= ::GetLastError();
74 // We don't trust that the IPC can work this early.
75 if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled())
79 void* memory
= GetGlobalIPCMemory();
83 uint32 inherit_handle_ipc
= inherit_handle
;
84 CountedParameterSet
<OpenEventParams
> params
;
85 params
[OpenEventParams::NAME
] = ParamPickerMake(name
);
86 params
[OpenEventParams::ACCESS
] = ParamPickerMake(desired_access
);
88 if (!QueryBroker(IPC_OPENEVENT_TAG
, params
.GetBase()))
91 SharedMemIPCClient
ipc(memory
);
92 CrossCallReturn answer
= {0};
93 ResultCode code
= CrossCall(ipc
, IPC_OPENEVENT_TAG
, name
, desired_access
,
94 inherit_handle_ipc
, &answer
);
96 if (SBOX_ALL_OK
!= code
)
99 ::SetLastError(answer
.win32_result
);
100 return answer
.handle
;
103 ::SetLastError(original_error
);
107 } // namespace sandbox