Index: syzygy/agent/asan/memory_interceptors_impl_x64.cc |
diff --git a/syzygy/agent/asan/memory_interceptors_impl_x64.cc b/syzygy/agent/asan/memory_interceptors_impl_x64.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7b07c2e70cd4f4ba38fe3eb01e73650669550c6a |
--- /dev/null |
+++ b/syzygy/agent/asan/memory_interceptors_impl_x64.cc |
@@ -0,0 +1,76 @@ |
+// Copyright 2016 Google Inc. All Rights Reserved. |
+// |
+// Licensed under the Apache License, Version 2.0 (the "License"); |
+// you may not use this file except in compliance with the License. |
+// You may obtain a copy of the License at |
+// |
+// http://www.apache.org/licenses/LICENSE-2.0 |
+// |
+// Unless required by applicable law or agreed to in writing, software |
+// distributed under the License is distributed on an "AS IS" BASIS, |
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+// See the License for the specific language governing permissions and |
+// limitations under the License. |
+ |
Sébastien Marchand
2016/09/12 20:12:22
Please add a global comment describing the content
|
+#include "syzygy/agent/asan/error_info.h" |
+#include "syzygy/agent/asan/rtl_utils.h" |
+#include "syzygy/agent/asan/runtime.h" |
+#include "syzygy/agent/asan/shadow.h" |
+ |
+template<size_t access_size, size_t heap_size, |
+ agent::asan::AccessMode access_mode> |
+void asan_check(const void* addr) { |
+ using namespace agent::asan; |
+ if (reinterpret_cast<uintptr_t>(addr) >= heap_size || |
+ !AsanRuntime::runtime()->shadow()->IsRangeAccessible(addr, access_size)) { |
+ CONTEXT ctx; |
Sébastien Marchand
2016/09/12 20:12:22
Add " = {}" to initialize this variable.
|
+ ::RtlCaptureContext(&ctx); |
+ AsanContext asan_ctx; |
Sébastien Marchand
2016/09/12 20:12:22
Ditto.
|
+ ContextToAsanContext(ctx, &asan_ctx); |
+ ReportBadMemoryAccess(addr, access_mode, access_size, asan_ctx); |
+ } |
+} |
+ |
+ |
Sébastien Marchand
2016/09/12 20:12:22
There's an extra BL
|
+#define EXPORT_INTERCEPTOR_READ(access_size, suffix, heap_size) \ |
+void asan_check_##access_size##_byte_read_access_no_flags_##suffix( \ |
Sébastien Marchand
2016/09/12 20:12:22
Can you add a comment describing the different var
|
+ const void* addr) { \ |
+ return asan_check<access_size, heap_size, \ |
+ agent::asan::ASAN_READ_ACCESS>(addr); \ |
+} \ |
+void asan_check_##access_size##_byte_read_access_##suffix(const void* addr) { \ |
+ return asan_check<access_size, heap_size, \ |
+ agent::asan::ASAN_READ_ACCESS>(addr); \ |
+} |
+ |
+#define EXPORT_INTERCEPTOR_WRITE(access_size, suffix, heap_size) \ |
+void asan_check_##access_size##_byte_write_access_no_flags_##suffix( \ |
+ const void* addr) { \ |
+ return asan_check<access_size, heap_size, \ |
+ agent::asan::ASAN_WRITE_ACCESS>(addr); \ |
+} \ |
+void asan_check_##access_size##_byte_write_access_##suffix(const void* addr) { \ |
+ return asan_check<access_size, heap_size, \ |
+ agent::asan::ASAN_WRITE_ACCESS>(addr); \ |
+} |
+ |
+#define EXPORT_INTERCEPTOR(access_size, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR_READ(access_size, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR_WRITE(access_size, suffix, heap_size) |
+ |
+#define EXPORT_INTERCEPTORS_ALL_SIZES(suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR(1, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR(2, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR(4, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR(8, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR(10, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR(16, suffix, heap_size) \ |
+ EXPORT_INTERCEPTOR(32, suffix, heap_size) |
+ |
+extern "C" { |
+ void asan_no_check() { return; } |
+ void asan_string_no_check() { return; } |
+ void* asan_shadow_references[] = { nullptr }; |
+ EXPORT_INTERCEPTORS_ALL_SIZES(8tb, static_cast<size_t>(8) << 40) |
+ EXPORT_INTERCEPTORS_ALL_SIZES(128tb, static_cast<size_t>(128) << 40) |
+} |