forked from loopholelabs/iouring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
324 lines (282 loc) · 7.78 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
Copyright 2023 Loophole Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package iouring
import (
"math"
"unsafe"
)
// SQRingOffsets is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L400
type SQRingOffsets struct {
Head uint32
Tail uint32
RingMask uint32
RingEntries uint32
Flags uint32
Dropped uint32
Array uint32
ResV1 uint32
ResV2 uint64
}
// CQRingOffsets is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L419
type CQRingOffsets struct {
Head uint32
Tail uint32
RingMask uint32
RingEntries uint32
Overflow uint32
CQEs uint32
Flags uint32
ResV1 uint32
ResV2 uint64
}
// Params is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L450
type Params struct {
SQEntries uint32
CQEntries uint32
Flags uint32
SQThreadCPU uint32
SQThreadIdle uint32
Features uint32
WQFD uint32
ResV [3]uint32
SQOffsets SQRingOffsets
CQOffsets CQRingOffsets
}
// CQEvent is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L357
type CQEvent struct {
UserData uint64
Res int32
Flags uint32
BigCQE *uint64
}
// UnionAddress3 is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L88
type UnionAddress3 struct {
Address3 uint64
_Pad2 [1]uint64
}
// SQEntry is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L30
type SQEntry struct {
OpCode uint8
Flags uint8
IOPriority uint16
FD int32
UnionOffset uint64
UnionAddress uint64
Length uint32
UnionRWFlags uint32
UserData uint64
UnionBufferIndexPacked uint16
Personality uint16
UnionSplicedFDIn int32
UnionAddress3 UnionAddress3
}
// SubmissionQueue is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing.h#L84
type SubmissionQueue struct {
KHead *uint32
KTail *uint32
_KRingMask *uint32 // Deprecated: use `RingMask` instead of `*_KRingMask`
_KRingEntries *uint32 // Deprecated: use `ring_entries` instead of `*_KRingEntries`
KFlags *uint32
KDropped *uint32
Array *uint32
SQEs *SQEntry
SQEHead uint32
SQETail uint32
RingSize uint
RingPointer unsafe.Pointer
RingMask uint32
RingEntries uint32
_Pad [2]uint32
}
// CompletionQueue is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing.h#L108
type CompletionQueue struct {
KHead *uint32
KTail *uint32
_KRingMask *uint32 // Deprecated: use `RingMask` instead of `*_KRingMask`
_KRingEntries *uint32 // Deprecated: use `ring_entries` instead of `*_KRingEntries`
KFlags *uint32
KOverflow *uint32
CQEs *CQEvent
RingSize uint
RingPointer unsafe.Pointer
RingMask uint32
RingEntries uint32
_Pad [2]uint32
}
// GetData is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/queue.c#L53
type GetData struct {
Submit uint32
WaitNR uint32
GetFlags uint32
Size int
HasTS int
Arg unsafe.Pointer
}
// GetEventsArg is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L671
type GetEventsArg struct {
SigMask uint64
SigMaskSize uint32
_Pad uint32
TS uint64
}
// OpCode is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L176
type OpCode uint8
const (
OpCodeNOP OpCode = iota
OpCodeReadV
OpCodeWriteV
OpCodeFsync
OpCodeReadFixed
OpCodeWriteFixed
OpCodePollAdd
OpCodePollRemove
OpCodeSyncFileRange
OpCodeSendMsg
OpCodeRecvMsg
OpCodeTimeout
OpCodeTimeoutRemove
OpCodeAccept
OpCodeAsyncCancel
OpCodeLinkTimeout
OpCodeConnect
OpCodeFallocate
OpCodeOpenat
OpCodeClose
OpCodeFilesUpdate
OpCodeStatx
OpCodeRead
OpCodeWrite
OpCodeFadvise
OpCodeMadvise
OpCodeSend
OpCodeRecv
OpOpenat2
OpCodeEpollCtl
OpCodeSplice
OpCodeProvideBuffers
OpCodeRemoveBuffers
OpCodeTee
OpCodeShutdown
OpCodeRenameat
OpCodeUnlinkat
OpCodeMkdirat
OpCodeSymlinkat
OpCodeLinkat
OpCodeMsgRing
OpCodeFsetxattr
OpCodeSetxattr
OpCodeFgetxattr
OpCodeGetxattr
OpCodeSocket
OpCodeUringCmd
OpCodeSendZC
OpCodeSendMsgZC
OpCodeLast
)
// Setup is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L140
type Setup uint32
const (
SetupIOPoll Setup = 1 << iota
SetupSQPoll
SetupSQAff
SetupCQSize
SetupClamp
SetupAttachWQ
SetupRDisabled
SetupSubmitAll
SetupCoopTaskRun
SetupTaskRunFlag
SetupSQE128
SetupCQE32
SetupSingleIssuer
SetupDeferTaskRun
SetupNoMMap
SetupRegisteredFDOnly
)
// SQStatus is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L415
type SQStatus uint32
const (
SQStatusNeedWakeup SQStatus = 1 << iota
SQStatusCQOverflow
SQStatusTaskRun
)
// Enter is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L441
type Enter uint32
const (
EnterGetEvents Enter = 1 << iota
EnterSQWakeup
EnterSQWait
EnterExtArg
EnterRegisteredRing
)
// IntFlag is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/int_flags.h#L5
type IntFlag uint8
const (
IntFlagRegRing IntFlag = 1
IntFlagRegRegRing IntFlag = 2
)
// Feature is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L466
type Feature uint32
const (
FeatureSingleMMap Feature = 1 << iota
FeatureNoDrop
FeatureSubmitStable
FeatureRWCurPos
FeatureCurPersonality
FeatureFastPoll
FeaturePoll32Bits
FeatureSQPollNonfixed
FeatureExtArg
FeatureNativeWorkers
FeatureRcrcTags
FeatureCQESkip
FeatureLinkedFile
FeatureRegRegRing
)
// RegisterOpCode is defined here: https://github.com/axboe/liburing/blob/liburing-2.4/src/include/liburing/io_uring.h#L484
type RegisterOpCode uint32
const (
RegisterOpCodeRegisterBuffers RegisterOpCode = iota
RegisterOpCodeUnregisterBuffers
RegisterOpCodeRegisterFiles
RegisterOpCodeUnregisterFiles
RegisterOpCodeRegisterEventFD
RegisterOpCodeUnregisterEventFD
RegisterOpCodeRegisterFilesUpdate
RegisterOpCodeRegisterEventFDAsync
RegisterOpCodeRegisterProbe
RegisterOpCodeRegisterPersonality
RegisterOpCodeUnregisterPersonality
RegisterOpCodeRegisterRestrictions
RegisterOpCodeRegisterEnableRings
RegisterOpCodeRegisterFiles2
RegisterOpCodeRegisterFilesUpdate2
RegisterOpCodeRegisterBuffers2
RegisterOpCodeRegisterBuffersUpdate
RegisterOpCodeRegisterIOWQAff
RegisterOpCodeUnregisterIOWQAff
RegisterOpCodeRegisterIOWQMaxWorkers
RegisterOpCodeRegisterRingFDs
RegisterOpCodeUnregisterRingFDs
RegisterOpCodeRegisterPbufRing
RegisterOpCodeUnregisterPbufRing
RegisterOpCodeRegisterSyncCancel
RegisterOpCodeRegisterFileAllocRange
RegisterOpCodeRegisterLast
RegisterOpCodeRegisterUseRegisteredRing = 1 << 31
)
const (
// _NSIG is defined here: https://github.com/torvalds/linux/blob/v6.5/include/uapi/asm-generic/signal.h#L7
_NSIG = 64
LIBURING_UDATA_TIMEOUT = math.MaxUint64
)