1 // Copyright 2023 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 use std::fs::File;
6
7 use crate::descriptor::FromRawDescriptor;
8 use crate::sys::unix::RawDescriptor;
9 use crate::unix::set_descriptor_cloexec;
10 use crate::unix::Pid;
11 use crate::MmapError;
12
13 mod event;
14 mod net;
15
16 pub(crate) use event::PlatformEvent;
17 pub(in crate::sys) use libc::sendmsg;
18 pub(in crate::sys) use net::sockaddr_un;
19 pub(in crate::sys) use net::sockaddrv4_to_lib_c;
20 pub(in crate::sys) use net::sockaddrv6_to_lib_c;
21
get_cpu_affinity() -> crate::errno::Result<Vec<usize>>22 pub fn get_cpu_affinity() -> crate::errno::Result<Vec<usize>> {
23 todo!();
24 }
25
get_filesystem_type(_file: &std::fs::File) -> crate::errno::Result<i64>26 pub fn get_filesystem_type(_file: &std::fs::File) -> crate::errno::Result<i64> {
27 todo!();
28 }
29
getpid() -> Pid30 pub fn getpid() -> Pid {
31 todo!();
32 }
33
open_file_or_duplicate<P: AsRef<std::path::Path>>( _path: P, _options: &std::fs::OpenOptions, ) -> crate::Result<std::fs::File>34 pub fn open_file_or_duplicate<P: AsRef<std::path::Path>>(
35 _path: P,
36 _options: &std::fs::OpenOptions,
37 ) -> crate::Result<std::fs::File> {
38 todo!();
39 }
40
41 pub mod platform_timer_resolution {
42 pub struct UnixSetTimerResolution {}
43 impl crate::EnabledHighResTimer for UnixSetTimerResolution {}
44
enable_high_res_timers() -> crate::Result<Box<dyn crate::EnabledHighResTimer>>45 pub fn enable_high_res_timers() -> crate::Result<Box<dyn crate::EnabledHighResTimer>> {
46 todo!();
47 }
48 }
49
set_cpu_affinity<I: IntoIterator<Item = usize>>(_cpus: I) -> crate::errno::Result<()>50 pub fn set_cpu_affinity<I: IntoIterator<Item = usize>>(_cpus: I) -> crate::errno::Result<()> {
51 todo!();
52 }
53
54 pub struct EventContext<T: crate::EventToken> {
55 p: std::marker::PhantomData<T>,
56 }
57
58 impl<T: crate::EventToken> EventContext<T> {
new() -> crate::errno::Result<EventContext<T>>59 pub fn new() -> crate::errno::Result<EventContext<T>> {
60 todo!();
61 }
build_with( _fd_tokens: &[(&dyn crate::AsRawDescriptor, T)], ) -> crate::errno::Result<EventContext<T>>62 pub fn build_with(
63 _fd_tokens: &[(&dyn crate::AsRawDescriptor, T)],
64 ) -> crate::errno::Result<EventContext<T>> {
65 todo!();
66 }
add_for_event( &self, _descriptor: &dyn crate::AsRawDescriptor, _event_type: crate::EventType, _token: T, ) -> crate::errno::Result<()>67 pub fn add_for_event(
68 &self,
69 _descriptor: &dyn crate::AsRawDescriptor,
70 _event_type: crate::EventType,
71 _token: T,
72 ) -> crate::errno::Result<()> {
73 todo!();
74 }
modify( &self, _fd: &dyn crate::AsRawDescriptor, _event_type: crate::EventType, _token: T, ) -> crate::errno::Result<()>75 pub fn modify(
76 &self,
77 _fd: &dyn crate::AsRawDescriptor,
78 _event_type: crate::EventType,
79 _token: T,
80 ) -> crate::errno::Result<()> {
81 todo!();
82 }
delete(&self, _fd: &dyn crate::AsRawDescriptor) -> crate::errno::Result<()>83 pub fn delete(&self, _fd: &dyn crate::AsRawDescriptor) -> crate::errno::Result<()> {
84 todo!();
85 }
wait(&self) -> crate::errno::Result<smallvec::SmallVec<[crate::TriggeredEvent<T>; 16]>>86 pub fn wait(&self) -> crate::errno::Result<smallvec::SmallVec<[crate::TriggeredEvent<T>; 16]>> {
87 todo!();
88 }
wait_timeout( &self, _timeout: std::time::Duration, ) -> crate::errno::Result<smallvec::SmallVec<[crate::TriggeredEvent<T>; 16]>>89 pub fn wait_timeout(
90 &self,
91 _timeout: std::time::Duration,
92 ) -> crate::errno::Result<smallvec::SmallVec<[crate::TriggeredEvent<T>; 16]>> {
93 todo!();
94 }
95 }
96
97 impl<T: crate::EventToken> crate::AsRawDescriptor for EventContext<T> {
as_raw_descriptor(&self) -> RawDescriptor98 fn as_raw_descriptor(&self) -> RawDescriptor {
99 todo!();
100 }
101 }
102
103 pub struct MemoryMappingArena {}
104
105 #[derive(Debug)]
106 pub struct MemoryMapping {}
107
108 impl MemoryMapping {
size(&self) -> usize109 pub fn size(&self) -> usize {
110 todo!();
111 }
range_end(&self, _offset: usize, _count: usize) -> Result<usize, MmapError>112 pub(crate) fn range_end(&self, _offset: usize, _count: usize) -> Result<usize, MmapError> {
113 todo!();
114 }
msync(&self) -> Result<(), MmapError>115 pub fn msync(&self) -> Result<(), MmapError> {
116 todo!();
117 }
new_protection_fixed( _addr: *mut u8, _size: usize, _prot: crate::Protection, ) -> Result<MemoryMapping, MmapError>118 pub fn new_protection_fixed(
119 _addr: *mut u8,
120 _size: usize,
121 _prot: crate::Protection,
122 ) -> Result<MemoryMapping, MmapError> {
123 todo!();
124 }
125 /// # Safety
126 ///
127 /// unimplemented, always aborts
from_descriptor_offset_protection_fixed( _addr: *mut u8, _fd: &dyn crate::AsRawDescriptor, _size: usize, _offset: u64, _prot: crate::Protection, ) -> Result<MemoryMapping, MmapError>128 pub unsafe fn from_descriptor_offset_protection_fixed(
129 _addr: *mut u8,
130 _fd: &dyn crate::AsRawDescriptor,
131 _size: usize,
132 _offset: u64,
133 _prot: crate::Protection,
134 ) -> Result<MemoryMapping, MmapError> {
135 todo!();
136 }
137 }
138
139 // SAFETY: Unimplemented, always aborts
140 unsafe impl crate::MappedRegion for MemoryMapping {
as_ptr(&self) -> *mut u8141 fn as_ptr(&self) -> *mut u8 {
142 todo!();
143 }
size(&self) -> usize144 fn size(&self) -> usize {
145 todo!();
146 }
147 }
148
149 pub mod ioctl {
150 pub type IoctlNr = std::ffi::c_ulong;
151 /// # Safety
152 ///
153 /// unimplemented, always aborts
ioctl<F: crate::AsRawDescriptor>( _descriptor: &F, _nr: IoctlNr, ) -> std::ffi::c_int154 pub unsafe fn ioctl<F: crate::AsRawDescriptor>(
155 _descriptor: &F,
156 _nr: IoctlNr,
157 ) -> std::ffi::c_int {
158 todo!();
159 }
160 /// # Safety
161 ///
162 /// unimplemented, always aborts
ioctl_with_val( _descriptor: &dyn crate::AsRawDescriptor, _nr: IoctlNr, _arg: std::ffi::c_ulong, ) -> std::ffi::c_int163 pub unsafe fn ioctl_with_val(
164 _descriptor: &dyn crate::AsRawDescriptor,
165 _nr: IoctlNr,
166 _arg: std::ffi::c_ulong,
167 ) -> std::ffi::c_int {
168 todo!();
169 }
170 /// # Safety
171 ///
172 /// unimplemented, always aborts
ioctl_with_ref<T>( _descriptor: &dyn crate::AsRawDescriptor, _nr: IoctlNr, _arg: &T, ) -> std::ffi::c_int173 pub unsafe fn ioctl_with_ref<T>(
174 _descriptor: &dyn crate::AsRawDescriptor,
175 _nr: IoctlNr,
176 _arg: &T,
177 ) -> std::ffi::c_int {
178 todo!();
179 }
180 /// # Safety
181 ///
182 /// unimplemented, always aborts
ioctl_with_mut_ref<T>( _descriptor: &dyn crate::AsRawDescriptor, _nr: IoctlNr, _arg: &mut T, ) -> std::ffi::c_int183 pub unsafe fn ioctl_with_mut_ref<T>(
184 _descriptor: &dyn crate::AsRawDescriptor,
185 _nr: IoctlNr,
186 _arg: &mut T,
187 ) -> std::ffi::c_int {
188 todo!();
189 }
190 /// # Safety
191 ///
192 /// unimplemented, always aborts
ioctl_with_ptr<T>( _descriptor: &dyn crate::AsRawDescriptor, _nr: IoctlNr, _arg: *const T, ) -> std::ffi::c_int193 pub unsafe fn ioctl_with_ptr<T>(
194 _descriptor: &dyn crate::AsRawDescriptor,
195 _nr: IoctlNr,
196 _arg: *const T,
197 ) -> std::ffi::c_int {
198 todo!();
199 }
200 /// # Safety
201 ///
202 /// unimplemented, always aborts
ioctl_with_mut_ptr<T>( _descriptor: &dyn crate::AsRawDescriptor, _nr: IoctlNr, _arg: *mut T, ) -> std::ffi::c_int203 pub unsafe fn ioctl_with_mut_ptr<T>(
204 _descriptor: &dyn crate::AsRawDescriptor,
205 _nr: IoctlNr,
206 _arg: *mut T,
207 ) -> std::ffi::c_int {
208 todo!();
209 }
210 }
211
file_punch_hole(_file: &std::fs::File, _offset: u64, _length: u64) -> std::io::Result<()>212 pub fn file_punch_hole(_file: &std::fs::File, _offset: u64, _length: u64) -> std::io::Result<()> {
213 todo!();
214 }
215
file_write_zeroes_at( _file: &std::fs::File, _offset: u64, _length: usize, ) -> std::io::Result<usize>216 pub fn file_write_zeroes_at(
217 _file: &std::fs::File,
218 _offset: u64,
219 _length: usize,
220 ) -> std::io::Result<usize> {
221 todo!();
222 }
223
224 pub mod syslog {
225 pub struct PlatformSyslog {}
226
227 impl crate::syslog::Syslog for PlatformSyslog {
new( _proc_name: String, _facility: crate::syslog::Facility, ) -> Result< ( Option<Box<dyn crate::syslog::Log + Send>>, Option<crate::RawDescriptor>, ), crate::syslog::Error, >228 fn new(
229 _proc_name: String,
230 _facility: crate::syslog::Facility,
231 ) -> Result<
232 (
233 Option<Box<dyn crate::syslog::Log + Send>>,
234 Option<crate::RawDescriptor>,
235 ),
236 crate::syslog::Error,
237 > {
238 todo!();
239 }
240 }
241 }
242
243 impl PartialEq for crate::SafeDescriptor {
eq(&self, _other: &Self) -> bool244 fn eq(&self, _other: &Self) -> bool {
245 todo!();
246 }
247 }
248
249 impl crate::shm::PlatformSharedMemory for crate::SharedMemory {
new(_debug_name: &std::ffi::CStr, _size: u64) -> crate::Result<crate::SharedMemory>250 fn new(_debug_name: &std::ffi::CStr, _size: u64) -> crate::Result<crate::SharedMemory> {
251 todo!();
252 }
from_safe_descriptor( _descriptor: crate::SafeDescriptor, _size: u64, ) -> crate::Result<crate::SharedMemory>253 fn from_safe_descriptor(
254 _descriptor: crate::SafeDescriptor,
255 _size: u64,
256 ) -> crate::Result<crate::SharedMemory> {
257 todo!();
258 }
259 }
260
261 impl crate::Timer {
new() -> crate::errno::Result<crate::Timer>262 pub fn new() -> crate::errno::Result<crate::Timer> {
263 todo!();
264 }
265 }
266
267 impl crate::TimerTrait for crate::Timer {
reset( &mut self, _dur: std::time::Duration, mut _interval: Option<std::time::Duration>, ) -> crate::errno::Result<()>268 fn reset(
269 &mut self,
270 _dur: std::time::Duration,
271 mut _interval: Option<std::time::Duration>,
272 ) -> crate::errno::Result<()> {
273 todo!();
274 }
wait(&mut self) -> crate::errno::Result<()>275 fn wait(&mut self) -> crate::errno::Result<()> {
276 todo!();
277 }
mark_waited(&mut self) -> crate::errno::Result<bool>278 fn mark_waited(&mut self) -> crate::errno::Result<bool> {
279 todo!();
280 }
clear(&mut self) -> crate::errno::Result<()>281 fn clear(&mut self) -> crate::errno::Result<()> {
282 todo!();
283 }
resolution(&self) -> crate::errno::Result<std::time::Duration>284 fn resolution(&self) -> crate::errno::Result<std::time::Duration> {
285 todo!();
286 }
287 }
288
289 pub(crate) use libc::off_t;
290 pub(crate) use libc::pread;
291 pub(crate) use libc::preadv;
292 pub(crate) use libc::pwrite;
293 pub(crate) use libc::pwritev;
294
295 /// Spawns a pipe pair where the first pipe is the read end and the second pipe is the write end.
296 ///
297 /// The `O_CLOEXEC` flag will be applied after pipe creation.
pipe() -> crate::errno::Result<(File, File)>298 pub fn pipe() -> crate::errno::Result<(File, File)> {
299 let mut pipe_fds = [-1; 2];
300 // SAFETY:
301 // Safe because pipe will only write 2 element array of i32 to the given pointer, and we check
302 // for error.
303 let ret = unsafe { libc::pipe(pipe_fds.as_mut_ptr()) };
304 if ret == -1 {
305 return crate::errno::errno_result();
306 }
307
308 // SAFETY:
309 // Safe because both fds must be valid for pipe to have returned sucessfully and we have
310 // exclusive ownership of them.
311 let pipes = unsafe {
312 (
313 File::from_raw_descriptor(pipe_fds[0]),
314 File::from_raw_descriptor(pipe_fds[1]),
315 )
316 };
317
318 set_descriptor_cloexec(&pipes.0)?;
319 set_descriptor_cloexec(&pipes.1)?;
320
321 Ok(pipes)
322 }
323