Skip to content

Commit 1d226d7

Browse files
committed
feat(ohos): fix some complier error and add some features
1 parent bcbcb50 commit 1d226d7

File tree

15 files changed

+112
-52
lines changed

15 files changed

+112
-52
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ feature! {
145145
#![feature = "mount"]
146146
pub mod mount;
147147
}
148-
#[cfg(any(freebsdlike, target_os = "linux", target_os = "netbsd"))]
148+
#[cfg(all(any(freebsdlike, target_os = "linux", target_os = "netbsd"), not(target_env = "ohos")))]
149149
feature! {
150150
#![feature = "mqueue"]
151151
pub mod mqueue;

src/sys/ioctl/linux.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use cfg_if::cfg_if;
22

33
/// The datatype used for the ioctl number
4-
#[cfg(any(target_os = "android", target_os = "fuchsia", target_env = "musl"))]
4+
#[cfg(any(target_os = "android", target_os = "fuchsia", target_env = "musl", target_env = "ohos"))]
55
#[doc(hidden)]
66
pub type ioctl_num_type = ::libc::c_int;
77
#[cfg(not(any(
88
target_os = "android",
99
target_os = "fuchsia",
10-
target_env = "musl"
10+
target_env = "musl",
11+
target_env = "ohos"
1112
)))]
1213
#[doc(hidden)]
1314
pub type ioctl_num_type = ::libc::c_ulong;

src/sys/memfd.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,54 @@ libc_bitflags!(
3535
/// See also the hugetlb filesystem in [`memfd_create(2)`].
3636
///
3737
/// [`memfd_create(2)`]: https://man7.org/linux/man-pages/man2/memfd_create.2.html
38-
#[cfg(linux_android)]
38+
#[cfg(any(linux_android, target_env = "ohos"))]
3939
MFD_HUGETLB;
40+
/// Following only supported on OHOS.
41+
/// Shift to get the huge page size.
42+
#[cfg(target_env = "ohos")]
43+
MFD_HUG_SHIFT;
44+
/// Mask to get the huge page size.
45+
#[cfg(target_env = "ohos")]
46+
MFD_HUG_MASK;
47+
/// hugetlb size of 64KB.
48+
#[cfg(target_env = "ohos")]
49+
MFD_HUG_64KB;
50+
/// hugetlb size of 512KB.
51+
#[cfg(target_env = "ohos")]
52+
MFD_HUG_512KB;
4053
/// Following are to be used with [`MFD_HUGETLB`], indicating the desired hugetlb size.
4154
///
4255
/// See also the hugetlb filesystem in [`memfd_create(2)`].
4356
///
4457
/// [`memfd_create(2)`]: https://man7.org/linux/man-pages/man2/memfd_create.2.html
45-
#[cfg(linux_android)]
58+
#[cfg(any(linux_android, target_env = "ohos"))]
4659
MFD_HUGE_1MB;
4760
/// hugetlb size of 2MB.
48-
#[cfg(linux_android)]
61+
#[cfg(any(linux_android, target_env = "ohos"))]
4962
MFD_HUGE_2MB;
5063
/// hugetlb size of 8MB.
51-
#[cfg(linux_android)]
64+
#[cfg(any(linux_android, target_env = "ohos"))]
5265
MFD_HUGE_8MB;
5366
/// hugetlb size of 16MB.
54-
#[cfg(linux_android)]
67+
#[cfg(any(linux_android, target_env = "ohos"))]
5568
MFD_HUGE_16MB;
5669
/// hugetlb size of 32MB.
57-
#[cfg(linux_android)]
70+
#[cfg(any(linux_android, target_env = "ohos"))]
5871
MFD_HUGE_32MB;
5972
/// hugetlb size of 256MB.
60-
#[cfg(linux_android)]
73+
#[cfg(any(linux_android, target_env = "ohos"))]
6174
MFD_HUGE_256MB;
6275
/// hugetlb size of 512MB.
63-
#[cfg(linux_android)]
76+
#[cfg(any(linux_android, target_env = "ohos"))]
6477
MFD_HUGE_512MB;
6578
/// hugetlb size of 1GB.
66-
#[cfg(linux_android)]
79+
#[cfg(any(linux_android, target_env = "ohos"))]
6780
MFD_HUGE_1GB;
6881
/// hugetlb size of 2GB.
69-
#[cfg(linux_android)]
82+
#[cfg(any(linux_android, target_env = "ohos"))]
7083
MFD_HUGE_2GB;
7184
/// hugetlb size of 16GB.
72-
#[cfg(linux_android)]
85+
#[cfg(any(linux_android, target_env = "ohos"))]
7386
MFD_HUGE_16GB;
7487
}
7588
);
@@ -102,6 +115,7 @@ pub fn memfd_create<P: NixPath + ?Sized>(
102115
// If the OS is Linux, gnu and musl expose a memfd_create symbol but not uclibc
103116
target_env = "gnu",
104117
target_env = "musl",
118+
target_env = "ohos"
105119
)))]
106120
{
107121
libc::memfd_create(cstr.as_ptr(), flags.bits())

src/sys/mman.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ libc_bitflags! {
6363
/// Put the mapping into the first 2GB of the process address space.
6464
#[cfg(any(all(linux_android,
6565
any(target_arch = "x86", target_arch = "x86_64")),
66-
all(target_os = "linux", target_env = "musl", any(target_arch = "x86", target_arch = "x86_64")),
66+
all(target_os = "linux", target_env = "musl", target_env = "ohos", any(target_arch = "x86", target_arch = "x86_64")),
6767
all(target_os = "freebsd", target_pointer_width = "64")))]
6868
MAP_32BIT;
6969
/// Used for stacks; indicates to the kernel that the mapping should extend downward in memory.

