• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The ChromiumOS Authors
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 pub mod win;
10 
11 #[macro_use]
12 pub mod ioctl;
13 #[macro_use]
14 pub mod syslog;
15 mod console;
16 mod descriptor;
17 mod event;
18 mod events;
19 pub mod file_traits;
20 mod get_filesystem_type;
21 mod mmap;
22 mod mmap_platform;
23 pub mod named_pipes;
24 pub mod platform_timer_resolution;
25 mod priority;
26 // Add conditional compile?
27 mod punch_hole;
28 mod read_write_wrappers;
29 mod sched;
30 mod shm;
31 mod shm_platform;
32 mod stream_channel;
33 mod terminal;
34 mod timer;
35 mod wait;
36 
37 pub mod thread;
38 
39 mod write_zeroes;
40 
41 pub use console::*;
42 pub use descriptor::*;
43 pub use event::*;
44 pub use events::*;
45 pub use get_filesystem_type::*;
46 pub use ioctl::*;
47 pub use mmap::Error as MmapError;
48 pub use mmap::*;
49 pub(crate) use mmap_platform::PROT_READ;
50 pub(crate) use mmap_platform::PROT_WRITE;
51 pub use priority::*;
52 pub(crate) use punch_hole::file_punch_hole;
53 pub use read_write_wrappers::*;
54 pub use sched::*;
55 pub use shm::*;
56 pub use shm_platform::*;
57 pub use stream_channel::*;
58 pub use terminal::*;
59 pub use timer::*;
60 pub use win::*;
61 pub(crate) use write_zeroes::file_write_zeroes_at;
62 
63 pub use crate::descriptor_reflection::deserialize_with_descriptors;
64 pub use crate::descriptor_reflection::with_as_descriptor;
65 pub use crate::descriptor_reflection::with_raw_descriptor;
66 pub use crate::descriptor_reflection::FileSerdeWrapper;
67 pub use crate::descriptor_reflection::SerializeDescriptors;
68 pub use crate::errno::Error;
69 pub use crate::errno::Result;
70 pub use crate::errno::*;
71 
72 // Define libc::* types
73 #[allow(non_camel_case_types)]
74 pub type pid_t = i32;
75 #[allow(non_camel_case_types)]
76 pub type uid_t = u32;
77 #[allow(non_camel_case_types)]
78 pub type gid_t = u32;
79 #[allow(non_camel_case_types)]
80 pub type mode_t = u32;
81 
82 /// Re-export libc types that are part of the API.
83 pub type Pid = pid_t;
84 pub type Uid = uid_t;
85 pub type Gid = gid_t;
86 pub type Mode = mode_t;
87 
88 /// Uses the system's page size in bytes to round the given value up to the nearest page boundary.
89 #[inline(always)]
round_up_to_page_size(v: usize) -> usize90 pub fn round_up_to_page_size(v: usize) -> usize {
91     let page_mask = pagesize() - 1;
92     (v + page_mask) & !page_mask
93 }
94 
95 /// Returns the number of online logical cores on the system.
number_of_logical_cores() -> Result<usize>96 pub fn number_of_logical_cores() -> Result<usize> {
97     Ok(win_util::number_of_processors())
98 }
99