diff options
Diffstat (limited to 'deps/v8/src/utils.h')
-rw-r--r-- | deps/v8/src/utils.h | 120 |
1 files changed, 19 insertions, 101 deletions
diff --git a/deps/v8/src/utils.h b/deps/v8/src/utils.h index b922332172d..9f4bb08614a 100644 --- a/deps/v8/src/utils.h +++ b/deps/v8/src/utils.h @@ -9,6 +9,7 @@ #include <stdlib.h> #include <string.h> #include <cmath> +#include <string> #include <type_traits> #include "include/v8.h" @@ -1079,12 +1080,6 @@ inline void Flush() { char* ReadLine(const char* prompt); -// Read and return the raw bytes in a file. the size of the buffer is returned -// in size. -// The returned buffer must be freed by the caller. -byte* ReadBytes(const char* filename, int* size, bool verbose = true); - - // Append size chars from str to the file given by filename. // The file is overwritten. Returns the number of chars written. int AppendChars(const char* filename, @@ -1228,16 +1223,11 @@ inline void MemsetPointer(T** dest, U* value, int counter) { #undef STOS } - -// Simple support to read a file into a 0-terminated C-string. -// The returned buffer must be freed by the caller. +// Simple support to read a file into std::string. // On return, *exits tells whether the file existed. -V8_EXPORT_PRIVATE Vector<const char> ReadFile(const char* filename, - bool* exists, - bool verbose = true); -Vector<const char> ReadFile(FILE* file, - bool* exists, - bool verbose = true); +V8_EXPORT_PRIVATE std::string ReadFile(const char* filename, bool* exists, + bool verbose = true); +std::string ReadFile(FILE* file, bool* exists, bool verbose = true); template <typename sourcechar, typename sinkchar> V8_INLINE static void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, @@ -1572,92 +1562,11 @@ bool DoubleToBoolean(double d); template <typename Stream> bool StringToArrayIndex(Stream* stream, uint32_t* index); -// Returns current value of top of the stack. Works correctly with ASAN. -DISABLE_ASAN -inline uintptr_t GetCurrentStackPosition() { - // Takes the address of the limit variable in order to find out where - // the top of stack is right now. - uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); - return limit; -} - -template <typename V> -static inline V ReadUnalignedValue(Address p) { - ASSERT_TRIVIALLY_COPYABLE(V); -#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM) - return *reinterpret_cast<const V*>(p); -#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM - V r; - memmove(&r, reinterpret_cast<void*>(p), sizeof(V)); - return r; -#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM -} - -template <typename V> -static inline void WriteUnalignedValue(Address p, V value) { - ASSERT_TRIVIALLY_COPYABLE(V); -#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM) - *(reinterpret_cast<V*>(p)) = value; -#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM - memmove(reinterpret_cast<void*>(p), &value, sizeof(V)); -#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM -} - -static inline double ReadFloatValue(Address p) { - return ReadUnalignedValue<float>(p); -} - -static inline double ReadDoubleValue(Address p) { - return ReadUnalignedValue<double>(p); -} - -static inline void WriteDoubleValue(Address p, double value) { - WriteUnalignedValue(p, value); -} - -static inline uint16_t ReadUnalignedUInt16(Address p) { - return ReadUnalignedValue<uint16_t>(p); -} - -static inline void WriteUnalignedUInt16(Address p, uint16_t value) { - WriteUnalignedValue(p, value); -} - -static inline uint32_t ReadUnalignedUInt32(Address p) { - return ReadUnalignedValue<uint32_t>(p); -} - -static inline void WriteUnalignedUInt32(Address p, uint32_t value) { - WriteUnalignedValue(p, value); -} - -template <typename V> -static inline V ReadLittleEndianValue(Address p) { -#if defined(V8_TARGET_LITTLE_ENDIAN) - return ReadUnalignedValue<V>(p); -#elif defined(V8_TARGET_BIG_ENDIAN) - V ret{}; - const byte* src = reinterpret_cast<const byte*>(p); - byte* dst = reinterpret_cast<byte*>(&ret); - for (size_t i = 0; i < sizeof(V); i++) { - dst[i] = src[sizeof(V) - i - 1]; - } - return ret; -#endif // V8_TARGET_LITTLE_ENDIAN -} - -template <typename V> -static inline void WriteLittleEndianValue(Address p, V value) { -#if defined(V8_TARGET_LITTLE_ENDIAN) - WriteUnalignedValue<V>(p, value); -#elif defined(V8_TARGET_BIG_ENDIAN) - byte* src = reinterpret_cast<byte*>(&value); - byte* dst = reinterpret_cast<byte*>(p); - for (size_t i = 0; i < sizeof(V); i++) { - dst[i] = src[sizeof(V) - i - 1]; - } -#endif // V8_TARGET_LITTLE_ENDIAN -} +// Returns the current stack top. Works correctly with ASAN and SafeStack. +// GetCurrentStackPosition() should not be inlined, because it works on stack +// frames if it were inlined into a function with a huge stack frame it would +// return an address significantly above the actual current stack position. +V8_NOINLINE uintptr_t GetCurrentStackPosition(); template <typename V> static inline V ByteReverse(V value) { @@ -1807,6 +1716,15 @@ class ThreadedList final { V8_EXPORT_PRIVATE bool PassesFilter(Vector<const char> name, Vector<const char> filter); +// Zap the specified area with a specific byte pattern. This currently defaults +// to int3 on x64 and ia32. On other architectures this will produce unspecified +// instruction sequences. +// TODO(jgruber): Better support for other architectures. +V8_INLINE void ZapCode(Address addr, size_t size_in_bytes) { + static constexpr int kZapByte = 0xCC; + std::memset(reinterpret_cast<void*>(addr), kZapByte, size_in_bytes); +} + } // namespace internal } // namespace v8 |