Skip to content

Commit 5aa779f

Browse files
committed
increase the readability by using the unique name for the hermit-abi
Take up suggestion from the discussions within rust-lang#115984 to increase readability.
1 parent e0ac250 commit 5aa779f

File tree

10 files changed

+81
-80
lines changed

10 files changed

+81
-80
lines changed

library/std/src/os/hermit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#[allow(unused_extern_crates)]
44
#[stable(feature = "rust1", since = "1.0.0")]
5-
pub extern crate hermit_abi as abi;
5+
pub extern crate hermit_abi;
66

77
pub mod ffi;
88
pub mod io;
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use super::abi;
1+
use super::hermit_abi;
22
use crate::alloc::{GlobalAlloc, Layout, System};
33
use crate::ptr;
44

55
#[stable(feature = "alloc_system_type", since = "1.28.0")]
66
unsafe impl GlobalAlloc for System {
77
#[inline]
88
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
9-
abi::malloc(layout.size(), layout.align())
9+
hermit_abi::malloc(layout.size(), layout.align())
1010
}
1111

1212
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
13-
let addr = abi::malloc(layout.size(), layout.align());
13+
let addr = hermit_abi::malloc(layout.size(), layout.align());
1414

1515
if !addr.is_null() {
1616
ptr::write_bytes(addr, 0x00, layout.size());
@@ -21,11 +21,11 @@ unsafe impl GlobalAlloc for System {
2121

2222
#[inline]
2323
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
24-
abi::free(ptr, layout.size(), layout.align())
24+
hermit_abi::free(ptr, layout.size(), layout.align())
2525
}
2626

2727
#[inline]
2828
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
29-
abi::realloc(ptr, layout.size(), layout.align(), new_size)
29+
hermit_abi::realloc(ptr, layout.size(), layout.align(), new_size)
3030
}
3131
}

library/std/src/sys/pal/hermit/fd.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![unstable(reason = "not public", issue = "none", feature = "fd")]
22

3-
use super::abi;
3+
use super::hermit_abi;
44
use crate::io::{self, Read};
55
use crate::os::hermit::io::{FromRawFd, OwnedFd, RawFd};
66
use crate::sys::cvt;
@@ -16,7 +16,8 @@ pub struct FileDesc {
1616

1717
impl FileDesc {
1818
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
19-
let result = cvt(unsafe { abi::read(self.fd.as_raw_fd(), buf.as_mut_ptr(), buf.len()) })?;
19+
let result =
20+
cvt(unsafe { hermit_abi::read(self.fd.as_raw_fd(), buf.as_mut_ptr(), buf.len()) })?;
2021
Ok(result as usize)
2122
}
2223

@@ -26,7 +27,8 @@ impl FileDesc {
2627
}
2728

2829
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
29-
let result = cvt(unsafe { abi::write(self.fd.as_raw_fd(), buf.as_ptr(), buf.len()) })?;
30+
let result =
31+
cvt(unsafe { hermit_abi::write(self.fd.as_raw_fd(), buf.as_ptr(), buf.len()) })?;
3032
Ok(result as usize)
3133
}
3234

@@ -49,8 +51,8 @@ impl FileDesc {
4951
unsupported()
5052
}
5153

52-
pub fn fstat(&self, stat: *mut abi::stat) -> io::Result<()> {
53-
cvt(unsafe { abi::fstat(self.fd.as_raw_fd(), stat) })?;
54+
pub fn fstat(&self, stat: *mut hermit_abi::stat) -> io::Result<()> {
55+
cvt(unsafe { hermit_abi::fstat(self.fd.as_raw_fd(), stat) })?;
5456
Ok(())
5557
}
5658
}

