Skip to content

Commit 2ccc2f4

Browse files
committed
Auto merge of #2135 - zonyitoo:master, r=<try>
Unified all Linux sockopts definitions by arch - ref rust-lang/socket2#213
2 parents 10d99b9 + 9733ded commit 2ccc2f4

File tree

42 files changed

+584
-1037
lines changed

Some content is hidden

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

42 files changed

+584
-1037
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use core::mem::size_of;
2+
3+
// sizeof(time_t) == sizeof(__kernel_long_t)
4+
pub const SO_TIMESTAMP: ::c_int =
5+
if size_of::<::time_t>() == size_of::<::c_long>() {
6+
super::SO_TIMESTAMP_OLD
7+
} else {
8+
super::SO_TIMESTAMP_NEW
9+
};
10+
pub const SO_TIMESTAMPNS: ::c_int =
11+
if size_of::<::time_t>() == size_of::<::c_long>() {
12+
super::SO_TIMESTAMPNS_OLD
13+
} else {
14+
super::SO_TIMESTAMPNS_NEW
15+
};
16+
pub const SO_TIMESTAMPING: ::c_int =
17+
if size_of::<::time_t>() == size_of::<::c_long>() {
18+
super::SO_TIMESTAMPING_OLD
19+
} else {
20+
super::SO_TIMESTAMPING_NEW
21+
};
22+
23+
pub const SO_RCVTIMEO: ::c_int =
24+
if size_of::<::time_t>() == size_of::<::c_long>() {
25+
super::SO_RCVTIMEO_OLD
26+
} else {
27+
super::SO_RCVTIMEO_NEW
28+
};
29+
pub const SO_SNDTIMEO: ::c_int =
30+
if size_of::<::time_t>() == size_of::<::c_long>() {
31+
super::SO_SNDTIMEO_OLD
32+
} else {
33+
super::SO_SNDTIMEO_NEW
34+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
2+
pub const SO_TIMESTAMP: ::c_int = super::SO_TIMESTAMP_OLD;
3+
pub const SO_TIMESTAMPNS: ::c_int = super::SO_TIMESTAMPNS_OLD;
4+
pub const SO_TIMESTAMPING: ::c_int = super::SO_TIMESTAMPING_OLD;
5+
6+
// __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
7+
pub const SO_RCVTIMEO: ::c_int = super::SO_RCVTIMEO_OLD;
8+
pub const SO_SNDTIMEO: ::c_int = super::SO_SNDTIMEO_OLD;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// include/uapi/asm-generic/socket.h
2+
// arch/alpha/include/uapi/asm/socket.h
3+
// tools/include/uapi/asm-generic/socket.h
4+
// arch/mips/include/uapi/asm/socket.h
5+
pub const SOL_SOCKET: ::c_int = 1;
6+
7+
// Defined in unix/linux_like/mod.rs
8+
// pub const SO_DEBUG: ::c_int = 1;
9+
pub const SO_REUSEADDR: ::c_int = 2;
10+
pub const SO_TYPE: ::c_int = 3;
11+
pub const SO_ERROR: ::c_int = 4;
12+
pub const SO_DONTROUTE: ::c_int = 5;
13+
pub const SO_BROADCAST: ::c_int = 6;
14+
pub const SO_SNDBUF: ::c_int = 7;
15+
pub const SO_RCVBUF: ::c_int = 8;
16+
pub const SO_KEEPALIVE: ::c_int = 9;
17+
pub const SO_OOBINLINE: ::c_int = 10;
18+
pub const SO_NO_CHECK: ::c_int = 11;
19+
pub const SO_PRIORITY: ::c_int = 12;
20+
pub const SO_LINGER: ::c_int = 13;
21+
pub const SO_BSDCOMPAT: ::c_int = 14;
22+
pub const SO_REUSEPORT: ::c_int = 15;
23+
pub const SO_PASSCRED: ::c_int = 16;
24+
pub const SO_PEERCRED: ::c_int = 17;
25+
pub const SO_RCVLOWAT: ::c_int = 18;
26+
pub const SO_SNDLOWAT: ::c_int = 19;
27+
pub const SO_RCVTIMEO_OLD: ::c_int = 20;
28+
pub const SO_SNDTIMEO_OLD: ::c_int = 21;
29+
pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22;
30+
pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23;
31+
pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24;
32+
pub const SO_BINDTODEVICE: ::c_int = 25;
33+
pub const SO_ATTACH_FILTER: ::c_int = 26;
34+
pub const SO_DETACH_FILTER: ::c_int = 27;
35+
pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER;
36+
pub const SO_PEERNAME: ::c_int = 28;
37+
pub const SO_TIMESTAMP_OLD: ::c_int = 29;
38+
pub const SO_ACCEPTCONN: ::c_int = 30;
39+
pub const SO_PEERSEC: ::c_int = 31;
40+
pub const SO_SNDBUFFORCE: ::c_int = 32;
41+
pub const SO_RCVBUFFORCE: ::c_int = 33;
42+
pub const SO_PASSSEC: ::c_int = 34;
43+
pub const SO_TIMESTAMPNS_OLD: ::c_int = 35;
44+
pub const SO_MARK: ::c_int = 36;
45+
pub const SO_TIMESTAMPING_OLD: ::c_int = 37;
46+
pub const SO_PROTOCOL: ::c_int = 38;
47+
pub const SO_DOMAIN: ::c_int = 39;
48+
pub const SO_RXQ_OVFL: ::c_int = 40;
49+
pub const SO_WIFI_STATUS: ::c_int = 41;
50+
pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS;
51+
pub const SO_PEEK_OFF: ::c_int = 42;
52+
pub const SO_NOFCS: ::c_int = 43;
53+
pub const SO_LOCK_FILTER: ::c_int = 44;
54+
pub const SO_SELECT_ERR_QUEUE: ::c_int = 45;
55+
pub const SO_BUSY_POLL: ::c_int = 46;
56+
pub const SO_MAX_PACING_RATE: ::c_int = 47;
57+
pub const SO_BPF_EXTENSIONS: ::c_int = 48;
58+
pub const SO_INCOMING_CPU: ::c_int = 49;
59+
pub const SO_ATTACH_BPF: ::c_int = 50;
60+
pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER;
61+
pub const SO_ATTACH_REUSEPORT_CBPF: ::c_int = 51;
62+
pub const SO_ATTACH_REUSEPORT_EBPF: ::c_int = 52;
63+
pub const SO_CNX_ADVICE: ::c_int = 53;
64+
pub const SCM_TIMESTAMPING_OPT_STATS: ::c_int = 54;
65+
pub const SO_MEMINFO: ::c_int = 55;
66+
pub const SO_INCOMING_NAPI_ID: ::c_int = 56;
67+
pub const SO_COOKIE: ::c_int = 57;
68+
pub const SCM_TIMESTAMPING_PKTINFO: ::c_int = 58;
69+
pub const SO_PEERGROUPS: ::c_int = 59;
70+
pub const SO_ZEROCOPY: ::c_int = 60;
71+
pub const SO_TXTIME: ::c_int = 61;
72+
pub const SCM_TXTIME: ::c_int = SO_TXTIME;
73+
pub const SO_BINDTOIFINDEX: ::c_int = 62;
74+
pub const SO_TIMESTAMP_NEW: ::c_int = 63;
75+
pub const SO_TIMESTAMPNS_NEW: ::c_int = 64;
76+
pub const SO_TIMESTAMPING_NEW: ::c_int = 65;
77+
pub const SO_RCVTIMEO_NEW: ::c_int = 66;
78+
pub const SO_SNDTIMEO_NEW: ::c_int = 67;
79+
pub const SO_DETACH_REUSEPORT_BPF: ::c_int = 68;
80+
// pub const SO_PREFER_BUSY_POLL: ::c_int = 69;
81+
// pub const SO_BUSY_POLL_BUDGET: ::c_int = 70;
82+
83+
// Defined in unix/linux_like/mod.rs
84+
// pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP;
85+
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
86+
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
87+
88+
cfg_if! {
89+
// __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
90+
91+
if #[cfg(any(target_arch = "x86",
92+
target_arch = "arm",
93+
target_arch = "riscv32"))] {
94+
mod b32;
95+
pub use self::b32::*;
96+
} else if #[cfg(any(target_arch = "x86_64",
97+
target_arch = "aarch64",
98+
target_arch = "s390x",
99+
target_arch = "riscv64"))] {
100+
mod b64;
101+
pub use self::b64::*;
102+
}
103+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use core::mem::size_of;
2+
3+
// sizeof(time_t) == sizeof(__kernel_long_t)
4+
pub const SO_TIMESTAMP: ::c_int =
5+
if size_of::<::time_t>() == size_of::<::c_long>() {
6+
super::SO_TIMESTAMP_OLD
7+
} else {
8+
super::SO_TIMESTAMP_NEW
9+
};
10+
pub const SO_TIMESTAMPNS: ::c_int =
11+
if size_of::<::time_t>() == size_of::<::c_long>() {
12+
super::SO_TIMESTAMPNS_OLD
13+
} else {
14+
super::SO_TIMESTAMPNS_NEW
15+
};
16+
pub const SO_TIMESTAMPING: ::c_int =
17+
if size_of::<::time_t>() == size_of::<::c_long>() {
18+
super::SO_TIMESTAMPING_OLD
19+
} else {
20+
super::SO_TIMESTAMPING_NEW
21+
};
22+
23+
pub const SO_RCVTIMEO: ::c_int =
24+
if size_of::<::time_t>() == size_of::<::c_long>() {
25+
super::SO_RCVTIMEO_OLD
26+
} else {
27+
super::SO_RCVTIMEO_NEW
28+
};
29+
pub const SO_SNDTIMEO: ::c_int =
30+
if size_of::<::time_t>() == size_of::<::c_long>() {
31+
super::SO_SNDTIMEO_OLD
32+
} else {
33+
super::SO_SNDTIMEO_NEW
34+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// #if __BITS_PER_LONG == 64
2+
pub const SO_TIMESTAMP: ::c_int = super::SO_TIMESTAMP_OLD;
3+
pub const SO_TIMESTAMPNS: ::c_int = super::SO_TIMESTAMPNS_OLD;
4+
pub const SO_TIMESTAMPING: ::c_int = super::SO_TIMESTAMPING_OLD;
5+
6+
// #if __BITS_PER_LONG == 64
7+
pub const SO_RCVTIMEO: ::c_int = super::SO_RCVTIMEO_OLD;
8+
pub const SO_SNDTIMEO: ::c_int = super::SO_SNDTIMEO_OLD;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// arch/mips/include/uapi/asm/socket.h
2+
pub const SOL_SOCKET: ::c_int = 0xffff;
3+
4+
// Defined in unix/linux_like/mod.rs
5+
// pub const SO_DEBUG: ::c_int = 0x0001;
6+
pub const SO_REUSEADDR: ::c_int = 0x0004;
7+
pub const SO_KEEPALIVE: ::c_int = 0x0008;
8+
pub const SO_DONTROUTE: ::c_int = 0x0010;
9+
pub const SO_BROADCAST: ::c_int = 0x0020;
10+
pub const SO_LINGER: ::c_int = 0x0080;
11+
pub const SO_OOBINLINE: ::c_int = 0x0100;
12+
pub const SO_REUSEPORT: ::c_int = 0x0200;
13+
pub const SO_TYPE: ::c_int = 0x1008;
14+
pub const SO_STYLE: ::c_int = SO_TYPE;
15+
pub const SO_ERROR: ::c_int = 0x1007;
16+
pub const SO_SNDBUF: ::c_int = 0x1001;
17+
pub const SO_RCVBUF: ::c_int = 0x1002;
18+
pub const SO_SNDLOWAT: ::c_int = 0x1003;
19+
pub const SO_RCVLOWAT: ::c_int = 0x1004;
20+
pub const SO_SNDTIMEO_OLD: ::c_int = 0x1005;
21+
pub const SO_RCVTIMEO_OLD: ::c_int = 0x1006;
22+
pub const SO_ACCEPTCONN: ::c_int = 0x1009;
23+
pub const SO_PROTOCOL: ::c_int = 0x1028; /* protocol type */
24+
pub const SO_DOMAIN: ::c_int = 0x1029; /* domain/socket family */
25+
26+
pub const SO_NO_CHECK: ::c_int = 11;
27+
pub const SO_PRIORITY: ::c_int = 12;
28+
pub const SO_BSDCOMPAT: ::c_int = 14;
29+
pub const SO_PASSCRED: ::c_int = 17;
30+
pub const SO_PEERCRED: ::c_int = 18;
31+
pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22;
32+
pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23;
33+
pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24;
34+
pub const SO_BINDTODEVICE: ::c_int = 25;
35+
pub const SO_ATTACH_FILTER: ::c_int = 26;
36+
pub const SO_DETACH_FILTER: ::c_int = 27;
37+
pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER;
38+
pub const SO_PEERNAME: ::c_int = 28;
39+
pub const SO_PEERSEC: ::c_int = 30;
40+
pub const SO_SNDBUFFORCE: ::c_int = 31;
41+
pub const SO_RCVBUFFORCE: ::c_int = 33;
42+
pub const SO_PASSSEC: ::c_int = 34;
43+
pub const SO_MARK: ::c_int = 36;
44+
pub const SO_RXQ_OVFL: ::c_int = 40;
45+
pub const SO_WIFI_STATUS: ::c_int = 41;
46+
pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS;
47+
pub const SO_PEEK_OFF: ::c_int = 42;
48+
pub const SO_NOFCS: ::c_int = 43;
49+
pub const SO_LOCK_FILTER: ::c_int = 44;
50+
pub const SO_SELECT_ERR_QUEUE: ::c_int = 45;
51+
pub const SO_BUSY_POLL: ::c_int = 46;
52+
pub const SO_MAX_PACING_RATE: ::c_int = 47;
53+
pub const SO_BPF_EXTENSIONS: ::c_int = 48;
54+
pub const SO_INCOMING_CPU: ::c_int = 49;
55+
pub const SO_ATTACH_BPF: ::c_int = 50;
56+
pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER;
57+
pub const SO_ATTACH_REUSEPORT_CBPF: ::c_int = 51;
58+
pub const SO_ATTACH_REUSEPORT_EBPF: ::c_int = 52;
59+
pub const SO_CNX_ADVICE: ::c_int = 53;
60+
pub const SCM_TIMESTAMPING_OPT_STATS: ::c_int = 54;
61+
pub const SO_MEMINFO: ::c_int = 55;
62+
pub const SO_INCOMING_NAPI_ID: ::c_int = 56;
63+
pub const SO_COOKIE: ::c_int = 57;
64+
pub const SCM_TIMESTAMPING_PKTINFO: ::c_int = 58;
65+
pub const SO_PEERGROUPS: ::c_int = 59;
66+
pub const SO_ZEROCOPY: ::c_int = 60;
67+
pub const SO_TXTIME: ::c_int = 61;
68+
pub const SCM_TXTIME: ::c_int = SO_TXTIME;
69+
pub const SO_BINDTOIFINDEX: ::c_int = 62;
70+
pub const SO_TIMESTAMP_OLD: ::c_int = 29;
71+
pub const SO_TIMESTAMPNS_OLD: ::c_int = 35;
72+
pub const SO_TIMESTAMPING_OLD: ::c_int = 37;
73+
pub const SO_TIMESTAMP_NEW: ::c_int = 63;
74+
pub const SO_TIMESTAMPNS_NEW: ::c_int = 64;
75+
pub const SO_TIMESTAMPING_NEW: ::c_int = 65;
76+
pub const SO_RCVTIMEO_NEW: ::c_int = 66;
77+
pub const SO_SNDTIMEO_NEW: ::c_int = 67;
78+
pub const SO_DETACH_REUSEPORT_BPF: ::c_int = 68;
79+
// pub const SO_PREFER_BUSY_POLL: ::c_int = 69;
80+
// pub const SO_BUSY_POLL_BUDGET: ::c_int = 70;
81+
82+
// Defined in unix/linux_like/mod.rs
83+
// pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP;
84+
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
85+
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
86+
87+
cfg_if! {
88+
// __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
89+
90+
if #[cfg(target_arch = "mips")] {
91+
mod b32;
92+
pub use self::b32::*;
93+
} else if #[cfg(target_arch = "mips64")] {
94+
mod b64;
95+
pub use self::b64::*;
96+
}
97+
}