src/sys/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Mostly platform-specific functionality
22
#[cfg(any(
33
freebsdlike,
4-
all(target_os = "linux", not(target_env = "uclibc")),
4+
all(target_os = "linux", not(any(target_env = "uclibc", target_env = "ohos"))),
55
apple_targets,
66
target_os = "netbsd"
77
))]
@@ -13,15 +13,15 @@ feature! {
1313
feature! {
1414
#![feature = "event"]
1515

16-
#[cfg(linux_android)]
16+
#[cfg(any(linux_android, target_env = "ohos"))]
1717
#[allow(missing_docs)]
1818
pub mod epoll;
1919

2020
#[cfg(bsd)]
2121
pub mod event;
2222

2323
/// Event file descriptor.
24-
#[cfg(any(linux_android, target_os = "freebsd"))]
24+
#[cfg(any(linux_android, target_os = "freebsd", target_env = "ohos"))]
2525
pub mod eventfd;
2626
}
2727

src/sys/personality.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ libc_bitflags! {
2020
/// [`mmap(2)`]: https://man7.org/linux/man-pages/man2/mmap.2.html
2121
ADDR_LIMIT_3GB;
2222
/// User-space function pointers to signal handlers point to descriptors.
23-
#[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
23+
#[cfg(not(any(target_env = "musl", target_env = "uclibc", target_env = "ohos")))]
2424
FDPIC_FUNCPTRS;
2525
/// Map page 0 as read-only.
2626
MMAP_PAGE_ZERO;
@@ -41,7 +41,7 @@ libc_bitflags! {
4141
/// version number.
4242
///
4343
/// [`uname(2)`]: https://man7.org/linux/man-pages/man2/uname.2.html
44-
#[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
44+
#[cfg(not(any(target_env = "musl", target_env = "uclibc", target_env = "ohos")))]
4545
UNAME26;
4646
/// No effects.
4747
WHOLE_SECONDS;

src/sys/ptrace/linux.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ cfg_if! {
3636
}
3737

3838
libc_enum! {
39-
#[cfg_attr(not(any(target_env = "musl", target_env = "uclibc", target_os = "android")), repr(u32))]
40-
#[cfg_attr(any(target_env = "musl", target_env = "uclibc", target_os = "android"), repr(i32))]
39+
#[cfg_attr(not(any(target_env = "musl", target_env = "uclibc", target_os = "android", target_env = "ohos")), repr(u32))]
40+
#[cfg_attr(any(target_env = "musl", target_env = "uclibc", target_os = "android", target_env = "ohos"), repr(i32))]
4141
/// Ptrace Request enum defining the action to be taken.
4242
#[non_exhaustive]
4343
pub enum Request {
@@ -58,7 +58,8 @@ libc_enum! {
5858
target_arch = "mips64",
5959
target_arch = "mips64r6",
6060
target_arch = "x86_64",
61-
target_pointer_width = "32"))))]
61+
target_pointer_width = "32",
62+
target_env = "ohos"))))]
6263
PTRACE_GETREGS,
6364
#[cfg(any(all(target_os = "android", target_pointer_width = "32"),
6465
all(target_os = "linux", any(target_env = "musl",
@@ -67,7 +68,8 @@ libc_enum! {
6768
target_arch = "mips64",
6869
target_arch = "mips64r6",
6970
target_arch = "x86_64",
70-
target_pointer_width = "32"))))]
71+
target_pointer_width = "32",
72+
target_env = "ohos"))))]
7173
PTRACE_SETREGS,
7274
#[cfg(any(all(target_os = "android", target_pointer_width = "32"),
7375
all(target_os = "linux", any(target_env = "musl",
@@ -76,7 +78,8 @@ libc_enum! {
7678
target_arch = "mips64",
7779
target_arch = "mips64r6",
7880
target_arch = "x86_64",
79-
target_pointer_width = "32"))))]
81+
target_pointer_width = "32",
82+
target_env = "ohos"))))]
8083
PTRACE_GETFPREGS,
8184
#[cfg(any(all(target_os = "android", target_pointer_width = "32"),
8285
all(target_os = "linux", any(target_env = "musl",
@@ -85,7 +88,8 @@ libc_enum! {
8588
target_arch = "mips64",
8689
target_arch = "mips64r6",
8790
target_arch = "x86_64",
88-
target_pointer_width = "32"))))]
91+
target_pointer_width = "32",
92+
target_env = "ohos"))))]
8993
PTRACE_SETFPREGS,
9094
PTRACE_ATTACH,
9195
PTRACE_DETACH,
@@ -95,15 +99,17 @@ libc_enum! {
9599
target_arch = "mips64",
96100
target_arch = "mips64r6",
97101
target_arch = "x86",
98-
target_arch = "x86_64")))]
102+
target_arch = "x86_64",
103+
target_env = "ohos")))]
99104
PTRACE_GETFPXREGS,
100105
#[cfg(all(target_os = "linux", any(target_env = "musl",
101106
target_arch = "mips",
102107
target_arch = "mips32r6",
103108
target_arch = "mips64",
104109
target_arch = "mips64r6",
105110
target_arch = "x86",
106-
target_arch = "x86_64")))]
111+
target_arch = "x86_64",
112+
target_env = "ohos")))]
107113
PTRACE_SETFPXREGS,
108114
PTRACE_SYSCALL,
109115
PTRACE_SETOPTIONS,