library/std/src/sys/pal/hermit/fs.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::abi::{
1+
use super::fd::FileDesc;
2+
use super::hermit_abi::{
23
self, dirent64, stat as stat_struct, DT_DIR, DT_LNK, DT_REG, DT_UNKNOWN, O_APPEND, O_CREAT,
34
O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG,
45
};
5-
use super::fd::FileDesc;
66
use crate::ffi::{CStr, OsStr, OsString};
77
use crate::fmt;
88
use crate::io::{self, Error, ErrorKind};
@@ -206,9 +206,7 @@ impl Iterator for ReadDir {
206206
return None;
207207
}
208208

209-
let dir = unsafe {
210-
&*(self.inner.dir.as_ptr().add(offset) as *const dirent64)
211-
};
209+
let dir = unsafe { &*(self.inner.dir.as_ptr().add(offset) as *const dirent64) };
212210

213211
if counter == self.pos {
214212
self.pos += 1;
@@ -217,9 +215,8 @@ impl Iterator for ReadDir {
217215
// plus the length of the file name. Consequently, file name has a size of d_reclen minus
218216
// the size of dirent64. The file name is always a C string and terminated by `\0`.
219217
// Consequently, we are able to ignore the last byte.
220-
let name_bytes = unsafe {
221-
CStr::from_ptr(&dir.d_name as *const _ as *const i8).to_bytes()
222-
};
218+
let name_bytes =
219+
unsafe { CStr::from_ptr(&dir.d_name as *const _ as *const i8).to_bytes() };
223220
let entry = DirEntry {
224221
root: self.inner.root.clone(),
225222
ino: dir.d_ino,
@@ -361,7 +358,7 @@ impl File {
361358
mode = 0;
362359
}
363360

364-
let fd = unsafe { cvt(abi::open(path.as_ptr(), flags, mode))? };
361+
let fd = unsafe { cvt(hermit_abi::open(path.as_ptr(), flags, mode))? };
365362
Ok(File(unsafe { FileDesc::from_raw_fd(fd as i32) }))
366363
}
367364

@@ -442,7 +439,7 @@ impl DirBuilder {
442439

443440
pub fn mkdir(&self, path: &Path) -> io::Result<()> {
444441
run_path_with_cstr(path, &|path| {
445-
cvt(unsafe { abi::mkdir(path.as_ptr(), self.mode) }).map(|_| ())
442+
cvt(unsafe { hermit_abi::mkdir(path.as_ptr(), self.mode) }).map(|_| ())
446443
})
447444
}
448445

@@ -504,7 +501,8 @@ impl FromRawFd for File {
504501
}
505502

506503
pub fn readdir(path: &Path) -> io::Result<ReadDir> {
507-
let fd_raw = run_path_with_cstr(path, &|path| cvt(unsafe { abi::opendir(path.as_ptr()) }))?;
504+
let fd_raw =
505+
run_path_with_cstr(path, &|path| cvt(unsafe { hermit_abi::opendir(path.as_ptr()) }))?;
508506
let fd = unsafe { FileDesc::from_raw_fd(fd_raw as i32) };
509507
let root = path.to_path_buf();
510508

@@ -515,8 +513,9 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
515513
// reserve memory to receive all directory entries
516514
vec.resize(sz, 0);
517515

518-
let readlen =
519-
unsafe { abi::getdents64(fd.as_raw_fd(), vec.as_mut_ptr() as *mut dirent64, sz) };
516+
let readlen = unsafe {
517+
hermit_abi::getdents64(fd.as_raw_fd(), vec.as_mut_ptr() as *mut dirent64, sz)
518+
};
520519
if readlen > 0 {
521520
// shrink down to the minimal size
522521
vec.resize(readlen.try_into().unwrap(), 0);
@@ -525,7 +524,7 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
525524

526525
// if the buffer is too small, getdents64 returns EINVAL
527526
// otherwise, getdents64 returns an error number
528-
if readlen != (-abi::errno::EINVAL).into() {
527+
if readlen != (-hermit_abi::errno::EINVAL).into() {
529528
return Err(Error::from_raw_os_error(readlen.try_into().unwrap()));
530529
}
531530

@@ -543,7 +542,7 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
543542
}
544543

545544
pub fn unlink(path: &Path) -> io::Result<()> {
546-
run_path_with_cstr(path, &|path| cvt(unsafe { abi::unlink(path.as_ptr()) }).map(|_| ()))
545+
run_path_with_cstr(path, &|path| cvt(unsafe { hermit_abi::unlink(path.as_ptr()) }).map(|_| ()))
547546
}
548547

549548
pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
@@ -555,7 +554,7 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
555554
}
556555

557556
pub fn rmdir(path: &Path) -> io::Result<()> {
558-
run_path_with_cstr(path, &|path| cvt(unsafe { abi::rmdir(path.as_ptr()) }).map(|_| ()))
557+
run_path_with_cstr(path, &|path| cvt(unsafe { hermit_abi::rmdir(path.as_ptr()) }).map(|_| ()))
559558
}
560559

561560
pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
@@ -577,15 +576,15 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
577576
pub fn stat(path: &Path) -> io::Result<FileAttr> {
578577
run_path_with_cstr(path, &|path| {
579578
let mut stat_val: stat_struct = unsafe { mem::zeroed() };
580-
cvt(unsafe { abi::stat(path.as_ptr(), &mut stat_val) })?;
579+
cvt(unsafe { hermit_abi::stat(path.as_ptr(), &mut stat_val) })?;
581580
Ok(FileAttr::from_stat(stat_val))
582581
})
583582
}
584583

585584
pub fn lstat(path: &Path) -> io::Result<FileAttr> {
586585
run_path_with_cstr(path, &|path| {
587586
let mut stat_val: stat_struct = unsafe { mem::zeroed() };
588-
cvt(unsafe { abi::lstat(path.as_ptr(), &mut stat_val) })?;
587+
cvt(unsafe { hermit_abi::lstat(path.as_ptr(), &mut stat_val) })?;
589588
Ok(FileAttr::from_stat(stat_val))
590589
})
591590
}
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::abi;
1+
use super::hermit_abi;
22
use crate::ptr::null;
33
use crate::sync::atomic::AtomicU32;
44
use crate::time::Duration;
@@ -8,32 +8,32 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -
88
//
99
// Overflows are rounded up to an infinite timeout (None).
1010
let timespec = timeout.and_then(|dur| {
11-
Some(abi::timespec {
11+
Some(hermit_abi::timespec {
1212
tv_sec: dur.as_secs().try_into().ok()?,
1313
tv_nsec: dur.subsec_nanos().into(),
1414
})
1515
});
1616

1717
let r = unsafe {
18-
abi::futex_wait(
18+
hermit_abi::futex_wait(
1919
futex.as_ptr(),
2020
expected,
21-
timespec.as_ref().map_or(null(), |t| t as *const abi::timespec),
22-
abi::FUTEX_RELATIVE_TIMEOUT,
21+
timespec.as_ref().map_or(null(), |t| t as *const hermit_abi::timespec),
22+
hermit_abi::FUTEX_RELATIVE_TIMEOUT,
2323
)
2424
};
2525

26-
r != -abi::errno::ETIMEDOUT
26+
r != -hermit_abi::errno::ETIMEDOUT
2727
}
2828

2929
#[inline]
3030
pub fn futex_wake(futex: &AtomicU32) -> bool {
31-
unsafe { abi::futex_wake(futex.as_ptr(), 1) > 0 }
31+
unsafe { hermit_abi::futex_wake(futex.as_ptr(), 1) > 0 }
3232
}
3333

3434
#[inline]
3535
pub fn futex_wake_all(futex: &AtomicU32) {
3636
unsafe {
37-
abi::futex_wake(futex.as_ptr(), i32::MAX);
37+
hermit_abi::futex_wake(futex.as_ptr(), i32::MAX);
3838
}
3939
}

library/std/src/sys/pal/hermit/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub mod thread_local_key;
3939
pub mod time;
4040

4141
use crate::io::ErrorKind;
42-
use crate::os::hermit::abi;
42+
use crate::os::hermit::hermit_abi;
4343

4444
pub fn unsupported<T>() -> crate::io::Result<T> {
4545
Err(unsupported_err())
@@ -54,15 +54,15 @@ pub fn unsupported_err() -> crate::io::Error {
5454

5555
pub fn abort_internal() -> ! {
5656
unsafe {
57-
abi::abort();
57+
hermit_abi::abort();
5858
}
5959
}
6060

6161
pub fn hashmap_random_keys() -> (u64, u64) {
6262
let mut buf = [0; 16];
6363
let mut slice = &mut buf[..];
6464
while !slice.is_empty() {
65-
let res = cvt(unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) })
65+
let res = cvt(unsafe { hermit_abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) })
6666
.expect("failed to generate random hashmap keys");
6767
slice = &mut slice[res as usize..];
6868
}
@@ -109,31 +109,31 @@ pub unsafe extern "C" fn runtime_entry(
109109
let result = main(argc as isize, argv);
110110

111111
run_dtors();
112-
abi::exit(result);
112+
hermit_abi::exit(result);
113113
}
114114

115115
#[inline]
116116
pub(crate) fn is_interrupted(errno: i32) -> bool {
117-
errno == abi::errno::EINTR
117+
errno == hermit_abi::errno::EINTR
118118
}
119119

120120
pub fn decode_error_kind(errno: i32) -> ErrorKind {
121121
match errno {
122-
abi::errno::EACCES => ErrorKind::PermissionDenied,
123-
abi::errno::EADDRINUSE => ErrorKind::AddrInUse,
124-
abi::errno::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
125-
abi::errno::EAGAIN => ErrorKind::WouldBlock,
126-
abi::errno::ECONNABORTED => ErrorKind::ConnectionAborted,
127-
abi::errno::ECONNREFUSED => ErrorKind::ConnectionRefused,
128-
abi::errno::ECONNRESET => ErrorKind::ConnectionReset,
129-
abi::errno::EEXIST => ErrorKind::AlreadyExists,
130-
abi::errno::EINTR => ErrorKind::Interrupted,
131-
abi::errno::EINVAL => ErrorKind::InvalidInput,
132-
abi::errno::ENOENT => ErrorKind::NotFound,
133-
abi::errno::ENOTCONN => ErrorKind::NotConnected,
134-
abi::errno::EPERM => ErrorKind::PermissionDenied,
135-
abi::errno::EPIPE => ErrorKind::BrokenPipe,
136-
abi::errno::ETIMEDOUT => ErrorKind::TimedOut,
122+
hermit_abi::errno::EACCES => ErrorKind::PermissionDenied,
123+
hermit_abi::errno::EADDRINUSE => ErrorKind::AddrInUse,
124+
hermit_abi::errno::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
125+
hermit_abi::errno::EAGAIN => ErrorKind::WouldBlock,
126+
hermit_abi::errno::ECONNABORTED => ErrorKind::ConnectionAborted,
127+
hermit_abi::errno::ECONNREFUSED => ErrorKind::ConnectionRefused,
128+
hermit_abi::errno::ECONNRESET => ErrorKind::ConnectionReset,
129+
hermit_abi::errno::EEXIST => ErrorKind::AlreadyExists,
130+
hermit_abi::errno::EINTR => ErrorKind::Interrupted,
131+
hermit_abi::errno::EINVAL => ErrorKind::InvalidInput,
132+
hermit_abi::errno::ENOENT => ErrorKind::NotFound,
133+
hermit_abi::errno::ENOTCONN => ErrorKind::NotConnected,
134+
hermit_abi::errno::EPERM => ErrorKind::PermissionDenied,
135+
hermit_abi::errno::EPIPE => ErrorKind::BrokenPipe,
136+
hermit_abi::errno::ETIMEDOUT => ErrorKind::TimedOut,
137137
_ => ErrorKind::Uncategorized,
138138
}
139139
}

library/std/src/sys/pal/hermit/os.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::abi;
1+
use super::hermit_abi;
22
use crate::collections::HashMap;
33
use crate::error::Error as StdError;
44
use crate::ffi::{CStr, OsStr, OsString};
@@ -14,11 +14,11 @@ use crate::vec;
1414
use core::slice::memchr;
1515

1616
pub fn errno() -> i32 {
17-
unsafe { abi::get_errno() }
17+
unsafe { hermit_abi::get_errno() }
1818
}
1919

2020
pub fn error_string(errno: i32) -> String {
21-
abi::error_string(errno).to_string()
21+
hermit_abi::error_string(errno).to_string()
2222
}
2323

2424
pub fn getcwd() -> io::Result<PathBuf> {
@@ -197,10 +197,10 @@ pub fn home_dir() -> Option<PathBuf> {
197197

198198
pub fn exit(code: i32) -> ! {
199199
unsafe {
200-
abi::exit(code);
200+
hermit_abi::exit(code);
201201
}
202202
}
203203

204204
pub fn getpid() -> u32 {
205-
unsafe { abi::getpid() }
205+
unsafe { hermit_abi::getpid() }
206206
}

library/std/src/sys/pal/hermit/stdio.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::abi;
1+
use super::hermit_abi;
22
use crate::io;
33
use crate::io::{IoSlice, IoSliceMut};
44

@@ -37,7 +37,7 @@ impl io::Write for Stdout {
3737
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
3838
let len;
3939

40-
unsafe { len = abi::write(1, data.as_ptr() as *const u8, data.len()) }
40+
unsafe { len = hermit_abi::write(1, data.as_ptr() as *const u8, data.len()) }
4141

4242
if len < 0 {
4343
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Stdout is not able to print"))
@@ -49,7 +49,7 @@ impl io::Write for Stdout {
4949
fn write_vectored(&mut self, data: &[IoSlice<'_>]) -> io::Result<usize> {
5050
let len;
5151

52-
unsafe { len = abi::write(1, data.as_ptr() as *const u8, data.len()) }
52+
unsafe { len = hermit_abi::write(1, data.as_ptr() as *const u8, data.len()) }
5353

5454
if len < 0 {
5555
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Stdout is not able to print"))
@@ -78,7 +78,7 @@ impl io::Write for Stderr {
7878
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
7979
let len;
8080

81-
unsafe { len = abi::write(2, data.as_ptr() as *const u8, data.len()) }
81+
unsafe { len = hermit_abi::write(2, data.as_ptr() as *const u8, data.len()) }
8282

8383
if len < 0 {
8484
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Stderr is not able to print"))
@@ -90,7 +90,7 @@ impl io::Write for Stderr {
9090
fn write_vectored(&mut self, data: &[IoSlice<'_>]) -> io::Result<usize> {
9191
let len;
9292

93-
unsafe { len = abi::write(2, data.as_ptr() as *const u8, data.len()) }
93+
unsafe { len = hermit_abi::write(2, data.as_ptr() as *const u8, data.len()) }
9494

9595
if len < 0 {
9696
Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Stderr is not able to print"))

0 commit comments

Comments
 (0)