1// Copyright 2018 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "src/utils/memcopy.h" 6 7#include "src/snapshot/embedded/embedded-data-inl.h" 8 9namespace v8 { 10namespace internal { 11 12#if V8_TARGET_ARCH_IA32 13static void MemMoveWrapper(void* dest, const void* src, size_t size) { 14 memmove(dest, src, size); 15} 16 17// Initialize to library version so we can call this at any time during startup. 18static MemMoveFunction memmove_function = &MemMoveWrapper; 19 20// Copy memory area to disjoint memory area. 21DISABLE_CFI_ICALL 22V8_EXPORT_PRIVATE void MemMove(void* dest, const void* src, size_t size) { 23 if (size == 0) return; 24 // Note: here we rely on dependent reads being ordered. This is true 25 // on all architectures we currently support. 26 (*memmove_function)(dest, src, size); 27} 28#elif(V8_OS_POSIX || V8_OS_STARBOARD) && V8_HOST_ARCH_ARM 29V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function = 30 &MemCopyUint8Wrapper; 31#elif V8_OS_POSIX && V8_HOST_ARCH_MIPS 32V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function = 33 &MemCopyUint8Wrapper; 34#endif 35 36void init_memcopy_functions() { 37#if V8_TARGET_ARCH_IA32 38 if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) { 39 EmbeddedData d = EmbeddedData::FromBlob(); 40 memmove_function = reinterpret_cast<MemMoveFunction>( 41 d.InstructionStartOfBuiltin(Builtin::kMemMove)); 42 } 43#elif(V8_OS_POSIX || V8_OS_STARBOARD) && V8_HOST_ARCH_ARM 44 if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) { 45 EmbeddedData d = EmbeddedData::FromBlob(); 46 memcopy_uint8_function = reinterpret_cast<MemCopyUint8Function>( 47 d.InstructionStartOfBuiltin(Builtin::kMemCopyUint8Uint8)); 48 } 49#elif V8_OS_POSIX && V8_HOST_ARCH_MIPS 50 if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) { 51 EmbeddedData d = EmbeddedData::FromBlob(); 52 memcopy_uint8_function = reinterpret_cast<MemCopyUint8Function>( 53 d.InstructionStartOfBuiltin(Builtin::kMemCopyUint8Uint8)); 54 } 55#endif 56} 57 58} // namespace internal 59} // namespace v8 60