• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_MEM_UTILS_H
17 #define ECMASCRIPT_MEM_UTILS_H
18 
19 #include "ecmascript/ecma_macros.h"
20 #include "securec.h"
21 
22 namespace panda::ecmascript {
23 class Utils {
24 public:
Copy(void * dest,size_t destCount,void * src,size_t count)25     static ARK_INLINE void Copy(void *dest, size_t destCount, void *src, size_t count)
26     {
27         switch (count) {
28 #define COPY_BY_CONST(destCount, value)                              \
29             case value:                                              \
30                 if (memcpy_sp(dest, destCount, src, value) != EOK) { \
31                     LOG_ECMA(FATAL) << "memcpy_s failed";            \
32                 }                                                    \
33                 break;
34             COPY_BY_CONST(destCount, 16)
35             COPY_BY_CONST(destCount, 24)
36             COPY_BY_CONST(destCount, 32)
37             COPY_BY_CONST(destCount, 40)
38             COPY_BY_CONST(destCount, 48)
39             COPY_BY_CONST(destCount, 56)
40             COPY_BY_CONST(destCount, 64)
41             COPY_BY_CONST(destCount, 72)
42             COPY_BY_CONST(destCount, 80)
43             COPY_BY_CONST(destCount, 88)
44             COPY_BY_CONST(destCount, 96)
45             COPY_BY_CONST(destCount, 104)
46             COPY_BY_CONST(destCount, 112)
47             COPY_BY_CONST(destCount, 120)
48             COPY_BY_CONST(destCount, 128)
49 #undef COPY_BY_CONST
50             default:
51                 if (memcpy_s(dest, destCount, src, count) != EOK) {
52                     LOG_ECMA(FATAL) << "memcpy_s failed";
53                 }
54         }
55     }
56 };
57 }  // namespace panda::ecmascript
58 #endif  // ECMASCRIPT_MEM_UTILS_H
59