Skip to content

Commit f544b27

Browse files
committed
Add correctly sized structs and types for Android aarch64.
1 parent a04a52a commit f544b27

File tree

3 files changed

+206
-103
lines changed

3 files changed

+206
-103
lines changed

src/unix/notbsd/android/b32.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
pub type c_long = i32;
2+
pub type c_ulong = u32;
13
pub type mode_t = u16;
4+
pub type off64_t = ::c_longlong;
5+
pub type dev_t = ::c_ulong;
6+
pub type ino_t = ::c_ulong;
27

38
s! {
49
pub struct sigaction {
@@ -7,9 +12,96 @@ s! {
712
pub sa_flags: ::c_ulong,
813
pub sa_restorer: ::dox::Option<extern fn()>,
914
}
15+
16+
pub struct stat64 {
17+
pub st_dev: ::c_ulonglong,
18+
__pad0: [::c_uchar; 4],
19+
__st_ino: ::ino_t,
20+
pub st_mode: ::mode_t,
21+
pub st_nlink: ::nlink_t,
22+
pub st_uid: ::uid_t,
23+
pub st_gid: ::gid_t,
24+
pub st_rdev: ::c_ulonglong,
25+
__pad3: [::c_uchar; 4],
26+
pub st_size: ::off64_t,
27+
pub st_blksize: ::blksize_t,
28+
pub st_blocks: ::c_ulonglong,
29+
pub st_atime: ::c_ulong,
30+
pub st_atime_nsec: ::c_ulong,
31+
pub st_mtime: ::c_ulong,
32+
pub st_mtime_nsec: ::c_ulong,
33+
pub st_ctime: ::c_ulong,
34+
pub st_ctime_nsec: ::c_ulong,
35+
pub st_ino: ::c_ulonglong,
36+
}
37+
38+
pub struct pthread_attr_t {
39+
pub flags: ::uint32_t,
40+
pub stack_base: *mut ::c_void,
41+
pub stack_size: ::size_t,
42+
pub guard_size: ::size_t,
43+
pub sched_policy: ::int32_t,
44+
pub sched_priority: ::int32_t,
45+
}
46+
47+
pub struct pthread_mutex_t { value: ::c_int }
48+
49+
pub struct pthread_cond_t { value: ::c_int }
50+
51+
pub struct pthread_rwlock_t {
52+
lock: pthread_mutex_t,
53+
cond: pthread_cond_t,
54+
numLocks: ::c_int,
55+
writerThreadId: ::c_int,
56+
pendingReaders: ::c_int,
57+
pendingWriters: ::c_int,
58+
attr: i32,
59+
__reserved: [::c_char; 12],
60+
}
61+
62+
pub struct passwd {
63+
pub pw_name: *mut ::c_char,
64+
pub pw_passwd: *mut ::c_char,
65+
pub pw_uid: ::uid_t,
66+
pub pw_gid: ::gid_t,
67+
pub pw_dir: *mut ::c_char,
68+
pub pw_shell: *mut ::c_char,
69+
}
70+
71+
pub struct statfs {
72+
pub f_type: ::uint32_t,
73+
pub f_bsize: ::uint32_t,
74+
pub f_blocks: ::uint64_t,
75+
pub f_bfree: ::uint64_t,
76+
pub f_bavail: ::uint64_t,
77+
pub f_files: ::uint64_t,
78+
pub f_ffree: ::uint64_t,
79+
pub f_fsid: ::__fsid_t,
80+
pub f_namelen: ::uint32_t,
81+
pub f_frsize: ::uint32_t,
82+
pub f_flags: ::uint32_t,
83+
pub f_spare: [::uint32_t; 4],
84+
}
1085
}
1186

1287
pub const SYS_gettid: ::c_long = 224;
88+
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
89+
value: 0,
90+
};
91+
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
92+
value: 0,
93+
};
94+
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
95+
lock: PTHREAD_MUTEX_INITIALIZER,
96+
cond: PTHREAD_COND_INITIALIZER,
97+
numLocks: 0,
98+
writerThreadId: 0,
99+
pendingReaders: 0,
100+
pendingWriters: 0,
101+
attr: 0,
102+
__reserved: [0; 12],
103+
};
104+
pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 2;
13105

