1 : // Copyright 2014 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 : // Macros for dealing with CRT interceptors.
16 :
17 : #ifndef SYZYGY_AGENT_ASAN_CRT_INTERCEPTORS_MACROS_H_
18 : #define SYZYGY_AGENT_ASAN_CRT_INTERCEPTORS_MACROS_H_
19 :
20 : // Macros for building CRT interceptors. The format is:
21 : // (0:calling_convention, 1:return_value, 2:function_name, 3:args, 4:arg_names,
22 : // 5...:user_data ...)
23 : #define ASAN_CRT_INTERCEPTORS(F, ...) \
24 m : F(__cdecl, void*, memcpy, \
25 m : (void* destination, const void* source, size_t num), \
26 m : (destination, source, num), __VA_ARGS__) \
27 m : F(__cdecl, void*, memmove, \
28 m : (void* destination, const void* source, size_t num), \
29 m : (destination, source, num), __VA_ARGS__) \
30 m : F(__cdecl, void*, memset, (void* ptr, int value, size_t num), \
31 m : (ptr, value, num), __VA_ARGS__) \
32 m : F(__cdecl, const void*, memchr, \
33 m : (const void* ptr, int value, size_t num), \
34 m : (ptr, value, num), __VA_ARGS__) \
35 m : F(__cdecl, size_t, strcspn, (const char* str1, const char* str2), \
36 m : (str1, str2), __VA_ARGS__) \
37 m : F(__cdecl, size_t, strlen, (const char* str), (str), __VA_ARGS__) \
38 m : F(__cdecl, size_t, strnlen, (const char* str, size_t max_len), \
39 m : (str, max_len), __VA_ARGS__) \
40 m : F(__cdecl, const char*, strrchr, (const char* str, int character), \
41 m : (str, character), __VA_ARGS__) \
42 m : F(__cdecl, const wchar_t*, wcsrchr, \
43 m : (const wchar_t* str, wchar_t character), \
44 m : (str, character), __VA_ARGS__) \
45 m : F(__cdecl, const wchar_t*, wcschr, \
46 m : (const wchar_t* str, wchar_t character), \
47 m : (str, character), __VA_ARGS__) \
48 m : F(__cdecl, int, strcmp, (const char* str1, const char* str2), \
49 m : (str1, str2), __VA_ARGS__) \
50 m : F(__cdecl, const char*, strpbrk, (const char* str1, const char* str2), \
51 m : (str1, str2), __VA_ARGS__) \
52 m : F(__cdecl, const char*, strstr, (const char* str1, const char* str2), \
53 m : (str1, str2), __VA_ARGS__) \
54 m : F(__cdecl, size_t, wcsnlen, (const wchar_t* str, size_t max_len), \
55 m : (str, max_len), __VA_ARGS__) \
56 m : F(__cdecl, const wchar_t*, wcsstr, (const wchar_t* str1, \
57 m : const wchar_t* str2), (str1, str2), __VA_ARGS__) \
58 m : F(__cdecl, size_t, strspn, (const char* str1, const char* str2), \
59 m : (str1, str2), __VA_ARGS__) \
60 m : F(__cdecl, char*, strncpy, \
61 m : (char* destination, const char* source, size_t num), \
62 m : (destination, source, num), __VA_ARGS__) \
63 m : F(__cdecl, char*, strncat, \
64 m : (char* destination, const char* source, size_t num), \
65 m : (destination, source, num), __VA_ARGS__)
66 :
67 : // Generates CRT interceptor function declarations.
68 : #define ASAN_CRT_INTERCEPTORS_DECL(calling_convention, \
69 m : return_value, \
70 m : function_name, \
71 m : args, \
72 m : arg_names, \
73 m : prefix) \
74 m : return_value calling_convention prefix ## function_name args;
75 :
76 : // Generates pass-through implementations of CRT interceptors.
77 : #define ASAN_CRT_INTERCEPTORS_DEFN(calling_convention, \
78 m : return_value, \
79 m : function_name, \
80 m : args, \
81 m : arg_names, \
82 m : prefix) \
83 m : return_value calling_convention prefix ## function_name args { \
84 m : return :: function_name arg_names; \
85 m : }
86 :
87 : #endif // SYZYGY_AGENT_ASAN_CRT_INTERCEPTORS_MACROS_H_
|