• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "ecmascript/platform/os.h"
17 
18 #include <ctime>
19 #include <malloc/malloc.h>
20 #include <sys/sysctl.h>
21 #include <sys/types.h>
22 #include <sys/xattr.h>
23 #include <unistd.h>
24 
25 #include "ecmascript/log_wrapper.h"
26 
27 namespace panda::ecmascript {
MallocUsableSize(void * p)28 size_t MallocUsableSize(void *p)
29 {
30     return malloc_size(p);
31 }
32 
PrctlSetVMA(const void * p,const size_t size,const char * tag)33 int PrctlSetVMA([[maybe_unused]] const void *p, [[maybe_unused]] const size_t size, [[maybe_unused]] const char *tag)
34 {
35     return -1;
36 }
37 
PtracePeektext(int pid,uintptr_t addr)38 long PtracePeektext([[maybe_unused]] int pid, [[maybe_unused]] uintptr_t addr)
39 {
40     return static_cast<long>(-1);
41 }
42 
BindSmallCpuCore()43 void BindSmallCpuCore()
44 {
45     LOG_ECMA(INFO) << "Bind Small Core in macos not support";
46 }
47 
BindMidCpuCore()48 void BindMidCpuCore()
49 {
50     LOG_ECMA(INFO) << "Bind Mid Core in macos not support";
51 }
52 
BindAllCpuCore()53 void BindAllCpuCore()
54 {
55     LOG_ECMA(INFO) << "Bind All Core in macos not support";
56 }
57 
PageMapExecFortSpace(void * addr,size_t size,int prot)58 void *PageMapExecFortSpace(void *addr, [[maybe_unused]] size_t size, [[maybe_unused]] int prot)
59 {
60     // basically no op
61     return addr;
62 }
63 
SetSecurityLabel(const std::string & path)64 void SetSecurityLabel(const std::string& path)
65 {
66     auto xattrValueSize = getxattr(path.c_str(), XATTR_KEY, nullptr, 0, 0, 0);
67     if (xattrValueSize == static_cast<ssize_t>(DEFAULT_DATA_LENGTH)) {
68         char xattrValue[DEFAULT_DATA_LENGTH + 1];
69         xattrValueSize = getxattr(path.c_str(), XATTR_KEY, xattrValue, xattrValueSize, 0, 0);
70         xattrValue[DEFAULT_DATA_LENGTH] = '\0';
71     }
72 
73     if (setxattr(path.c_str(), XATTR_KEY, DEFAULT_DATA_LEVEL.data(), DEFAULT_DATA_LEVEL.size(), 0, 0) < 0) {
74         LOG_ECMA(DEBUG) << "set label failed! level: " << DEFAULT_DATA_LEVEL << ", file: " << path;
75     }
76 }
77 
HasJitFortACL()78 bool HasJitFortACL()
79 {
80     LOG_ECMA(INFO) << "Get Jit Fort ACL in mac not support";
81     return false;
82 }
83 
InitializeMallocConfig()84 void InitializeMallocConfig()
85 {
86     LOG_ECMA(INFO) << "Initialize Malloc Config in mac not support";
87 }
88 
CheckDiskSpace(const std::string & path,size_t requiredBytes)89 bool CheckDiskSpace(const std::string& path, size_t requiredBytes)
90 {
91     LOG_ECMA(INFO) << "Check Disk Space not support in Mac";
92     return true;
93 }
94 
GetDeviceValidSize(const std::string & path)95 uint64_t GetDeviceValidSize(const std::string &path)
96 {
97     return 0;
98 }
99 }  // namespace panda::ecmascript
100