src/sys/statfs.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ pub struct Statfs(type_of_statfs);
5151
type fs_type_t = u32;
5252
#[cfg(target_os = "android")]
5353
type fs_type_t = libc::c_ulong;
54-
#[cfg(all(target_os = "linux", target_arch = "s390x", not(target_env = "musl")))]
54+
#[cfg(all(target_os = "linux", target_arch = "s390x", not(any(target_env = "musl", target_env = "ohos"))))]
5555
type fs_type_t = libc::c_uint;
56-
#[cfg(all(target_os = "linux", target_env = "musl"))]
57-
type fs_type_t = libc::c_ulong;
58-
#[cfg(all(target_os = "linux", target_env = "ohos"))]
56+
#[cfg(all(target_os = "linux", any(target_env = "musl", target_env = "ohos")))]
5957
type fs_type_t = libc::c_ulong;
6058
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
6159
type fs_type_t = libc::c_int;

src/sys/time.rs

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#[cfg_attr(target_env = "musl", allow(deprecated))]
1+
#[cfg_attr(
2+
any(target_env = "musl", target_env = "ohos"),
3+
allow(deprecated)
4+
)]
25
// https://github.com/rust-lang/libc/issues/1848
36
pub use libc::{suseconds_t, time_t};
47
use libc::{timespec, timeval};
@@ -13,7 +16,10 @@ const fn zero_init_timespec() -> timespec {
1316
}
1417

