• 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 } ParamSecurityNode;
91 
92 typedef struct {
93     ATOMIC_LLONG commitId;
94     ATOMIC_LLONG commitPersistId;
95     uint32_t trieNodeCount;
96     uint32_t paramNodeCount;
97     uint32_t securityNodeCount;
98     uint32_t currOffset;
99     uint32_t firstNode;
100     uint32_t dataSize;
101     char data[0];
102 } ParamTrieHeader;
103 
104 typedef struct WorkSpace_ {
105     unsigned int flags;
106     MemHandle memHandle;
107     ParamTrieHeader *area;
108     ATOMIC_UINT32 rwSpaceLock;
109     uint32_t spaceSize;
110     uint32_t spaceIndex;
111     ParamRWMutex rwlock;
112     char fileName[0];
113 } WorkSpace;
114 
115 typedef struct {
116     uint8_t updaterMode;
117     void (*logFunc)(int logLevel, uint32_t domain, const char *tag, const char *fmt, va_list vargs);
118     int (*setfilecon)(const char *name, const char *content);
119     int (*getServiceGroupIdByPid)(pid_t pid, gid_t *gids, uint32_t gidSize);
120 } PARAM_WORKSPACE_OPS;
121 
122 typedef struct CachedParameter_ {
123     struct WorkSpace_ *workspace;
124     const char *(*cachedParameterCheck)(struct CachedParameter_ *param, int *changed);
125     long long spaceCommitId;
126     uint32_t dataCommitId;
127     uint32_t dataIndex;
128     uint32_t bufferLen;
129     uint32_t nameLen;
130     char *paramValue;
131     char data[0];
132 } CachedParameter;
133 
134 typedef void *CachedHandle;
135 #ifdef __cplusplus
136 #if __cplusplus
137 }
138 #endif
139 #endif
140 #endif  // BASE_STARTUP_PARAM_COMMON_H