Skip to content

Commit 3a73dfb

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 3a73dfb

File tree

10 files changed

+70
-72
lines changed

10 files changed

+70
-72
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

+5-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,7 @@ 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 = cvt(unsafe { hermit_abi::read(self.fd.as_raw_fd(), buf.as_mut_ptr(), buf.len()) })?;
2020
Ok(result as usize)
2121
}
2222

@@ -26,7 +26,7 @@ impl FileDesc {
2626
}
2727

2828
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()) })?;
29+
let result = cvt(unsafe { hermit_abi::write(self.fd.as_raw_fd(), buf.as_ptr(), buf.len()) })?;
3030
Ok(result as usize)
3131
}
3232

@@ -49,8 +49,8 @@ impl FileDesc {
4949
unsupported()
5050
}
5151

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

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::abi::{
1+
use super::hermit_abi::{
22
self, dirent64, stat as stat_struct, DT_DIR, DT_LNK, DT_REG, DT_UNKNOWN, O_APPEND, O_CREAT,
33
O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG,
44
};
@@ -361,7 +361,7 @@ impl File {
361361
mode = 0;
362362
}
363363

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

@@ -442,7 +442,7 @@ impl DirBuilder {
442442

443443
pub fn mkdir(&self, path: &Path) -> io::Result<()> {
444444
run_path_with_cstr(path, &|path| {
445-
cvt(unsafe { abi::mkdir(path.as_ptr(), self.mode) }).map(|_| ())
445+
cvt(unsafe { hermit_abi::mkdir(path.as_ptr(), self.mode) }).map(|_| ())
446446
})
447447
}
448448

@@ -504,7 +504,7 @@ impl FromRawFd for File {
504504
}
505505

506506
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()) }))?;
507+
let fd_raw = run_path_with_cstr(path, &|path| cvt(unsafe { hermit_abi::opendir(path.as_ptr()) }))?;
508508
let fd = unsafe { FileDesc::from_raw_fd(fd_raw as i32) };
509509
let root = path.to_path_buf();
510510

@@ -516,7 +516,7 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
516516
vec.resize(sz, 0);
517517

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

526526
// if the buffer is too small, getdents64 returns EINVAL
527527
// otherwise, getdents64 returns an error number
528-
if readlen != (-abi::errno::EINVAL).into() {
528+
if readlen != (-hermit_abi::errno::EINVAL).into() {
529529
return Err(Error::from_raw_os_error(readlen.try_into().unwrap()));
530530
}
531531

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

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

549549
pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
@@ -555,7 +555,7 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
555555
}
556556

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

561561
pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
@@ -577,15 +577,15 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
577577
pub fn stat(path: &Path) -> io::Result<FileAttr> {
578578
run_path_with_cstr(path, &|path| {
579579
let mut stat_val: stat_struct = unsafe { mem::zeroed() };
580-
cvt(unsafe { abi::stat(path.as_ptr(), &mut stat_val) })?;
580+
cvt(unsafe { hermit_abi::stat(path.as_ptr(), &mut stat_val) })?;
581581
Ok(FileAttr::from_stat(stat_val))
582582
})
583583
}
584584

585585
pub fn lstat(path: &Path) -> io::Result<FileAttr> {
586586
run_path_with_cstr(path, &|path| {
587587
let mut stat_val: stat_struct = unsafe { mem::zeroed() };
588-
cvt(unsafe { abi::lstat(path.as_ptr(), &mut stat_val) })?;
588+
cvt(unsafe { hermit_abi::lstat(path.as_ptr(), &mut stat_val) })?;
589589
Ok(FileAttr::from_stat(stat_val))
590590
})
591591
}
+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)