1518
#[cfg(any(
16-
all(feature = "time", any(target_os = "android", target_os = "linux")),
19+
all(
20+
feature = "time",
21+
any(target_os = "android", target_os = "linux", target_env = "ohos")
22+
),
1723
all(
1824
any(
1925
target_os = "freebsd",
@@ -253,7 +259,10 @@ impl PartialOrd for TimeSpec {
253259

254260
impl TimeValLike for TimeSpec {
255261
#[inline]
256-
#[cfg_attr(target_env = "musl", allow(deprecated))]
262+
#[cfg_attr(
263+
any(target_env = "musl", target_env = "ohos"),
264+
allow(deprecated)
265+
)]
257266
// https://github.com/rust-lang/libc/issues/1848
258267
fn seconds(seconds: i64) -> TimeSpec {
259268
assert!(
@@ -286,7 +295,10 @@ impl TimeValLike for TimeSpec {
286295

287296
/// Makes a new `TimeSpec` with given number of nanoseconds.
288297
#[inline]
289-
#[cfg_attr(target_env = "musl", allow(deprecated))]
298+
#[cfg_attr(
299+
any(target_env = "musl", target_env = "ohos"),
300+
allow(deprecated)
301+
)]
290302
// https://github.com/rust-lang/libc/issues/1848
291303
fn nanoseconds(nanoseconds: i64) -> TimeSpec {
292304
let (secs, nanos) = div_mod_floor_64(nanoseconds, NANOS_PER_SEC);
@@ -340,7 +352,10 @@ impl TimeSpec {
340352
TimeSpec::new(0, libc::UTIME_NOW as timespec_tv_nsec_t);
341353

342354
/// Construct a new `TimeSpec` from its components
343-
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
355+
#[cfg_attr(
356+
any(target_env = "musl", target_env = "ohos"),
357+
allow(deprecated)
358+
)] // https://github.com/rust-lang/libc/issues/1848
344359
pub const fn new(seconds: time_t, nanoseconds: timespec_tv_nsec_t) -> Self {
345360
let mut ts = zero_init_timespec();
346361
ts.tv_sec = seconds;
@@ -356,7 +371,10 @@ impl TimeSpec {
356371
}
357372
}
358373

359-
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
374+
#[cfg_attr(
375+
any(target_env = "musl", target_env = "ohos"),
376+
allow(deprecated)
377+
)] // https://github.com/rust-lang/libc/issues/1848
360378
pub const fn tv_sec(&self) -> time_t {
361379
self.0.tv_sec
362380
}
@@ -365,7 +383,10 @@ impl TimeSpec {
365383
self.0.tv_nsec
366384
}
367385

368-
#[cfg_attr(target_env = "musl", allow(deprecated))]
386+
#[cfg_attr(
387+
any(target_env = "musl", target_env = "ohos"),
388+
allow(deprecated)
389+
)]
369390
// https://github.com/rust-lang/libc/issues/1848
370391
pub const fn from_duration(duration: Duration) -> Self {
371392
let mut ts = zero_init_timespec();
@@ -506,7 +527,10 @@ impl TimeValLike for TimeVal {
506527
(TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&seconds),
507528
"TimeVal out of bounds; seconds={seconds}"
508529
);
509-
#[cfg_attr(target_env = "musl", allow(deprecated))]
530+
#[cfg_attr(
531+
any(target_env = "musl", target_env = "ohos"),
532+
allow(deprecated)
533+
)]
510534
// https://github.com/rust-lang/libc/issues/1848
511535
TimeVal(timeval {
512536
tv_sec: seconds as time_t,
@@ -531,7 +555,10 @@ impl TimeValLike for TimeVal {
531555
(TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&secs),
532556
"TimeVal out of bounds"
533557
);
534-
#[cfg_attr(target_env = "musl", allow(deprecated))]
558+
#[cfg_attr(
559+
any(target_env = "musl", target_env = "ohos"),
560+
allow(deprecated)
561+
)]
535562
// https://github.com/rust-lang/libc/issues/1848
536563
TimeVal(timeval {
537564
tv_sec: secs as time_t,
@@ -549,7 +576,10 @@ impl TimeValLike for TimeVal {
549576
(TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&secs),
550577
"TimeVal out of bounds"
551578
);
552-
#[cfg_attr(target_env = "musl", allow(deprecated))]
579+
#[cfg_attr(
580+
any(target_env = "musl", target_env = "ohos"),
581+
allow(deprecated)
582+
)]
553583
// https://github.com/rust-lang/libc/issues/1848
554584
TimeVal(timeval {
555585
tv_sec: secs as time_t,
@@ -586,7 +616,10 @@ impl TimeValLike for TimeVal {
586616

587617
impl TimeVal {
588618
/// Construct a new `TimeVal` from its components
589-
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
619+
#[cfg_attr(
620+
any(target_env = "musl", target_env = "ohos"),
621+
allow(deprecated)
622+
)] // https://github.com/rust-lang/libc/issues/1848
590623
pub const fn new(seconds: time_t, microseconds: suseconds_t) -> Self {
591624
Self(timeval {
592625
tv_sec: seconds,
@@ -602,7 +635,10 @@ impl TimeVal {
602635
}
603636
}
604637

605-
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
638+
#[cfg_attr(
639+
any(target_env = "musl", target_env = "ohos"),
640+
allow(deprecated)
641+
)] // https://github.com/rust-lang/libc/issues/1848
606642
pub const fn tv_sec(&self) -> time_t {
607643
self.0.tv_sec
608644
}

src/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl ClockId {
122122
#[cfg(any(
123123
target_os = "emscripten",
124124
target_os = "fuchsia",
125-
all(target_os = "linux", target_env = "musl")
125+
all(target_os = "linux", target_env = "musl", target_env = "ohos")
126126
))]
127127
pub const CLOCK_SGI_CYCLE: ClockId = ClockId(libc::CLOCK_SGI_CYCLE);
128128
/// International Atomic Time.

0 commit comments

Comments
 (0)