1 // Copyright 2022 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 //! Small system utility modules for usage by other modules.
6
7 #![cfg(windows)]
8
9 #[macro_use]
10 pub mod win;
11
12 #[path = "win/ioctl.rs"]
13 #[macro_use]
14 pub mod ioctl;
15 #[macro_use]
16 pub mod syslog;
17 mod clock;
18 #[path = "win/console.rs"]
19 mod console;
20 mod descriptor;
21 #[path = "win/event.rs"]
22 mod event;
23 mod events;
24 pub mod file_traits;
25 #[path = "win/get_filesystem_type.rs"]
26 mod get_filesystem_type;
27 mod gmtime;
28 mod mmap;
29 #[path = "win/named_pipes.rs"]
30 pub mod named_pipes;
31 mod notifiers;
32 mod poll;
33 #[path = "win/priority.rs"]
34 mod priority;
35 // Add conditional compile?
36 #[path = "win/sched.rs"]
37 mod sched;
38 mod shm;
39 mod stream_channel;
40 mod timer;
41
42 pub mod thread;
43
44 mod write_zeroes;
45
46 pub use crate::descriptor_reflection::{
47 deserialize_with_descriptors, with_as_descriptor, with_raw_descriptor, FileSerdeWrapper,
48 SerializeDescriptors,
49 };
50 pub use crate::errno::{Error, Result, *};
51 pub use base_poll_token_derive::*;
52 pub use clock::{Clock, FakeClock};
53 pub use console::*;
54 pub use descriptor::*;
55 pub use event::*;
56 pub use events::*;
57 pub use get_filesystem_type::*;
58 pub use gmtime::*;
59 pub use ioctl::*;
60 pub use mmap::*;
61 pub use notifiers::*;
62 pub use poll::*;
63 pub use priority::*;
64 pub use sched::*;
65 pub use shm::*;
66 pub use stream_channel::*;
67 pub use timer::*;
68 pub use win::*;
69
70 pub use file_traits::{
71 AsRawDescriptors, FileAllocate, FileGetLen, FileReadWriteAtVolatile, FileReadWriteVolatile,
72 FileSetLen, FileSync,
73 };
74 pub use mmap::Error as MmapError;
75 pub use write_zeroes::{PunchHole, WriteZeroes, WriteZeroesAt};
76
77 use std::cell::Cell;
78
79 // Define libc::* types
80 #[allow(non_camel_case_types)]
81 pub type pid_t = i32;
82 #[allow(non_camel_case_types)]
83 pub type uid_t = u32;
84 #[allow(non_camel_case_types)]
85 pub type gid_t = u32;
86 #[allow(non_camel_case_types)]
87 pub type mode_t = u32;
88
89 /// Re-export libc types that are part of the API.
90 pub type Pid = pid_t;
91 pub type Uid = uid_t;
92 pub type Gid = gid_t;
93 pub type Mode = mode_t;
94
95 /// Used to mark types as !Sync.
96 pub type UnsyncMarker = std::marker::PhantomData<Cell<usize>>;
97
98 /// Uses the system's page size in bytes to round the given value up to the nearest page boundary.
99 #[inline(always)]
round_up_to_page_size(v: usize) -> usize100 pub fn round_up_to_page_size(v: usize) -> usize {
101 let page_mask = pagesize() - 1;
102 (v + page_mask) & !page_mask
103 }
104
105 #[macro_export]
106 macro_rules! CHRONO_TIMESTAMP_FIXED_FMT {
107 () => {
108 "%F %T%.9f"
109 };
110 }
111