src/unix/linux_like/linux/arch/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cfg_if! {
2+
if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] {
3+
mod mips;
4+
pub use self::mips::*;
5+
} else if #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] {
6+
mod powerpc;
7+
pub use self::powerpc::*;
8+
} else if #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] {
9+
mod sparc;
10+
pub use self::sparc::*;
11+
} else {
12+
mod generic;
13+
pub use self::generic::*;
14+
}
15+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use core::mem::size_of;
2+
3+
// sizeof(time_t) == sizeof(__kernel_long_t)
4+
pub const SO_TIMESTAMP: ::c_int =
5+
if size_of::<::time_t>() == size_of::<::c_long>() {
6+
super::SO_TIMESTAMP_OLD
7+
} else {
8+
super::SO_TIMESTAMP_NEW
9+
};
10+
pub const SO_TIMESTAMPNS: ::c_int =
11+
if size_of::<::time_t>() == size_of::<::c_long>() {
12+
super::SO_TIMESTAMPNS_OLD
13+
} else {
14+
super::SO_TIMESTAMPNS_NEW
15+
};
16+
pub const SO_TIMESTAMPING: ::c_int =
17+
if size_of::<::time_t>() == size_of::<::c_long>() {
18+
super::SO_TIMESTAMPING_OLD
19+
} else {
20+
super::SO_TIMESTAMPING_NEW
21+
};
22+
23+
pub const SO_RCVTIMEO: ::c_int =
24+
if size_of::<::time_t>() == size_of::<::c_long>() {
25+
super::SO_RCVTIMEO_OLD
26+
} else {
27+
super::SO_RCVTIMEO_NEW
28+
};
29+
pub const SO_SNDTIMEO: ::c_int =
30+
if size_of::<::time_t>() == size_of::<::c_long>() {
31+
super::SO_SNDTIMEO_OLD
32+
} else {
33+
super::SO_SNDTIMEO_NEW
34+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
2+
pub const SO_TIMESTAMP: ::c_int = super::SO_TIMESTAMP_OLD;
3+
pub const SO_TIMESTAMPNS: ::c_int = super::SO_TIMESTAMPNS_OLD;
4+
pub const SO_TIMESTAMPING: ::c_int = super::SO_TIMESTAMPING_OLD;
5+
6+
// __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
7+
pub const SO_RCVTIMEO: ::c_int = super::SO_RCVTIMEO_OLD;
8+
pub const SO_SNDTIMEO: ::c_int = super::SO_SNDTIMEO_OLD;

0 commit comments

Comments
 (0)