• 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 <unistd.h>
22 
23 #include "ecmascript/log_wrapper.h"
24 
25 namespace panda::ecmascript {
MallocUsableSize(void * p)26 size_t MallocUsableSize(void *p)
27 {
28     return malloc_size(p);
29 }
30 
NumberOfCpuCore()31 uint32_t NumberOfCpuCore()
32 {
33     return static_cast<uint32_t>(sysconf(_SC_NPROCESSORS_ONLN));
34 }
35 
PhysicalSize()36 size_t PhysicalSize()
37 {
38     static constexpr int MIB_LENGTH = 2;
39     int mib[2];
40     mib[0] = CTL_HW;
41     mib[1] = HW_MEMSIZE;
42     int64_t size = 0;
43     size_t bufferLength = sizeof(size);
44     if (sysctl(mib, MIB_LENGTH, &size, &bufferLength, NULL, 0) != 0) {
45         LOG_ECMA(FATAL) << "sysctl error";
46     }
47     return static_cast<size_t>(size);
48 }
49 
PrctlSetVMA(const void * p,const size_t size,const char * tag)50 int PrctlSetVMA([[maybe_unused]] const void *p, [[maybe_unused]] const size_t size, [[maybe_unused]] const char *tag)
51 {
52     return -1;
53 }
54 
PtracePeektext(int pid,uintptr_t addr)55 long PtracePeektext([[maybe_unused]] int pid, [[maybe_unused]] uintptr_t addr)
56 {
57     return static_cast<long>(-1);
58 }
59 }  // namespace panda::ecmascript
60