-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rework networking a bit, add some functions * Update to new lints
- Loading branch information
1 parent
9961f0a
commit 2d573ad
Showing
33 changed files
with
1,483 additions
and
91 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# General dev-notes | ||
|
||
Running multi-arch is difficult. | ||
|
||
## Qemu | ||
|
||
`qemu-aarch64` version 9.0.0 [seems to have an issue](https://gitlab.com/qemu-project/qemu/-/issues/2326). | ||
Use a previous version, 0.7.2 works, manifests as VDSO-image address-alignment being zero, which | ||
causes a div-by-zero. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
pub use accept::accept; | ||
pub use bind::bind; | ||
pub use connect::connect; | ||
pub use accept::{accept_inet, accept_unix}; | ||
pub use bind::{bind_inet, bind_unix}; | ||
pub use connect::{connect_inet, connect_unix}; | ||
pub use listen::listen; | ||
pub use socket::socket; | ||
|
||
#[cfg(feature = "alloc")] | ||
pub use socket::{get_inet_sock_name, get_unix_sock_name, recvmsg, sendmsg, socket}; | ||
#[cfg(not(feature = "alloc"))] | ||
pub use socket::{get_inet_sock_name, get_unix_sock_name, socket}; | ||
|
||
mod accept; | ||
mod bind; | ||
mod connect; | ||
mod listen; | ||
mod socket; | ||
#[cfg(all(test, feature = "alloc"))] | ||
mod test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,57 @@ | ||
use core::mem::MaybeUninit; | ||
use sc::syscall; | ||
|
||
use crate::platform::{Fd, SocketArg, SocketFlags}; | ||
use crate::platform::{Fd, SocketAddressInet, SocketAddressUnix, SocketArgUnix, SocketFlags}; | ||
use crate::Result; | ||
|
||
/// Accept a new connection and set flags on the new connection's `Fd` | ||
/// Accept a new unix-connection and set flags on the new connection's `Fd` | ||
/// Accepted flags are 0, `SOCK_NONBLOCK` an `SOCK_CLOEXEC` | ||
/// The `socket_address` is the peer address, if applicable | ||
/// See [Linux documentation for more details](https://man7.org/linux/man-pages/man2/accept.2.html) | ||
/// # Errors | ||
/// See above | ||
#[inline] | ||
pub fn accept(sock_fd: Fd, socket_address: Option<&SocketArg>, flags: SocketFlags) -> Result<Fd> { | ||
let (addr, addr_len) = socket_address.map_or((0, 0), |addr| { | ||
(core::ptr::addr_of!(addr.addr) as usize, addr.addr_len) | ||
}); | ||
let res = unsafe { syscall!(ACCEPT4, sock_fd.0, addr, addr_len, flags.0) }; | ||
Fd::coerce_from_register(res, "`ACCEPT4` syscall failed") | ||
pub fn accept_unix(sock_fd: Fd, flags: SocketFlags) -> Result<(Fd, SocketArgUnix)> { | ||
let mut addr = MaybeUninit::zeroed(); | ||
let mut addr_len = core::mem::size_of::<SocketAddressUnix>(); | ||
let res = unsafe { | ||
syscall!( | ||
ACCEPT4, | ||
sock_fd.0, | ||
core::ptr::addr_of_mut!(addr), | ||
core::ptr::addr_of_mut!(addr_len), | ||
flags.0 | ||
) | ||
}; | ||
let fd = Fd::coerce_from_register(res, "`ACCEPT4` syscall failed")?; | ||
unsafe { | ||
Ok(( | ||
fd, | ||
SocketArgUnix { | ||
addr: addr.assume_init(), | ||
addr_len, | ||
}, | ||
)) | ||
} | ||
} | ||
|
||
/// Accept a new tcp-connection and set flags on the new connection's `Fd` | ||
/// Accepted flags are 0, `SOCK_NONBLOCK` an `SOCK_CLOEXEC` | ||
/// See [Linux documentation for more details](https://man7.org/linux/man-pages/man2/accept.2.html) | ||
/// # Errors | ||
/// See above | ||
#[inline] | ||
pub fn accept_inet(sock_fd: Fd, flags: SocketFlags) -> Result<(Fd, SocketAddressInet)> { | ||
let mut addr = MaybeUninit::zeroed(); | ||
let mut addr_len = core::mem::size_of::<SocketAddressUnix>(); | ||
let res = unsafe { | ||
syscall!( | ||
ACCEPT4, | ||
sock_fd.0, | ||
core::ptr::addr_of_mut!(addr), | ||
core::ptr::addr_of_mut!(addr_len), | ||
flags.0 | ||
) | ||
}; | ||
let fd = Fd::coerce_from_register(res, "`ACCEPT4` syscall failed")?; | ||
unsafe { Ok((fd, addr.assume_init())) } | ||
} |
Oops, something went wrong.