1 /*
2 * Copyright (c) 2025 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 #include "common_components/log/log.h"
17 #include "securec.h"
18
19 namespace common {
MemorySet(uintptr_t dest,size_t size,int c,size_t count)20 void MemorySet(uintptr_t dest, size_t size, int c, size_t count)
21 {
22 uintptr_t destAddress = dest;
23 while (size != 0) {
24 size_t sizePerChunk = size > SECUREC_MEM_MAX_LEN ? SECUREC_MEM_MAX_LEN : size;
25 size_t countPerChunk = count > SECUREC_MEM_MAX_LEN ? SECUREC_MEM_MAX_LEN : count;
26 LOGE_IF(memset_s(reinterpret_cast<void*>(destAddress), sizePerChunk, c, countPerChunk) != EOK) <<
27 "memset_s fail";
28 size -= sizePerChunk;
29 count -= countPerChunk;
30 destAddress += sizePerChunk;
31 }
32 }
33
MemoryCopy(uintptr_t dest,size_t size,const uintptr_t src,size_t count)34 void MemoryCopy(uintptr_t dest, size_t size, const uintptr_t src, size_t count)
35 {
36 uintptr_t destAddress = dest;
37 uintptr_t srcAddress = src;
38 while (size != 0) {
39 size_t sizePerChunk = size > SECUREC_MEM_MAX_LEN ? SECUREC_MEM_MAX_LEN : size;
40 size_t countPerChunk = count > SECUREC_MEM_MAX_LEN ? SECUREC_MEM_MAX_LEN : count;
41 LOGE_IF(memcpy_s(reinterpret_cast<void*>(destAddress), sizePerChunk, reinterpret_cast<void*>(srcAddress),
42 countPerChunk) != EOK) << "memcpy_s fail";
43 size -= sizePerChunk;
44 count -= countPerChunk;
45 destAddress += sizePerChunk;
46 srcAddress += sizePerChunk;
47 }
48 }
49 } // namespace common
50