Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions litebox_shim_linux/src/syscalls/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use litebox::{
};
use litebox_common_linux::{
AtFlags, EfdFlags, EpollCreateFlags, FcntlArg, FileDescriptorFlags, FileStat, IoReadVec,
IoWriteVec, IoctlArg, TimeParam, errno::Errno,
IoWriteVec, IoctlArg, TimeParam, errno::Errno, signal::Signal,
};
use litebox_platform_multiplex::Platform;

use crate::{ConstPtr, GlobalState, MutPtr, ShimFS, Task};
use crate::{ConstPtr, GlobalState, MutPtr, ShimFS, Task, syscalls::signal::siginfo_kill};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, use declarations for types/macros/modules are fine, but we make sure not to do so for functions, in order to match the conventions most mature Rust projects use.

use core::sync::atomic::{AtomicUsize, Ordering};

/// Task state shared by `CLONE_FS`.
Expand Down Expand Up @@ -420,7 +420,7 @@ impl<FS: ShimFS> Task<FS> {
)
.flatten();
if let Err(Errno::EPIPE) = res {
unimplemented!("send SIGPIPE to the current task");
self.send_signal(Signal::SIGPIPE, siginfo_kill(Signal::SIGPIPE));
}
res
}
Expand Down Expand Up @@ -671,7 +671,7 @@ impl<FS: ShimFS> Task<FS> {
)
.flatten();
if let Err(Errno::EPIPE) = res {
unimplemented!("send SIGPIPE to the current task");
self.send_signal(Signal::SIGPIPE, siginfo_kill(Signal::SIGPIPE));
}
res
}
Expand Down
38 changes: 22 additions & 16 deletions litebox_shim_linux/src/syscalls/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use litebox::{
};
use litebox_common_linux::{
AddressFamily, FileDescriptorFlags, IPProtocol, ReceiveFlags, SendFlags, SockFlags, SockType,
SocketOption, SocketOptionName, TcpOption, UnixProtocol, errno::Errno,
SocketOption, SocketOptionName, TcpOption, UnixProtocol, errno::Errno, signal::Signal,
};
use zerocopy::{FromBytes, IntoBytes};

use crate::{ConstPtr, MutPtr};
use crate::{ConstPtr, MutPtr, syscalls::signal::siginfo_kill};
use crate::{GlobalState, ShimFS, Task};
use crate::{
Platform,
Expand Down Expand Up @@ -735,7 +735,8 @@ impl<FS: ShimFS> GlobalState<FS> {
}

// Convert `SendFlags` to `litebox::net::SendFlags`
// `DONTWAIT` and `NOSIGNAL` are handled in this function so we don't convert them.
// `DONTWAIT` is handled in this function and `NOSIGNAL` should be handled by caller,
// so we don't convert them.
let new_flags = convert_flags!(
flags,
SendFlags,
Expand All @@ -751,8 +752,7 @@ impl<FS: ShimFS> GlobalState<FS> {
let is_nonblock =
self.get_status(fd).contains(OFlags::NONBLOCK) || flags.contains(SendFlags::DONTWAIT);

let ret = cx
.with_timeout(timeout)
cx.with_timeout(timeout)
.wait_on_events(
is_nonblock,
Events::OUT,
Expand All @@ -766,13 +766,7 @@ impl<FS: ShimFS> GlobalState<FS> {
Err(e) => Err(TryOpError::Other(Errno::from(e))),
},
)
.map_err(Errno::from);
if let Err(Errno::EPIPE) = ret
&& !flags.contains(SendFlags::NOSIGNAL)
{
unimplemented!("send signal SIGPIPE on EPIPE");
}
ret
.map_err(Errno::from)
}

/// Receive data via socket channel (lock-free path).
Expand Down Expand Up @@ -1345,7 +1339,7 @@ impl<FS: ShimFS> Task<FS> {
flags: SendFlags,
sockaddr: Option<SocketAddress>,
) -> Result<usize, Errno> {
self.files.borrow().with_socket(
let res = self.files.borrow().with_socket(
&self.global,
sockfd,
|fd| {
Expand All @@ -1363,7 +1357,13 @@ impl<FS: ShimFS> Task<FS> {
.transpose()?;
file.sendto(self, buf, flags, addr)
},
)
);
if let Err(Errno::EPIPE) = res
&& !flags.contains(SendFlags::NOSIGNAL)
{
self.send_signal(Signal::SIGPIPE, siginfo_kill(Signal::SIGPIPE));
}
res
}

/// Handle syscall `sendmsg`
Expand Down Expand Up @@ -1404,7 +1404,7 @@ impl<FS: ShimFS> Task<FS> {
.msg_iov
.to_owned_slice(msg.msg_iovlen)
.ok_or(Errno::EFAULT)?;
self.files.borrow().with_socket(
let res = self.files.borrow().with_socket(
&self.global,
sockfd,
|fd| {
Expand Down Expand Up @@ -1445,7 +1445,13 @@ impl<FS: ShimFS> Task<FS> {
}
Ok(total_sent)
},
)
);
if let Err(Errno::EPIPE) = res
&& !flags.contains(SendFlags::NOSIGNAL)
{
self.send_signal(Signal::SIGPIPE, siginfo_kill(Signal::SIGPIPE));
}
res
}

/// Handle syscall `recvfrom`
Expand Down
9 changes: 1 addition & 8 deletions litebox_shim_linux/src/syscalls/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,21 +1241,14 @@ impl<FS: ShimFS> UnixSocket<FS> {
let is_nonblocking =
flags.contains(SendFlags::DONTWAIT) || self.get_status().contains(OFlags::NONBLOCK);
let timeout = self.options.lock().send_timeout;
let ret = match &self.inner {
match &self.inner {
UnixSocketInner::Stream(stream) => {
stream.sendto(&task.wait_cx(), timeout, buf, is_nonblocking, addr)
}
UnixSocketInner::Datagram(datagram) => {
datagram.sendto(task, timeout, buf, is_nonblocking, addr)
}
};
if let Err(Errno::EPIPE) = ret
&& !flags.contains(SendFlags::NOSIGNAL)
{
// TODO: send SIGPIPE signal
unimplemented!("send SIGPIPE on EPIPE");
}
ret
}

pub(super) fn recvfrom(
Expand Down
Loading