• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BASE_STARTUP_PARAM_COMMON_H
17 #define BASE_STARTUP_PARAM_COMMON_H
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <stdarg.h>
21 #ifndef __LITEOS_M__
22 #include <pthread.h>
23 #endif
24 #include "param_atomic.h"
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 // support mutex
32 #ifndef __LITEOS_M__
33 typedef struct {
34     pthread_rwlock_t rwlock;
35 } ParamRWMutex;
36 
37 typedef struct {
38     pthread_mutex_t mutex;
39 } ParamMutex;
40 #else
41 typedef struct {
42     uint32_t mutex;
43 } ParamRWMutex;
44 
45 typedef struct {
46     uint32_t mutex;
47 } ParamMutex;
48 #endif
49 
50 typedef struct {
51     int shmid;
52 } MemHandle;
53 
54 typedef struct {
55     uint32_t left;
56     uint32_t right;
57     uint32_t child;
58     uint32_t labelIndex;
59     uint32_t dataIndex;
60     uint16_t selinuxLabel;
61     uint16_t length;
62     char key[0];
63 } ParamTrieNode;
64 
65 #define PARAM_FLAGS_MODIFY 0x80000000
66 #define PARAM_FLAGS_TRIGGED 0x40000000
67 #define PARAM_FLAGS_WAITED 0x20000000
68 #define PARAM_FLAGS_COMMITID 0x0000ffff
69 
70 #define PARAM_TYPE_MASK   0x0f
71 #define PARAM_TYPE_STRING 0x00
72 #define PARAM_TYPE_INT    0x01
73 #define PARAM_TYPE_BOOL   0x02
74 
75 typedef struct {
76     ATOMIC_UINT32 commitId;
77     uint8_t type;
78     uint8_t keyLength;
79     uint16_t valueLength;
80     char data[0];
81 } ParamNode;
82 
83 typedef struct {
84     uid_t uid;
85     gid_t gid;
86     uint32_t selinuxIndex;
87     uint16_t mode;
88     uint8_t type;
89     uint8_t length;
90     uint32_t memberNum;
91     uid_t members[0];
92 } ParamSecurityNode;
93 
94 typedef struct {
95     ATOMIC_LLONG commitId;
96     ATOMIC_LLONG commitPersistId;
97     uint32_t trieNodeCount;
98     uint32_t paramNodeCount;
99     uint32_t securityNodeCount;
100     uint32_t currOffset;
101     uint32_t spaceSizeOffset;
102     uint32_t firstNode;
103     uint32_t dataSize;
104     char data[0];
105 } ParamTrieHeader;
106 
107 typedef struct WorkSpace_ {
108     unsigned int flags;
109     MemHandle memHandle;
110     ParamTrieHeader *area;
111     ATOMIC_UINT32 rwSpaceLock;
112     uint32_t spaceSize;
113     uint32_t spaceIndex;
114     ParamRWMutex rwlock;
115     char fileName[0];
116 } WorkSpace;
117 
118 typedef struct {
119     uint8_t updaterMode;
120     void (*logFunc)(int logLevel, uint32_t domain, const char *tag, const char *fmt, va_list vargs);
121     int (*setfilecon)(const char *name, const char *content);
122     int (*getServiceGroupIdByPid)(pid_t pid, gid_t *gids, uint32_t gidSize);
123 } PARAM_WORKSPACE_OPS;
124 
125 typedef struct CachedParameter_ {
126     struct WorkSpace_ *workspace;
127     const char *(*cachedParameterCheck)(struct CachedParameter_ *param, int *changed);
128     long long spaceCommitId;
129     uint32_t dataCommitId;
130     uint32_t dataIndex;
131     uint32_t bufferLen;
132     uint32_t nameLen;
133     char *paramValue;
134     char data[0];
135 } CachedParameter;
136 
137 typedef void *CachedHandle;
138 
139 typedef struct _SpaceSize {
140     uint32_t maxLabelIndex;
141     uint32_t spaceSize[0];
142 } WorkSpaceSize;
143 
144 #ifdef __cplusplus
145 #if __cplusplus
146 }
147 #endif
148 #endif
149 #endif  // BASE_STARTUP_PARAM_COMMON_H