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 CODE_SIGN_ATTR_UTILS_H
17 #define CODE_SIGN_ATTR_UTILS_H
18 
19 #include <stdint.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #if defined(__LP64__)
26 #define XPM_REGION_LEN 0x100000000
27 #else
28 #define XPM_REGION_LEN 0x10000000
29 #endif
30 
31 #define MAX_OWNERID_LEN 64
32 
33 #define OWNERID_SYSTEM_TAG "SYSTEM_LIB_ID"
34 #define OWNERID_DEBUG_TAG  "DEBUG_LIB_ID"
35 #define OWNERID_SHARED_TAG "SHARED_LIB_ID"
36 #define OWNERID_COMPAT_TAG "COMPAT_LIB_ID"
37 
38 enum FileOwneridType {
39     FILE_OWNERID_UNINT = 0,
40     FILE_OWNERID_SYSTEM,          // 1
41     FILE_OWNERID_APP,             // 2
42     FILE_OWNERID_DEBUG,           // 3
43     FILE_OWNERID_SHARED,          // 4
44     FILE_OWNERID_COMPAT,          // 5
45     FILE_OWNERID_EXTEND,          // 6
46     FILE_OWNERID_DEBUG_PLATFORM,  // 7
47     FILE_OWNERID_PLATFORM,        // 8
48     FILE_OWNERID_NWEB,            // 9
49     FILE_OWNERID_APP_TEMP_ALLOW,  // 10
50     FILE_OWNERID_MAX
51 };
52 
53 /* process and file ownerid types need to correspond to each other */
54 enum ProcessOwneridType {
55     PROCESS_OWNERID_UNINIT = FILE_OWNERID_UNINT,
56     PROCESS_OWNERID_SYSTEM,          // 1
57     PROCESS_OWNERID_APP,             // 2
58     PROCESS_OWNERID_DEBUG,           // 3
59     PROCESS_OWNERID_SHARED,          // 4
60     PROCESS_OWNERID_COMPAT,          // 5
61     PROCESS_OWNERID_EXTEND,          // 6
62     PROCESS_OWNERID_DEBUG_PLATFORM,  // 7
63     PROCESS_OWNERID_PLATFORM,        // 8
64     PROCESS_OWNERID_NWEB,            // 9
65     PROCESS_OWNERID_APP_TEMP_ALLOW,  // 10
66     PROCESS_OWNERID_MAX
67 };
68 
69 struct XpmConfig {
70     uint64_t regionAddr;
71     uint64_t regionLength;
72 
73     uint32_t idType;
74     char ownerId[MAX_OWNERID_LEN];
75 };
76 
77 int InitXpm(int enableJitFort, uint32_t idType, const char *ownerId);
78 
79 int SetXpmOwnerId(uint32_t idType, const char *ownerId);
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif // CODE_SIGN_ATTR_UTILS_H
86