Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2492)

Unified Diff: syzygy/agent/asan/memory_interceptors_impl_x64.cc

Issue 2316303008: Add probes for x64. (Closed)
Patch Set: Rename |heap_size| to |address_space_size|. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..49646777abf3392ae17dc36f7aed18207aa7bb7c
--- /dev/null
+++ b/syzygy/agent/asan/memory_interceptors_impl_x64.cc
@@ -0,0 +1,90 @@
+// 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.
+
+// The C++ implementation of the memory interceptors, intended to work on win64,
+// unlike the win32 implementation, written (generated) in pure assembly.
+// This implementation provides less functions than the original win32 one,
+// as it's intended to be used outside of Syzygy.
+
+#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"
+
+// The template function that performs the checks.
+// @param access_size Access size in bytes.
Sébastien Marchand 2016/09/13 18:23:05 nit, for the template parameters we annotate them
+// @param address_space_size The virtual address space size limit in bytes.
+// It's 8 TB for Win7 and Win8 and 128 TB for Win8.1+.
+// @param access_mode The access mode, which can be any of AccessMode values,
+// allthough this file only exports the probes for read and write accesses.
+// @param addr The address being accessed.
+template<size_t access_size, size_t address_space_size,
+ agent::asan::AccessMode access_mode>
+void asan_check(const void* addr) {
+ using namespace agent::asan;
Sébastien Marchand 2016/09/13 18:23:05 We never use 'using ...' inside a function, do thi
+ if (reinterpret_cast<uintptr_t>(addr) >= address_space_size ||
+ !AsanRuntime::runtime()->shadow()->IsRangeAccessible(addr, access_size)) {
+ CONTEXT ctx = {};
+ ::RtlCaptureContext(&ctx);
+ AsanContext asan_ctx = {};
+ ContextToAsanContext(ctx, &asan_ctx);
+ ReportBadMemoryAccess(addr, access_mode, access_size, asan_ctx);
+ }
+}
+
+// A few macros to instantiate 'asan_check' and export the instantiations
+// with appropriate names.
+
+#define EXPORT_INTERCEPTOR_READ(access_size, suffix, address_space_size) \
+void asan_check_##access_size##_byte_read_access_no_flags_##suffix( \
+ const void* addr) { \
+ return asan_check<access_size, address_space_size, \
+ agent::asan::ASAN_READ_ACCESS>(addr); \
+} \
+void asan_check_##access_size##_byte_read_access_##suffix(const void* addr) { \
+ return asan_check<access_size, address_space_size, \
+ agent::asan::ASAN_READ_ACCESS>(addr); \
+}
+
+#define EXPORT_INTERCEPTOR_WRITE(access_size, suffix, address_space_size) \
+void asan_check_##access_size##_byte_write_access_no_flags_##suffix( \
Sébastien Marchand 2016/09/13 18:23:05 You don't seem to be using the address_space_size
+ const void* addr) { \
+ return asan_check<access_size, address_space_size, \
+ agent::asan::ASAN_WRITE_ACCESS>(addr); \
+} \
+void asan_check_##access_size##_byte_write_access_##suffix(const void* addr) { \
+ return asan_check<access_size, address_space_size, \
+ agent::asan::ASAN_WRITE_ACCESS>(addr); \
+}
+
+#define EXPORT_INTERCEPTOR(access_size, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR_READ(access_size, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR_WRITE(access_size, suffix, address_space_size)
+
+#define EXPORT_INTERCEPTORS_ALL_SIZES(suffix, address_space_size) \
+ EXPORT_INTERCEPTOR(1, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR(2, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR(4, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR(8, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR(10, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR(16, suffix, address_space_size) \
+ EXPORT_INTERCEPTOR(32, suffix, address_space_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)
Sébastien Marchand 2016/09/13 18:23:05 There's some extra spaces in front of the static_c
Sébastien Marchand 2016/09/13 18:23:05 The '40' isn't obvious, can you move it to a const
+ EXPORT_INTERCEPTORS_ALL_SIZES(128tb, static_cast<size_t>(128) << 40)
+}

Powered by Google App Engine
This is Rietveld 408576698