Skip to content

Commit 3012ff4

Browse files
brettwgnoliyil
authored andcommitted
[starnix] Implement epoll_pwait2().
Implements epoll_pwait2() which is the same as epoll_pwait() except it takes a timespec* for the timeout. Change-Id: Iaa6b16afe6c5b2081476f3a63a23e98ce6e905b9 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/774663 Reviewed-by: Theodore Dubois <tbodt@google.com> Commit-Queue: Brett Wilson <brettw@google.com>
1 parent b71e3ed commit 3012ff4

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

src/proc/bin/starnix/fs/syscalls.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,19 +1556,19 @@ pub fn sys_epoll_wait(
15561556
sys_epoll_pwait(current_task, epfd, events, max_events, timeout, UserRef::<sigset_t>::default())
15571557
}
15581558

1559-
pub fn sys_epoll_pwait(
1559+
// Backend for sys_epoll_pwait and sys_epoll_pwait2 that takes an already-decoded duration.
1560+
fn do_epoll_pwait(
15601561
current_task: &mut CurrentTask,
15611562
epfd: FdNumber,
15621563
events: UserRef<EpollEvent>,
15631564
max_events: i32,
1564-
timeout: i32,
1565+
timeout: zx::Duration,
15651566
user_sigmask: UserRef<sigset_t>,
15661567
) -> Result<usize, Errno> {
15671568
if max_events < 1 {
15681569
return error!(EINVAL);
15691570
}
15701571

1571-
let timeout = duration_from_poll_timeout(timeout)?;
15721572
let file = current_task.files.get(epfd)?;
15731573
let epoll_file = file.downcast_file::<EpollFileObject>().ok_or_else(|| errno!(EINVAL))?;
15741574

@@ -1590,6 +1590,35 @@ pub fn sys_epoll_pwait(
15901590
Ok(active_events.len())
15911591
}
15921592

1593+
pub fn sys_epoll_pwait(
1594+
current_task: &mut CurrentTask,
1595+
epfd: FdNumber,
1596+
events: UserRef<EpollEvent>,
1597+
max_events: i32,
1598+
timeout: i32,
1599+
user_sigmask: UserRef<sigset_t>,
1600+
) -> Result<usize, Errno> {
1601+
let timeout = duration_from_poll_timeout(timeout)?;
1602+
do_epoll_pwait(current_task, epfd, events, max_events, timeout, user_sigmask)
1603+
}
1604+
1605+
pub fn sys_epoll_pwait2(
1606+
current_task: &mut CurrentTask,
1607+
epfd: FdNumber,
1608+
events: UserRef<EpollEvent>,
1609+
max_events: i32,
1610+
user_timespec: UserRef<timespec>,
1611+
user_sigmask: UserRef<sigset_t>,
1612+
) -> Result<usize, Errno> {
1613+
let timeout = if user_timespec.is_null() {
1614+
zx::Duration::INFINITE
1615+
} else {
1616+
let ts = current_task.mm.read_object(user_timespec)?;
1617+
duration_from_timespec(ts)?
1618+
};
1619+
do_epoll_pwait(current_task, epfd, events, max_events, timeout, user_sigmask)
1620+
}
1621+
15931622
struct ReadyPollItem {
15941623
index: usize,
15951624
events: u32,

src/proc/bin/starnix/syscalls/decls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ macro_rules! for_each_syscall {
368368
pidfd_getfd,
369369
faccessat2,
370370
process_madvise,
371+
epoll_pwait2,
371372
}
372373
}
373374
}

src/proc/bin/starnix/syscalls/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub fn dispatch_syscall(
7979
epoll_create[1],
8080
epoll_ctl[4],
8181
epoll_pwait[5],
82+
epoll_pwait2[5],
8283
epoll_wait[4],
8384
eventfd2[2],
8485
eventfd[1],

src/proc/tests/android/gvisor/meta/epoll_test.cml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
include: [ "//src/proc/tests/android/gvisor/meta/gvisor.shard.cml" ],
66
program: {
77
binary: "data/tests/epoll_test",
8-
args: [ "--gunit_filter=-*.EpollPwait2Timeout:*.DoubleEpollOneShot:*.CloseFile:*.DoubleLayerEpoll" ],
8+
args: [ "--gunit_filter=-*.DoubleEpollOneShot:*.CloseFile:*.DoubleLayerEpoll" ],
99
},
1010
}

0 commit comments

Comments
 (0)