1 // Copyright (c) 2006-2010 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/resolver.h"
7 // For placement new. This file must not depend on the CRT at runtime, but
8 // placement operator new is inline.
11 #include "sandbox/win/src/sandbox_nt_util.h"
15 const BYTE kPushRax
= 0x50;
16 const USHORT kMovRax
= 0xB848;
17 const ULONG kMovRspRax
= 0x24048948;
18 const BYTE kRetNp
= 0xC3;
21 struct InternalThunk
{
22 // This struct contains roughly the following code:
24 // 01 48b8f0debc9a78563412 mov rax,123456789ABCDEF0h
25 // 0b 48890424 mov qword ptr [rsp],rax
28 // The code modifies rax, but that should not be an issue for the common
29 // calling conventions.
34 interceptor_function
= 0;
35 mov_rsp_rax
= kMovRspRax
;
38 BYTE push_rax
; // = 50
39 USHORT mov_rax
; // = 48 B8
40 ULONG_PTR interceptor_function
;
41 ULONG mov_rsp_rax
; // = 48 89 04 24
50 size_t ResolverThunk::GetInternalThunkSize() const {
51 return sizeof(InternalThunk
);
54 bool ResolverThunk::SetInternalThunk(void* storage
, size_t storage_bytes
,
55 const void* original_function
,
56 const void* interceptor
) {
57 if (storage_bytes
< sizeof(InternalThunk
))
60 InternalThunk
* thunk
= new(storage
) InternalThunk
;
61 thunk
->interceptor_function
= reinterpret_cast<ULONG_PTR
>(interceptor
);
66 NTSTATUS
ResolverThunk::ResolveTarget(const void* module
,
67 const char* function_name
,
69 // We don't support sidestep & co.
70 return STATUS_NOT_IMPLEMENTED
;
73 } // namespace sandbox