14106
extern {
15107
pub fn timegm64(tm: *const ::tm) -> ::time64_t;

src/unix/notbsd/android/b64.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
// The following definitions are correct for aarch64 and may be wrong for x86_64
2+
3+
pub type c_long = i64;
4+
pub type c_ulong = u64;
15
pub type mode_t = u32;
6+
pub type off64_t = i64;
7+
pub type dev_t = ::c_ulong;
8+
pub type ino_t = ::c_ulong;
29

310
s! {
411
pub struct sigaction {
@@ -7,9 +14,103 @@ s! {
714
pub sa_mask: ::sigset_t,
815
_restorer: *mut ::c_void,
916
}
17+
18+
pub struct stat64 {
19+
pub st_dev: ::dev_t,
20+
pub st_ino: ::ino_t,
21+
pub st_mode: ::mode_t,
22+
pub st_nlink: ::nlink_t,
23+
pub st_uid: ::uid_t,
24+
pub st_gid: ::gid_t,
25+
pub st_rdev: ::dev_t,
26+
__pad1: ::c_ulong,
27+
pub st_size: ::off64_t,
28+
pub st_blksize: ::c_int,
29+
__pad2: ::c_int,
30+
pub st_blocks: ::c_long,
31+
pub st_atime: ::time_t,
32+
pub st_atime_nsec: ::c_ulong,
33+
pub st_mtime: ::time_t,
34+
pub st_mtime_nsec: ::c_ulong,
35+
pub st_ctime: ::time_t,
36+
pub st_ctime_nsec: ::c_ulong,
37+
__unused4: ::c_uint,
38+
__unused5: ::c_uint,
39+
}
40+
41+
pub struct pthread_attr_t {
42+
pub flags: ::uint32_t,
43+
pub stack_base: *mut ::c_void,
44+
pub stack_size: ::size_t,
45+
pub guard_size: ::size_t,
46+
pub sched_policy: ::int32_t,
47+
pub sched_priority: ::int32_t,
48+
__reserved: [::c_char; 16],
49+
}
50+
51+
pub struct pthread_mutex_t {
52+
value: ::c_int,
53+
__reserved: [::c_char; 36],
54+
}
55+
56+
pub struct pthread_cond_t {
57+
value: ::c_int,
58+
__reserved: [::c_char; 44],
59+
}
60+
61+
pub struct pthread_rwlock_t {
62+
numLocks: ::c_int,
63+
writerThreadId: ::c_int,
64+
pendingReaders: ::c_int,
65+
pendingWriters: ::c_int,
66+
attr: i32,
67+
__reserved: [::c_char; 36],
68+
}
69+
70+
pub struct passwd {
71+
pub pw_name: *mut ::c_char,
72+
pub pw_passwd: *mut ::c_char,
73+
pub pw_uid: ::uid_t,
74+
pub pw_gid: ::gid_t,
75+
pub pw_gecos: *mut ::c_char,
76+
pub pw_dir: *mut ::c_char,
77+
pub pw_shell: *mut ::c_char,
78+
}
79+
80+
pub struct statfs {
81+
pub f_type: ::uint64_t,
82+
pub f_bsize: ::uint64_t,
83+
pub f_blocks: ::uint64_t,
84+
pub f_bfree: ::uint64_t,
85+
pub f_bavail: ::uint64_t,
86+
pub f_files: ::uint64_t,
87+
pub f_ffree: ::uint64_t,
88+
pub f_fsid: ::__fsid_t,
89+
pub f_namelen: ::uint64_t,
90+
pub f_frsize: ::uint64_t,
91+
pub f_flags: ::uint64_t,
92+
pub f_spare: [::uint64_t; 4],
93+
}
1094
}
1195

1296
pub const SYS_gettid: ::c_long = 178;
97+
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
98+
value: 0,
99+
__reserved: [0; 36],
100+
};
101+
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
102+
value: 0,
103+
__reserved: [0; 44],
104+
};
105+
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
106+
numLocks: 0,
107+
writerThreadId: 0,
108+
pendingReaders: 0,
109+
pendingWriters: 0,
110+
attr: 0,
111+
__reserved: [0; 36],
112+
};
113+
pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 4;
13114

