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
9 namespace v8 {
10 namespace internal {
11
12 #if V8_TARGET_ARCH_IA32
MemMoveWrapper(void * dest,const void * src,size_t size)13 static 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.
18 static MemMoveFunction memmove_function = &MemMoveWrapper;
19
20 // Copy memory area to disjoint memory area.
21 DISABLE_CFI_ICALL
MemMove(void * dest,const void * src,size_t size)22 V8_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
29 V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function =
30 &MemCopyUint8Wrapper;
31 #elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
32 V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function =
33 &MemCopyUint8Wrapper;
34 #endif
35
init_memcopy_functions()36 void 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