• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "ecmascript/compiler/aot_file/binary_buffer_parser.h"
16 #include "ecmascript/compiler/compiler_log.h"
17 
18 namespace panda::ecmascript {
ParseBuffer(void * dst,uint32_t count)19 void BinaryBufferParser::ParseBuffer(void *dst, uint32_t count)
20 {
21     if (count > 0 && count + offset_ <= length_) {
22         if (memcpy_s(dst, count, buffer_ + offset_, count) != EOK) {
23             LOG_FULL(FATAL) << "memcpy_s failed";
24         }
25         offset_ = offset_ + count;
26     } else {
27         LOG_FULL(FATAL) << "parse buffer error, length is 0 or overflow";
28     }
29 }
30 
ParseBuffer(void * dst,uint32_t count,uint32_t offset)31 void BinaryBufferParser::ParseBuffer(void *dst, uint32_t count, uint32_t offset)
32 {
33     offset_ = offset;
34     ParseBuffer(dst, count);
35 }
36 
ParseBuffer(uint8_t * dst,uint32_t count,uint8_t * src)37 void BinaryBufferParser::ParseBuffer(uint8_t *dst, uint32_t count, uint8_t *src)
38 {
39     if (src >= buffer_ && src + count <= buffer_ + length_) {
40         if (memcpy_s(dst, count, src, count) != EOK) {
41             LOG_FULL(FATAL) << "memcpy_s failed";
42         }
43     } else {
44         LOG_FULL(FATAL) << "parse buffer error, length is 0 or overflow";
45     }
46 }
47 }  // namespace panda::ecmascript
48