зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1716518 - Upgrade hermit-abi to v0.1.18. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D117794
This commit is contained in:
Родитель
dbe5aa3629
Коммит
e7619f1be9
|
@ -2308,9 +2308,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.12"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
|
||||
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"dd977b9273d4463b1209bf9241b74edb2ec928aedab1e11c4137b5c0ec4d4533","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"8c4278de40812c689d00e854a052ff47e1abf0c03441537b3a9d7ee9a8c94617","rust-toolchain":"58bea07cb6d97f9cfcd5c8f98b1feca0fb81cce5b0bf29a8e70ed2641956e9a6","src/lib.rs":"d9b2246533bff48539b2bfa3ad92b1005f779d41a9e06829c026800dfb413e6e","src/tcpstream.rs":"73807a89635126a347da53ee7ffd07795e107e9dd98cd7d5914bc9f1ef4f5a8d"},"package":"61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"}
|
||||
{"files":{"Cargo.toml":"6cd0350a8b7cf5f825b88b1cafc7a5e71781d91dc1c2e57646d909c689e9afed","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"322fadd63e558e5a10caf980cbedf83ac1546ba40fd992f54492e21ce54205af","rust-toolchain":"58bea07cb6d97f9cfcd5c8f98b1feca0fb81cce5b0bf29a8e70ed2641956e9a6","src/lib.rs":"1fe7da738cb27c5c0941f6d4079bac8eb3e81da2aeb71fcfb81e37584fddaad7","src/tcplistener.rs":"c6e2db06d4265fa0956851e1c965336d60c53ab21573729aae76ecfe0ccc84c3","src/tcpstream.rs":"38a17de54213faf9de217f6146ff86ee75b67d4404a532b1419903269200936b"},"package":"322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"}
|
|
@ -11,15 +11,17 @@
|
|||
# will likely look very different (and much more reasonable)
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
name = "hermit-abi"
|
||||
version = "0.1.12"
|
||||
version = "0.1.18"
|
||||
authors = ["Stefan Lankes"]
|
||||
description = "hermit-abi is small interface to call functions from the unikernel RustyHermit.\nIt is used to build the target `x86_64-unknown-hermit`.\n"
|
||||
documentation = "https://hermitcore.github.io/rusty-hermit/hermit_abi"
|
||||
readme = "README.md"
|
||||
keywords = ["unikernel", "libos"]
|
||||
categories = ["os"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/hermitcore/rusty-hermit"
|
||||
repository = "https://github.com/hermitcore/libhermit-rs"
|
||||
[package.metadata.docs.rs]
|
||||
default-target = "x86_64-unknown-hermit"
|
||||
features = ["docs"]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# hermit-abi
|
||||
|
||||
[![Crates.io](https://img.shields.io/crates/v/hermit-abi.svg)](https://crates.io/crates/hermit-abi)
|
||||
[![Documentation](https://docs.rs/hermit-abi/badge.svg)](https://docs.rs/hermit-abi)
|
||||
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://hermitcore.github.io/rusty-hermit/hermit_abi/)
|
||||
[![License](https://img.shields.io/crates/l/hermit-abi.svg)](https://img.shields.io/crates/l/hermit-abi.svg)
|
||||
|
||||
This is small interface to call functions from the unikernel [RustyHermit](https://github.com/hermitcore/libhermit-rs).
|
||||
|
@ -19,4 +19,4 @@ at your option.
|
|||
|
||||
## Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
||||
|
|
|
@ -1,20 +1,29 @@
|
|||
//! `hermit-abi` is small interface to call functions from the unikernel
|
||||
//! [RustyHermit](https://github.com/hermitcore/libhermit-rs).
|
||||
|
||||
#![cfg_attr(feature = "rustc-dep-of-std", no_std)]
|
||||
#![feature(const_raw_ptr_to_usize_cast)]
|
||||
#![no_std]
|
||||
extern crate libc;
|
||||
|
||||
pub mod tcplistener;
|
||||
pub mod tcpstream;
|
||||
|
||||
use libc::c_void;
|
||||
|
||||
// sysmbols, which are part of the library operating system
|
||||
|
||||
extern "Rust" {
|
||||
fn sys_secure_rand64() -> Option<u64>;
|
||||
fn sys_secure_rand32() -> Option<u32>;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn sys_rand() -> u32;
|
||||
fn sys_srand(seed: u32);
|
||||
fn sys_get_processor_count() -> usize;
|
||||
fn sys_malloc(size: usize, align: usize) -> *mut u8;
|
||||
fn sys_realloc(ptr: *mut u8, size: usize, align: usize, new_size: usize) -> *mut u8;
|
||||
fn sys_free(ptr: *mut u8, size: usize, align: usize);
|
||||
fn sys_init_queue(ptr: usize) -> i32;
|
||||
fn sys_notify(id: usize, count: i32) -> i32;
|
||||
fn sys_add_queue(id: usize, timeout_ns: i64) -> i32;
|
||||
fn sys_wait(id: usize) -> i32;
|
||||
|
@ -55,11 +64,17 @@ extern "C" {
|
|||
fn sys_open(name: *const i8, flags: i32, mode: i32) -> i32;
|
||||
fn sys_unlink(name: *const i8) -> i32;
|
||||
fn sys_network_init() -> i32;
|
||||
fn sys_block_current_task();
|
||||
fn sys_wakeup_task(tid: Tid);
|
||||
fn sys_get_priority() -> u8;
|
||||
}
|
||||
|
||||
/// A thread handle type
|
||||
pub type Tid = u32;
|
||||
|
||||
/// Maximum number of priorities
|
||||
pub const NO_PRIORITIES: usize = 31;
|
||||
|
||||
/// Priority of a thread
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
|
||||
pub struct Priority(u8);
|
||||
|
@ -117,6 +132,34 @@ pub struct timespec {
|
|||
pub tv_nsec: i64,
|
||||
}
|
||||
|
||||
/// Internet protocol version.
|
||||
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||
pub enum Version {
|
||||
Unspecified,
|
||||
Ipv4,
|
||||
Ipv6,
|
||||
}
|
||||
|
||||
/// A four-octet IPv4 address.
|
||||
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
|
||||
pub struct Ipv4Address(pub [u8; 4]);
|
||||
|
||||
/// A sixteen-octet IPv6 address.
|
||||
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
|
||||
pub struct Ipv6Address(pub [u8; 16]);
|
||||
|
||||
/// An internetworking address.
|
||||
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||
pub enum IpAddress {
|
||||
/// An unspecified address.
|
||||
/// May be used as a placeholder for storage where the address is not assigned yet.
|
||||
Unspecified,
|
||||
/// An IPv4 address.
|
||||
Ipv4(Ipv4Address),
|
||||
/// An IPv6 address.
|
||||
Ipv6(Ipv6Address),
|
||||
}
|
||||
|
||||
/// determines the number of activated processors
|
||||
#[inline(always)]
|
||||
pub unsafe fn get_processor_count() -> usize {
|
||||
|
@ -158,6 +201,12 @@ pub unsafe fn wait(id: usize) -> i32 {
|
|||
sys_wait(id)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub unsafe fn init_queue(id: usize) -> i32 {
|
||||
sys_init_queue(id)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub unsafe fn destroy_queue(id: usize) -> i32 {
|
||||
|
@ -384,3 +433,55 @@ pub unsafe fn open(name: *const i8, flags: i32, mode: i32) -> i32 {
|
|||
pub unsafe fn unlink(name: *const i8) -> i32 {
|
||||
sys_unlink(name)
|
||||
}
|
||||
|
||||
/// The largest number `rand` will return
|
||||
pub const RAND_MAX: u64 = 2_147_483_647;
|
||||
|
||||
/// The function computes a sequence of pseudo-random integers
|
||||
/// in the range of 0 to RAND_MAX
|
||||
#[inline(always)]
|
||||
pub unsafe fn rand() -> u32 {
|
||||
sys_rand()
|
||||
}
|
||||
|
||||
/// The function sets its argument as the seed for a new sequence
|
||||
/// of pseudo-random numbers to be returned by `rand`
|
||||
#[inline(always)]
|
||||
pub unsafe fn srand(seed: u32) {
|
||||
sys_srand(seed);
|
||||
}
|
||||
|
||||
/// Create a cryptographicly secure 32bit random number with the support of
|
||||
/// the underlying hardware. If the required hardware isn't available,
|
||||
/// the function returns `None`.
|
||||
#[inline(always)]
|
||||
pub unsafe fn secure_rand32() -> Option<u32> {
|
||||
sys_secure_rand32()
|
||||
}
|
||||
|
||||
/// Create a cryptographicly secure 64bit random number with the support of
|
||||
/// the underlying hardware. If the required hardware isn't available,
|
||||
/// the function returns `None`.
|
||||
#[inline(always)]
|
||||
pub unsafe fn secure_rand64() -> Option<u64> {
|
||||
sys_secure_rand64()
|
||||
}
|
||||
|
||||
/// Add current task to the queue of blocked tasl. After calling `block_current_task`,
|
||||
/// call `yield_now` to switch to another task.
|
||||
#[inline(always)]
|
||||
pub unsafe fn block_current_task() {
|
||||
sys_block_current_task();
|
||||
}
|
||||
|
||||
/// Wakeup task with the thread id `tid`
|
||||
#[inline(always)]
|
||||
pub unsafe fn wakeup_task(tid: Tid) {
|
||||
sys_wakeup_task(tid);
|
||||
}
|
||||
|
||||
/// Determine the priority of the current thread
|
||||
#[inline(always)]
|
||||
pub unsafe fn get_priority() -> Priority {
|
||||
Priority::from(sys_get_priority())
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
//! `tcplistener` provide an interface to establish tcp socket server.
|
||||
|
||||
use crate::{Handle, IpAddress};
|
||||
|
||||
extern "Rust" {
|
||||
fn sys_tcp_listener_accept(port: u16) -> Result<(Handle, IpAddress, u16), ()>;
|
||||
}
|
||||
|
||||
/// Wait for connection at specified address.
|
||||
#[inline(always)]
|
||||
pub fn accept(port: u16) -> Result<(Handle, IpAddress, u16), ()> {
|
||||
unsafe { sys_tcp_listener_accept(port) }
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
//! `tcpstream` provide an interface to the network stack
|
||||
//! `tcpstream` provide an interface to establish tcp socket client.
|
||||
|
||||
use crate::Handle;
|
||||
use crate::{Handle, IpAddress};
|
||||
|
||||
extern "Rust" {
|
||||
fn sys_tcp_stream_connect(ip: &[u8], port: u16, timeout: Option<u64>) -> Result<Handle, ()>;
|
||||
|
@ -11,12 +11,12 @@ extern "Rust" {
|
|||
fn sys_tcp_stream_get_read_timeout(handle: Handle) -> Result<Option<u64>, ()>;
|
||||
fn sys_tcp_stream_set_write_timeout(handle: Handle, timeout: Option<u64>) -> Result<(), ()>;
|
||||
fn sys_tcp_stream_get_write_timeout(handle: Handle) -> Result<Option<u64>, ()>;
|
||||
fn sys_tcp_stream_duplicate(handle: Handle) -> Result<Handle, ()>;
|
||||
fn sys_tcp_stream_peek(handle: Handle, buf: &mut [u8]) -> Result<usize, ()>;
|
||||
fn sys_tcp_stream_set_nonblocking(handle: Handle, mode: bool) -> Result<(), ()>;
|
||||
fn sys_tcp_stream_set_tll(handle: Handle, ttl: u32) -> Result<(), ()>;
|
||||
fn sys_tcp_stream_get_tll(handle: Handle) -> Result<u32, ()>;
|
||||
fn sys_tcp_stream_shutdown(handle: Handle, how: i32) -> Result<(), ()>;
|
||||
fn sys_tcp_stream_peer_addr(handle: Handle) -> Result<(IpAddress, u16), ()>;
|
||||
}
|
||||
|
||||
/// Opens a TCP connection to a remote host.
|
||||
|
@ -31,16 +31,15 @@ pub fn close(handle: Handle) -> Result<(), ()> {
|
|||
unsafe { sys_tcp_stream_close(handle) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn duplicate(handle: Handle) -> Result<Handle, ()> {
|
||||
unsafe { sys_tcp_stream_duplicate(handle) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn peek(handle: Handle, buf: &mut [u8]) -> Result<usize, ()> {
|
||||
unsafe { sys_tcp_stream_peek(handle, buf) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn peer_addr(handle: Handle) -> Result<(IpAddress, u16), ()> {
|
||||
unsafe { sys_tcp_stream_peer_addr(handle) }
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn read(handle: Handle, buffer: &mut [u8]) -> Result<usize, ()> {
|
||||
unsafe { sys_tcp_stream_read(handle, buffer) }
|
||||
|
@ -74,8 +73,8 @@ pub fn get_write_timeout(handle: Handle) -> Result<Option<u64>, ()> {
|
|||
#[inline(always)]
|
||||
pub fn set_nodelay(_: Handle, mode: bool) -> Result<(), ()> {
|
||||
// smoltcp does not support Nagle's algorithm
|
||||
// => to enable Nagle's algorithm ins't possineö
|
||||
if mode == true {
|
||||
// => to enable Nagle's algorithm isn't possible
|
||||
if mode {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
|
|
Загрузка…
Ссылка в новой задаче