1 /* 2 * Copyright (c) 2024 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 #ifndef JSVM_PLATFORM_H 17 #define JSVM_PLATFORM_H 18 #include <cstdint> 19 #include <cstdio> 20 #include <cstdlib> 21 #include <fstream> 22 #include <securec.h> 23 #include <string> 24 25 #ifdef TARGET_OHOS 26 #include "platform/platform_ohos.h" 27 #define OHOS_API_CALL(api_call) api_call 28 #else 29 #define OHOS_API_CALL(api_call) 30 #endif 31 32 namespace platform { 33 class OS { 34 public: 35 [[noreturn]] static void Abort(); 36 static uint64_t GetUid(); 37 static uint64_t GetPid(); 38 static uint64_t GetTid(); 39 40 enum class LogLevel : uint64_t { LOG_DEBUG = 0, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL }; 41 42 static void Print(LogLevel level, const char* format, ...) __attribute__((format(printf, 2, 3))); 43 static void PrintString(LogLevel level, const char* string); 44 }; 45 46 class RunJsTrace { 47 public: 48 explicit RunJsTrace(bool runJs); 49 explicit RunJsTrace(const char* name); 50 51 ~RunJsTrace(); 52 53 private: 54 bool runJs; 55 }; 56 } // namespace platform 57 58 #endif 59