• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ASHMEM_IMPL_H
16 #define ASHMEM_IMPL_H
17 
18 #include "ashmem.h"
19 #include "ffi_remote_data.h"
20 #include "ipc_utils_ffi.h"
21 #include "securec.h"
22 
23 namespace OHOS {
24 class AshmemImpl : public OHOS::FFI::FFIData {
25     DECL_TYPE(MessageSequenceImpl, OHOS::FFI::FFIData)
26 public:
27     enum {
28         PROT_EXEC = 4,
29         PROT_NONE = 0,
30         PROT_READ = 1,
31         PROT_WRITE = 2,
32     };
33     explicit AshmemImpl(sptr<Ashmem> ashmem);
34     ~AshmemImpl() = default;
GetAshmem()35     const sptr<Ashmem>& GetAshmem()
36     {
37         return ashmem_;
38     }
SetAshmem(sptr<Ashmem> & ashmem)39     void SetAshmem(sptr<Ashmem>& ashmem)
40     {
41         ashmem_ = ashmem;
42     }
43     void CloseAshmem();
44     int32_t GetAshmemSize(int32_t* errCode);
45     int32_t MapTypedAshmem(uint32_t mapType);
46     int32_t MapReadWriteAshmem();
47     int32_t MapReadonlyAshmem();
48     void UnmapAshmem();
49     int32_t SetProtectionType(uint32_t protectionType);
50     int32_t WriteDataToAshmem(uint8_t* data, int64_t size, int64_t offset);
51     uint8_t* ReadDataFromAshmem(int64_t size, int64_t offset, int32_t* errCode);
52 
53 private:
54     sptr<Ashmem> ashmem_;
55 };
56 } // namespace OHOS
57 
58 #endif