1 : // Copyright 2013 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Implementation of the jump table entry count agent library.
16 :
17 : #include "syzygy/agent/jump_table_count/jump_table_count.h"
18 :
19 : #include "base/at_exit.h"
20 : #include "base/logging.h"
21 :
22 m : extern "C" void __declspec(naked) _jump_table_case_counter() {
23 m : __asm {
24 : // This is expected to be called via instrumentation that looks like:
25 : // push case_id
26 : // call [_jump_table_case_counter]
27 : //
28 : // Stack: ... case_id, ret_addr.
29 :
30 : // TODO(sebmarchand): Implement this function.
31 m : ret 4
32 m : }
33 m : }
34 :
35 m : extern "C" void __declspec(naked) _indirect_penter_dllmain() {
36 m : __asm {
37 : // TODO(sebmarchand): Implement this function.
38 m : ret 4
39 m : }
40 m : }
41 :
42 m : BOOL WINAPI DllMain(HMODULE instance, DWORD reason, LPVOID reserved) {
43 : // Our AtExit manager required by base.
44 m : static base::AtExitManager* at_exit = NULL;
45 :
46 m : switch (reason) {
47 m : case DLL_PROCESS_ATTACH:
48 m : DCHECK(at_exit == NULL);
49 m : at_exit = new base::AtExitManager();
50 :
51 m : LOG(INFO) << "Initialized jump table entry count agent library.";
52 m : break;
53 :
54 m : case DLL_THREAD_ATTACH:
55 m : break;
56 :
57 m : case DLL_THREAD_DETACH:
58 m : break;
59 :
60 m : case DLL_PROCESS_DETACH:
61 m : DCHECK(at_exit != NULL);
62 m : delete at_exit;
63 m : at_exit = NULL;
64 m : break;
65 :
66 m : default:
67 m : NOTREACHED();
68 m : break;
69 m : }
70 :
71 m : return TRUE;
72 m : }
|