Skip to content

Commit f3068b1

Browse files
authored
Split "general" into a few different modules. (#65)
Split out "net", "io_uring", "prctl", and "system" modules from the main "general" module. More splitting is possible; this is a starting point.
1 parent 0a10e02 commit f3068b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+101717
-90452
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ targets = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
2828
[features]
2929
errno = []
3030
general = []
31+
io_uring = []
3132
ioctl = []
33+
net = []
3234
netlink = []
35+
prctl = []
36+
system = []
3337
default = ["std", "general", "errno"]
3438
std = []
3539
no_std = []

gen/modules/general.h

Lines changed: 31 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,21 @@
1313
#include <linux/fcntl.h>
1414
#include <linux/fs.h>
1515
#include <linux/futex.h>
16-
#include <linux/in.h>
1716
#include <linux/inotify.h>
18-
#include <linux/ip.h>
19-
#include <linux/in6.h>
20-
#include <linux/ipv6.h>
2117
#include <linux/limits.h>
2218
#include <linux/magic.h>
2319
#include <linux/mman.h>
24-
#include <linux/net.h>
2520
#include <linux/poll.h>
26-
#include <linux/prctl.h>
2721
#include <linux/random.h>
2822
#include <linux/resource.h>
2923
#include <linux/sched.h>
3024
#include <linux/signal.h>
31-
#include <linux/socket.h>
3225
#include <linux/stat.h>
33-
#include <linux/sysinfo.h>
34-
#include <linux/tcp.h>
3526
#include <linux/termios.h>
3627
#include <linux/time.h>
3728
#include <linux/types.h>
3829
#include <linux/uio.h>
39-
#include <linux/un.h>
4030
#include <linux/unistd.h>
41-
#include <linux/utsname.h>
4231
#include <linux/wait.h>
4332
#include <linux/xattr.h>
4433

@@ -62,47 +51,6 @@
6251
#include <linux/userfaultfd.h>
6352
#endif
6453

65-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0)
66-
#include <linux/io_uring.h>
67-
#endif
68-
69-
// Miscellaneous definitions which don't appear to be defined in Linux's public
70-
// headers, but which are nonetheless part of the ABI, and necessary for
71-
// interoperability.
72-
//
73-
// When adding definitions here, please only include content needed for
74-
// interoperability with Linux's public ABI, and please only include types
75-
// and constants.
76-
//
77-
// In particular, please don't copy comments from other sources. And please
78-
// don't include any functions or function-style macros, as bindgen isn't
79-
// able to generate bindings for them.
80-
//
81-
// Also, please be aware that libc implementations (and thus the Rust libc
82-
// crate as well) sometimes define types and constants with similar names but
83-
// which are ABI-incompatible with the Linux kernel ABI. This file should
84-
// only describe the kernel ABI.
85-
86-
struct sockaddr {
87-
struct __kernel_sockaddr_storage __storage;
88-
};
89-
#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32)
90-
typedef uint16_t __kernel_sa_family_t;
91-
#endif
92-
93-
struct linger {
94-
int l_onoff;
95-
int l_linger;
96-
};
97-
98-
#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,4,0)
99-
typedef long long __kernel_time64_t;
100-
struct __kernel_timespec {
101-
__kernel_time64_t tv_sec;
102-
long long tv_nsec;
103-
};
104-
#endif
105-
10654
#define DT_UNKNOWN 0
10755
#define DT_FIFO 1
10856
#define DT_CHR 2
@@ -112,13 +60,6 @@ struct __kernel_timespec {
11260
#define DT_LNK 10
11361
#define DT_SOCK 12
11462

115-
#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
116-
#define WIFEXITED(status) (((status) & 0x7f) == 0)
117-
118-
#define SHUT_RD 0
119-
#define SHUT_WR 1
120-
#define SHUT_RDWR 2
121-
12263
struct linux_dirent64 {
12364
__UINT64_TYPE__ d_ino;
12465
__INT64_TYPE__ d_off;
@@ -127,8 +68,6 @@ struct linux_dirent64 {
12768
char d_name[];
12869
};
12970

130-
typedef __UINT32_TYPE__ socklen_t;
131-
13271
// Obtain the definitions of structs stat/stat64 and statfs/statfs64.
13372
#include <asm/stat.h>
13473
#include <asm/statfs.h>
@@ -143,17 +82,6 @@ typedef long __fsword_t;
14382
typedef __statfs_word __fsword_t;
14483
#endif
14584

146-
#if defined(__mips__) || defined(__mips64__)
147-
#define SOCK_STREAM 2
148-
#define SOCK_DGRAM 1
149-
#else
150-
#define SOCK_STREAM 1
151-
#define SOCK_DGRAM 2
152-
#endif
153-
#define SOCK_RAW 3
154-
#define SOCK_RDM 4
155-
#define SOCK_SEQPACKET 5
156-
15785
#define F_OK 0
15886
#define R_OK 4
15987
#define W_OK 2
@@ -162,62 +90,37 @@ typedef __statfs_word __fsword_t;
16290
#define UTIME_NOW 0x3fffffff
16391
#define UTIME_OMIT 0x3ffffffe
16492

165-
#define MSG_DONTWAIT 0x40
166-
167-
#define AF_UNSPEC 0
168-
#define AF_UNIX 1
169-
#define AF_INET 2
170-
#define AF_AX25 3
171-
#define AF_IPX 4
172-
#define AF_APPLETALK 5
173-
#define AF_NETROM 6
174-
#define AF_BRIDGE 7
175-
#define AF_ATMPVC 8
176-
#define AF_X25 9
177-
#define AF_INET6 10
178-
#define AF_ROSE 11
179-
#define AF_DECnet 12
180-
#define AF_NETBEUI 13
181-
#define AF_SECURITY 14
182-
#define AF_KEY 15
183-
#define AF_NETLINK 16
184-
#define AF_PACKET 17
185-
#define AF_ASH 18
186-
#define AF_ECONET 19
187-
#define AF_ATMSVC 20
188-
#define AF_RDS 21
189-
#define AF_SNA 22
190-
#define AF_IRDA 23
191-
#define AF_PPPOX 24
192-
#define AF_WANPIPE 25
193-
#define AF_LLC 26
194-
#define AF_CAN 29
195-
#define AF_TIPC 30
196-
#define AF_BLUETOOTH 31
197-
#define AF_IUCV 32
198-
#define AF_RXRPC 33
199-
#define AF_ISDN 34
200-
#define AF_PHONET 35
201-
#define AF_IEEE802154 36
202-
#define AF_MAX 37
203-
204-
#define MSG_OOB 0x1
205-
#define MSG_PEEK 0x2
206-
#define MSG_DONTROUTE 0x4
207-
#define MSG_CTRUNC 0x8
208-
#define MSG_PROBE 0x10
209-
#define MSG_TRUNC 0x20
210-
#define MSG_DONTWAIT 0x40
211-
#define MSG_EOR 0x80
212-
#define MSG_WAITALL 0x100
213-
#define MSG_FIN 0x200
214-
#define MSG_SYN 0x400
215-
#define MSG_CONFIRM 0x800
216-
#define MSG_RST 0x1000
217-
#define MSG_ERRQUEUE 0x2000
218-
#define MSG_NOSIGNAL 0x4000
219-
#define MSG_MORE 0x8000
220-
#define MSG_CMSG_CLOEXEC 0x40000000
93+
#define MNT_FORCE 0x1
94+
#define MNT_DETACH 0x2
95+
#define MNT_EXPIRE 0x4
96+
#define UMOUNT_NOFOLLOW 0x8
97+
#define UMOUNT_UNUSED 0x80000000// Miscellaneous definitions which don't appear to be defined in Linux's public
98+
// headers, but which are nonetheless part of the ABI, and necessary for
99+
// interoperability.
100+
//
101+
// When adding definitions here, please only include content needed for
102+
// interoperability with Linux's public ABI, and please only include types
103+
// and constants.
104+
//
105+
// In particular, please don't copy comments from other sources. And please
106+
// don't include any functions or function-style macros, as bindgen isn't
107+
// able to generate bindings for them.
108+
//
109+
// Also, please be aware that libc implementations (and thus the Rust libc
110+
// crate as well) sometimes define types and constants with similar names but
111+
// which are ABI-incompatible with the Linux kernel ABI. This file should
112+
// only describe the kernel ABI.
113+
114+
#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,4,0)
115+
typedef long long __kernel_time64_t;
116+
struct __kernel_timespec {
117+
__kernel_time64_t tv_sec;
118+
long long tv_nsec;
119+
};
120+
#endif
121+
122+
#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
123+
#define WIFEXITED(status) (((status) & 0x7f) == 0)
221124

222125
#define STDIN_FILENO 0
223126
#define STDOUT_FILENO 1
@@ -293,38 +196,6 @@ struct user_desc {
293196
#define ARCH_SET_FS 0x1002
294197
#endif
295198

296-
struct msghdr {
297-
void *msg_name;
298-
int msg_namelen;
299-
struct iovec *msg_iov;
300-
size_t msg_iovlen;
301-
void *msg_control;
302-
size_t msg_controllen;
303-
unsigned int msg_flags;
304-
};
305-
306-
struct cmsghdr {
307-
size_t cmsg_len;
308-
int cmsg_level;
309-
int cmsg_type;
310-
};
311-
312-
313-
#define SCM_RIGHTS 0x01
314-
#define SCM_CREDENTIALS 0x02
315-
#define SCM_SECURITY 0x03
316-
317-
struct ucred {
318-
__u32 pid;
319-
__u32 uid;
320-
__u32 gid;
321-
};
322-
323-
struct mmsghdr {
324-
struct msghdr msg_hdr;
325-
unsigned int msg_len;
326-
};
327-
328199
#define UFFD_API 0xAA
329200

330201
#define UFFDIO_REGISTER_MODE_MISSING 0x1
@@ -352,12 +223,6 @@ struct mmsghdr {
352223
#define SPLICE_F_MORE 4
353224
#define SPLICE_F_GIFT 8
354225

355-
#define MNT_FORCE 0x1
356-
#define MNT_DETACH 0x2
357-
#define MNT_EXPIRE 0x4
358-
#define UMOUNT_NOFOLLOW 0x8
359-
#define UMOUNT_UNUSED 0x80000000
360-
361226
// Linux's public headers provide public `NSIG`, `sigset_t` and `sigaction`
362227
// definitions which "cater to libcs that poke about in kernel headers", but
363228
// they're not usable in libcs because, for example, `SYS_rt_sigaction` insists

gen/modules/io_uring.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file includes selected Linux header files, and supplementary
2+
// definitions, needed for io_uring code.
3+
4+
#include "support.h"
5+
6+
// Selected Linux headers.
7+
8+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0)
9+
#include <linux/io_uring.h>
10+
#endif
11+
12+
// Miscellaneous definitions which don't appear to be defined in Linux's public
13+
// headers, but which are nonetheless part of the ABI, and necessary for
14+
// interoperability.
15+
//
16+
// When adding definitions here, please only include content needed for
17+
// interoperability with Linux's public ABI, and please only include types
18+
// and constants.
19+
//
20+
// In particular, please don't copy comments from other sources. And please
21+
// don't include any functions or function-style macros, as bindgen isn't
22+
// able to generate bindings for them.
23+
//
24+
// Also, please be aware that libc implementations (and thus the Rust libc
25+
// crate as well) sometimes define types and constants with similar names but
26+
// which are ABI-incompatible with the Linux kernel ABI. This file should
27+
// only describe the kernel ABI.

0 commit comments

Comments
 (0)