diff options
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_local_address_space_view.h')
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_local_address_space_view.h | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_local_address_space_view.h b/compiler-rt/lib/sanitizer_common/sanitizer_local_address_space_view.h index f9507c701e2..ec1847abc53 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_local_address_space_view.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_local_address_space_view.h @@ -31,18 +31,42 @@ namespace __sanitizer { struct LocalAddressSpaceView { - // Load memory `sizeof(T) * num_elements` bytes of memory - // from the target process (always local for this implementation) - // starting at address `target_address`. The local copy of - // this memory is returned as a pointer. It is guaranteed that + // Load memory `sizeof(T) * num_elements` bytes of memory from the target + // process (always local for this implementation) starting at address + // `target_address`. The local copy of this memory is returned as a pointer. + // The caller should not write to this memory. The behaviour when doing so is + // undefined. Callers should use `LoadWritable()` to get access to memory + // that is writable. // - // * That the function will always return the same value - // for a given set of arguments. - // * That the memory returned is writable and that writes will persist. + // The lifetime of loaded memory is implementation defined. + template <typename T> + static const T *Load(const T *target_address, uptr num_elements = 1) { + // The target address space is the local address space so + // nothing needs to be copied. Just return the pointer. + return target_address; + } + + // Load memory `sizeof(T) * num_elements` bytes of memory from the target + // process (always local for this implementation) starting at address + // `target_address`. The local copy of this memory is returned as a pointer. + // The memory returned may be written to. + // + // Writes made to the returned memory will be visible in the memory returned + // by subsequent `Load()` or `LoadWritable()` calls provided the + // `target_address` parameter is the same. It is not guaranteed that the + // memory returned by previous calls to `Load()` will contain any performed + // writes. If two or more overlapping regions of memory are loaded via + // separate calls to `LoadWritable()`, it is implementation defined whether + // writes made to the region returned by one call are visible in the regions + // returned by other calls. + // + // Given the above it is recommended to load the largest possible object + // that requires modification (e.g. a class) rather than individual fields + // from a class to avoid issues with overlapping writable regions. // // The lifetime of loaded memory is implementation defined. template <typename T> - static T *Load(T *target_address, uptr num_elements = 1) { + static T *LoadWritable(T *target_address, uptr num_elements = 1) { // The target address space is the local address space so // nothing needs to be copied. Just return the pointer. return target_address; |