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 16#ifndef XPM_COMMON_TEST_H 17#define XPM_COMMON_TEST_H 18 19#include <fstream> 20#include <iostream> 21#include <string> 22#include <unistd.h> 23#include <sys/ioctl.h> 24 25namespace OHOS { 26namespace Security { 27namespace CodeSign { 28constexpr unsigned long MAP_XPM = 0x40; 29const unsigned long PAGE_SIZE = (sysconf(_SC_PAGESIZE)); 30const unsigned long PAGE_MASK = ~(PAGE_SIZE - 1); 31 32const std::string XPM_DEBUG_FS_MODE_PATH = "/proc/sys/kernel/xpm/xpm_mode"; 33const std::string SELINUX_MODE_PATH = "/sys/fs/selinux/enforce"; 34const std::string PERMISSIVE_MODE = "0"; 35const std::string ENFORCE_MODE = "1"; 36 37inline bool SaveStringToFile(const std::string &filePath, 38 const std::string &value) 39{ 40 std::fstream fout(filePath, std::ios::out); 41 if (!fout.is_open()) { 42 return false; 43 } 44 fout << value; 45 fout.close(); 46 return true; 47} 48 49bool AllocXpmRegion(); 50} // namespace CodeSign 51} // namespace Security 52} // namespace OHOS 53 54#endif