14115
extern {
15116
pub fn timegm(tm: *const ::tm) -> ::time64_t;

src/unix/notbsd/android/mod.rs

Lines changed: 13 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,38 @@
11
//! Android-specific definitions for linux-like values
22
33
pub type c_char = u8;
4-
pub type c_long = i32;
5-
pub type c_ulong = u32;
6-
pub type clock_t = i32;
7-
pub type time_t = i32;
8-
pub type suseconds_t = i32;
4+
pub type clock_t = ::c_long;
5+
pub type time_t = ::c_long;
6+
pub type suseconds_t = ::c_long;
97
pub type wchar_t = u32;
10-
pub type off_t = i32;
11-
pub type off64_t = i64;
12-
pub type ino_t = u32;
13-
pub type blkcnt_t = u32;
14-
pub type blksize_t = u32;
15-
pub type dev_t = u32;
8+
pub type off_t = ::c_long;
9+
pub type blkcnt_t = ::c_ulong;
10+
pub type blksize_t = ::c_ulong;
1611
pub type nlink_t = u32;
1712
pub type useconds_t = u32;
1813
pub type socklen_t = i32;
19-
pub type pthread_t = c_long;
14+
pub type pthread_t = ::c_long;
2015
pub type pthread_mutexattr_t = ::c_long;
21-
pub type sigset_t = c_ulong;
22-
pub type time64_t = i64;
16+
pub type sigset_t = ::c_ulong;
17+
pub type time64_t = i64; // N/A on android
2318
pub type fsfilcnt_t = ::c_ulong;
2419
pub type fsblkcnt_t = ::c_ulong;
2520
pub type nfds_t = ::c_uint;
26-
pub type rlim_t = c_ulong;
21+
pub type rlim_t = ::c_ulong;
2722

2823
s! {
2924
pub struct stat {
3025
pub st_dev: ::c_ulonglong,
3126
__pad0: [::c_uchar; 4],
3227
__st_ino: ::ino_t,
33-
pub st_mode: ::c_uint,
34-
pub st_nlink: ::c_uint,
28+
pub st_mode: ::mode_t,
29+
pub st_nlink: ::nlink_t,
3530
pub st_uid: ::uid_t,
3631
pub st_gid: ::gid_t,
3732
pub st_rdev: ::c_ulonglong,
3833
__pad3: [::c_uchar; 4],
3934
pub st_size: ::c_longlong,
40-
pub st_blksize: blksize_t,
41-
pub st_blocks: ::c_ulonglong,
42-
pub st_atime: ::c_ulong,
43-
pub st_atime_nsec: ::c_ulong,
44-
pub st_mtime: ::c_ulong,
45-
pub st_mtime_nsec: ::c_ulong,
46-
pub st_ctime: ::c_ulong,
47-
pub st_ctime_nsec: ::c_ulong,
48-
pub st_ino: ::c_ulonglong,
49-
}
50-
51-
pub struct stat64 {
52-
pub st_dev: ::c_ulonglong,
53-
__pad0: [::c_uchar; 4],
54-
__st_ino: ::ino_t,
55-
pub st_mode: ::c_uint,
56-
pub st_nlink: ::c_uint,
57-
pub st_uid: ::uid_t,
58-
pub st_gid: ::gid_t,
59-
pub st_rdev: ::c_ulonglong,
60-
__pad3: [::c_uchar; 4],
61-
pub st_size: ::c_longlong,
62-
pub st_blksize: blksize_t,
35+
pub st_blksize: ::blksize_t,
6336
pub st_blocks: ::c_ulonglong,
6437
pub st_atime: ::c_ulong,
6538
pub st_atime_nsec: ::c_ulong,
@@ -91,38 +64,6 @@ s! {
9164
pub rlim_max: u64,
9265
}
9366

94-
pub struct pthread_attr_t {
95-
pub flags: ::uint32_t,
96-
pub stack_base: *mut ::c_void,
97-
pub stack_size: ::size_t,
98-
pub guard_size: ::size_t,
99-
pub sched_policy: ::int32_t,
100-
pub sched_priority: ::int32_t,
101-
}
102-
103-
pub struct pthread_mutex_t { value: ::c_int }
104-
105-
pub struct pthread_cond_t { value: ::c_int }
106-
107-
pub struct pthread_rwlock_t {
108-
lock: pthread_mutex_t,
109-
cond: pthread_cond_t,
110-
numLocks: ::c_int,
111-
writerThreadId: ::c_int,
112-
pendingReaders: ::c_int,
113-
pendingWriters: ::c_int,
114-
reserved: [*mut ::c_void; 4],
115-
}
116-
117-
pub struct passwd {
118-
pub pw_name: *mut ::c_char,
119-
pub pw_passwd: *mut ::c_char,
120-
pub pw_uid: ::uid_t,
121-
pub pw_gid: ::gid_t,
122-
pub pw_dir: *mut ::c_char,
123-
pub pw_shell: *mut ::c_char,
124-
}
125-
12667
pub struct stack_t {
12768
pub ss_sp: *mut ::c_void,
12869
pub ss_flags: ::c_int,
@@ -136,21 +77,6 @@ s! {
13677
pub _pad: [::c_int; 29],
13778
}
13879

139-
pub struct statfs {
140-
pub f_type: ::uint32_t,
141-
pub f_bsize: ::uint32_t,
142-
pub f_blocks: ::uint64_t,
143-
pub f_bfree: ::uint64_t,
144-
pub f_bavail: ::uint64_t,
145-
pub f_files: ::uint64_t,
146-
pub f_ffree: ::uint64_t,
147-
pub f_fsid: ::__fsid_t,
148-
pub f_namelen: ::uint32_t,
149-
pub f_frsize: ::uint32_t,
150-
pub f_flags: ::uint32_t,
151-
pub f_spare: [::uint32_t; 4],
152-
}
153-
15480
pub struct __fsid_t {
15581
__val: [::c_int; 2],
15682
}
@@ -251,22 +177,6 @@ pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 84;
251177
pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 85;
252178
pub const _SC_NPROCESSORS_ONLN: ::c_int = 97;
253179

254-
pub const PTHREAD_STACK_MIN: ::size_t = 8192;
255-
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
256-
value: 0,
257-
};
258-
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
259-
value: 0,
260-
};
261-
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
262-
lock: PTHREAD_MUTEX_INITIALIZER,
263-
cond: PTHREAD_COND_INITIALIZER,
264-
numLocks: 0,
265-
writerThreadId: 0,
266-
pendingReaders: 0,
267-
pendingWriters: 0,
268-
reserved: [0 as *mut _; 4],
269-
};
270180
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
271181

272182
pub const FIOCLEX: ::c_int = 0x5451;

0 commit comments

Comments
 (0)