18e920a95Sopenharmony_ci/* 28e920a95Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 38e920a95Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48e920a95Sopenharmony_ci * you may not use this file except in compliance with the License. 58e920a95Sopenharmony_ci * You may obtain a copy of the License at 68e920a95Sopenharmony_ci * 78e920a95Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88e920a95Sopenharmony_ci * 98e920a95Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108e920a95Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118e920a95Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128e920a95Sopenharmony_ci * See the License for the specific language governing permissions and 138e920a95Sopenharmony_ci * limitations under the License. 148e920a95Sopenharmony_ci */ 158e920a95Sopenharmony_ci 168e920a95Sopenharmony_ci#ifndef XPM_COMMON_TEST_H 178e920a95Sopenharmony_ci#define XPM_COMMON_TEST_H 188e920a95Sopenharmony_ci 198e920a95Sopenharmony_ci#include <fstream> 208e920a95Sopenharmony_ci#include <iostream> 218e920a95Sopenharmony_ci#include <string> 228e920a95Sopenharmony_ci#include <unistd.h> 238e920a95Sopenharmony_ci#include <sys/ioctl.h> 248e920a95Sopenharmony_ci 258e920a95Sopenharmony_cinamespace OHOS { 268e920a95Sopenharmony_cinamespace Security { 278e920a95Sopenharmony_cinamespace CodeSign { 288e920a95Sopenharmony_ciconstexpr unsigned long MAP_XPM = 0x40; 298e920a95Sopenharmony_ciconst unsigned long PAGE_SIZE = (sysconf(_SC_PAGESIZE)); 308e920a95Sopenharmony_ciconst unsigned long PAGE_MASK = ~(PAGE_SIZE - 1); 318e920a95Sopenharmony_ci 328e920a95Sopenharmony_ciconst std::string XPM_DEBUG_FS_MODE_PATH = "/proc/sys/kernel/xpm/xpm_mode"; 338e920a95Sopenharmony_ciconst std::string SELINUX_MODE_PATH = "/sys/fs/selinux/enforce"; 348e920a95Sopenharmony_ciconst std::string PERMISSIVE_MODE = "0"; 358e920a95Sopenharmony_ciconst std::string ENFORCE_MODE = "1"; 368e920a95Sopenharmony_ci 378e920a95Sopenharmony_ciinline bool SaveStringToFile(const std::string &filePath, 388e920a95Sopenharmony_ci const std::string &value) 398e920a95Sopenharmony_ci{ 408e920a95Sopenharmony_ci std::fstream fout(filePath, std::ios::out); 418e920a95Sopenharmony_ci if (!fout.is_open()) { 428e920a95Sopenharmony_ci return false; 438e920a95Sopenharmony_ci } 448e920a95Sopenharmony_ci fout << value; 458e920a95Sopenharmony_ci fout.close(); 468e920a95Sopenharmony_ci return true; 478e920a95Sopenharmony_ci} 488e920a95Sopenharmony_ci 498e920a95Sopenharmony_cibool AllocXpmRegion(); 508e920a95Sopenharmony_ci} // namespace CodeSign 518e920a95Sopenharmony_ci} // namespace Security 528e920a95Sopenharmony_ci} // namespace OHOS 538e920a95Sopenharmony_ci 548e920a95Sopenharmony_ci#endif