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 25 namespace OHOS { 26 namespace Security { 27 namespace CodeSign { 28 constexpr unsigned long MAP_XPM = 0x40; 29 const unsigned long PAGE_SIZE = (sysconf(_SC_PAGESIZE)); 30 const unsigned long PAGE_MASK = ~(PAGE_SIZE - 1); 31 32 const std::string XPM_DEBUG_FS_MODE_PATH = "/proc/sys/kernel/xpm/xpm_mode"; 33 const std::string SELINUX_MODE_PATH = "/sys/fs/selinux/enforce"; 34 const std::string PERMISSIVE_MODE = "0"; 35 const std::string ENFORCE_MODE = "1"; 36 SaveStringToFile(const std::string & filePath,const std::string & value)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 49 bool AllocXpmRegion(); 50 } // namespace CodeSign 51 } // namespace Security 52 } // namespace OHOS 53 54 #endif