• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 OHOS_IPC_SYS_BINDER_H
17 #define OHOS_IPC_SYS_BINDER_H
18 
19 #include <sys/types.h>
20 
21 #ifndef _UAPI_LINUX_BINDER_H
22 #define _UAPI_LINUX_BINDER_H
23 
24 #include <linux/types.h>
25 #include <linux/ioctl.h>
26 
27 #ifndef B_PACK_CHARS
28 #define B_PACK_CHARS(c1, c2, c3, c4) ((((c1) << 24)) | (((c2) << 16)) | (((c3) << 8)) | (c4))
29 #endif
30 
31 #define B_TYPE_LARGE 0x85
32 enum {
33     BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
34     BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
35     BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
36     BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE),
37     BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE),
38     BINDER_TYPE_FDA = B_PACK_CHARS('f', 'd', 'a', B_TYPE_LARGE),
39     BINDER_TYPE_PTR = B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE),
40 };
41 enum {
42     FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
43     FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
44     FLAT_BINDER_FLAG_TXN_SECURITY_CTX = 0x1000,
45 };
46 typedef __u64 binder_size_t;
47 typedef __u64 binder_uintptr_t;
48 struct binder_object_header {
49     __u32 type;
50 };
51 struct flat_binder_object {
52     struct binder_object_header hdr;
53     __u32 flags;
54     union {
55         binder_uintptr_t binder;
56         __u32 handle;
57     };
58     binder_uintptr_t cookie;
59 };
60 
61 struct binder_fd_object {
62     struct binder_object_header hdr;
63     __u32 pad_flags;
64     union {
65         binder_uintptr_t pad_binder;
66         __u32 fd;
67     };
68     binder_uintptr_t cookie;
69 };
70 struct binder_buffer_object {
71     struct binder_object_header hdr;
72     __u32 flags;
73     binder_uintptr_t buffer;
74     binder_size_t length;
75     binder_size_t parent;
76     binder_size_t parent_offset;
77 };
78 enum {
79     BINDER_BUFFER_FLAG_HAS_PARENT = 0x01,
80 };
81 struct binder_fd_array_object {
82     struct binder_object_header hdr;
83     __u32 pad;
84     binder_size_t num_fds;
85     binder_size_t parent;
86     binder_size_t parent_offset;
87 };
88 struct binder_write_read {
89     binder_size_t write_size;
90     binder_size_t write_consumed;
91     binder_uintptr_t write_buffer;
92     binder_size_t read_size;
93     binder_size_t read_consumed;
94     binder_uintptr_t read_buffer;
95 };
96 struct binder_version {
97     __s32 protocol_version;
98 };
99 #define BINDER_CURRENT_PROTOCOL_VERSION 8
100 
101 struct binder_feature_set {
102     __u64 feature_set;
103 };
104 #define ACCESS_TOKEN_FAETURE_MASK (1 << 0)
105 
106 struct binder_node_debug_info {
107     binder_uintptr_t ptr;
108     binder_uintptr_t cookie;
109     __u32 has_strong_ref;
110     __u32 has_weak_ref;
111 };
112 
113 struct binder_node_info_for_ref {
114     __u32 handle;
115     __u32 strong_count;
116     __u32 weak_count;
117     __u32 reserved1;
118     __u32 reserved2;
119     __u32 reserved3;
120 };
121 
122 struct access_token {
123     __u64 sender_tokenid;
124     __u64 first_tokenid;
125     __u64 reserved[2];
126 };
127 
128 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
129 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
130 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
131 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
132 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
133 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
134 #define BINDER_VERSION _IOWR('b', 9, struct binder_version)
135 #define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info)
136 #define BINDER_GET_NODE_INFO_FOR_REF _IOWR('b', 12, struct binder_node_info_for_ref)
137 #define BINDER_SET_CONTEXT_MGR_EXT _IOW('b', 13, struct flat_binder_object)
138 #define BINDER_GET_NODE_REFCOUNT _IOWR('b', 17, struct binder_ptr_count)
139 #define BINDER_TRANSLATE_HANDLE _IOWR('b', 18, __u32)
140 #define BINDER_FEATURE_SET	_IOWR('b', 30, struct binder_feature_set)
141 #define BINDER_GET_ACCESS_TOKEN	_IOWR('b', 31, struct access_token)
142 
143 enum transaction_flags {
144     TF_ONE_WAY = 0x01,
145     TF_ROOT_OBJECT = 0x04,
146     TF_STATUS_CODE = 0x08,
147     TF_ACCEPT_FDS = 0x10,
148     TF_HITRACE = 0x80, // add flag for hitrace
149 };
150 struct binder_transaction_data {
151     union {
152         __u32 handle;
153         binder_uintptr_t ptr;
154     } target;
155     binder_uintptr_t cookie;
156     __u32 code;
157     __u32 flags;
158     pid_t sender_pid;
159     uid_t sender_euid;
160     binder_size_t data_size;
161     binder_size_t offsets_size;
162     union {
163         struct {
164             binder_uintptr_t buffer;
165             binder_uintptr_t offsets;
166         } ptr;
167         __u8 buf[8];
168     } data;
169 };
170 struct binder_ptr_cookie {
171     binder_uintptr_t ptr;
172     binder_uintptr_t cookie;
173 };
174 struct binder_handle_cookie {
175     __u32 handle;
176     binder_uintptr_t cookie;
177 } __attribute__((__packed__));
178 struct binder_pri_desc {
179     __s32 priority;
180     __u32 desc;
181 };
182 struct binder_pri_ptr_cookie {
183     __s32 priority;
184     binder_uintptr_t ptr;
185     binder_uintptr_t cookie;
186 };
187 enum binder_driver_return_protocol {
188     BR_ERROR = _IOR('r', 0, __s32),
189     BR_OK = _IO('r', 1),
190     BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
191     BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
192     BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
193     BR_DEAD_REPLY = _IO('r', 5),
194     BR_TRANSACTION_COMPLETE = _IO('r', 6),
195     BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
196     BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
197     BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
198     BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
199     BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
200     BR_NOOP = _IO('r', 12),
201     BR_SPAWN_LOOPER = _IO('r', 13),
202     BR_FINISHED = _IO('r', 14),
203     BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
204     BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
205     BR_FAILED_REPLY = _IO('r', 17),
206     BR_RELEASE_NODE = _IO('r', 18),
207 };
208 enum binder_driver_command_protocol {
209     BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
210     BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
211     BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
212     BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
213     BC_INCREFS = _IOW('c', 4, __u32),
214     BC_ACQUIRE = _IOW('c', 5, __u32),
215     BC_RELEASE = _IOW('c', 6, __u32),
216     BC_DECREFS = _IOW('c', 7, __u32),
217     BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
218     BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
219     BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
220     BC_REGISTER_LOOPER = _IO('c', 11),
221     BC_ENTER_LOOPER = _IO('c', 12),
222     BC_EXIT_LOOPER = _IO('c', 13),
223     BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_handle_cookie),
224     BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_handle_cookie),
225     BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
226     BC_SEND_RAWDATA = _IOW('c', 20, __u32),
227 };
228 #endif /* * _UAPI_LINUX_BINDER_H * */
229 
230 static const int DBINDER_MAGICWORD = 0X4442494E;
231 static const int ENCRYPT_HEAD_LEN = 28;
232 static const int DEVICEID_LENGTH = 64;
233 static const int PID_LEN = 32;
234 static const int VERSION_NUM = 1;
235 
236 enum {
237     BINDER_TYPE_REMOTE_BINDER = B_PACK_CHARS('r', 'b', '*', B_TYPE_LARGE),
238     BINDER_TYPE_REMOTE_HANDLE = B_PACK_CHARS('r', 'h', '*', B_TYPE_LARGE),
239     ZBINDER_TYPE_REMOTE_NODE = B_PACK_CHARS('r', 'n', '*', B_TYPE_LARGE),
240     ZBINDER_TYPE_NODE = B_PACK_CHARS('s', 'n', '*', B_TYPE_LARGE),
241     BINDER_TYPE_FDR = B_PACK_CHARS('f', 'd', 'r', B_TYPE_LARGE),
242 };
243 
244 struct binder_ptr_count {
245     binder_uintptr_t ptr;
246     uint32_t count;
247 };
248 
249 struct dbinder_transaction_data {
250     __u32 sizeOfSelf;
251     __u32 magic;
252     __u32 version;
253     int cmd;
254     __u32 code;
255     __u32 flags;
256     __u64 cookie;
257     __u64 seqNumber;
258     binder_size_t buffer_size;
259     binder_size_t offsets_size;
260     binder_uintptr_t offsets;
261     unsigned char buffer[0];
262 };
263 #endif // OHOS_IPC_SYS_BINDER_H
264