Release pledge.com 1.7 and landlockmake.com 1.3

- pledge("chown") now supported
- pledge("stdio") now allows killing self
- Write tests for pselect() and ppoll()
This commit is contained in:
Justine Tunney 2022-08-15 19:52:00 -07:00
parent 255d834f8f
commit ce588dd56b
19 changed files with 190 additions and 39 deletions

View file

@ -73,8 +73,8 @@ ssize_t sys_sendto(int, const void *, size_t, int, const void *,
uint32_t) hidden;
int32_t sys_select(int32_t, fd_set *, fd_set *, fd_set *,
struct timeval *) hidden;
int sys_pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
const sigset_t *);
int sys_pselect(int, fd_set *, fd_set *, fd_set *, struct timespec *,
const void *) hidden;
int sys_setsockopt(int, int, int, const void *, uint32_t) hidden;
int32_t sys_epoll_create(int32_t) hidden;
int32_t sys_epoll_ctl(int32_t, int32_t, int32_t, void *) hidden;

View file

@ -1,14 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_PPOLL_H_
#define COSMOPOLITAN_LIBC_SOCK_PPOLL_H_
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/timespec.h"
#include "libc/sock/struct/pollfd.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int ppoll(struct pollfd *, uint64_t, const struct timespec *,
const struct sigset *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_PPOLL_H_ */

View file

@ -29,6 +29,19 @@
/**
* Does what poll() does except with bitset API.
*
* This function is the same as saying:
*
* sigset_t old;
* sigprocmask(SIG_SETMASK, sigmask, &old);
* select(nfds, readfds, writefds, exceptfds, timeout);
* sigprocmask(SIG_SETMASK, old, 0);
*
* Except it happens atomically.
*
* The Linux Kernel modifies the timeout parameter. This wrapper gives
* it a local variable due to POSIX requiring that `timeout` be const.
* If you need that information from the Linux Kernel use sys_pselect.
*
* This system call is supported on all platforms. It's like select()
* except that it atomically changes the sigprocmask() during the op.
*/
@ -37,6 +50,11 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
int rc;
sigset_t oldmask;
struct timeval tv, *tvp;
struct timespec ts, *tsp;
struct {
sigset_t *s;
size_t n;
} ss;
if (nfds < 0) {
rc = einval();
} else if (IsAsan() &&
@ -46,6 +64,16 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
(timeout && !__asan_is_valid(timeout, sizeof(*timeout))) ||
(sigmask && !__asan_is_valid(sigmask, sizeof(*sigmask))))) {
rc = efault();
} else if (IsLinux()) {
if (timeout) {
ts = *timeout;
tsp = &ts;
} else {
tsp = 0;
}
ss.s = sigmask;
ss.n = 8;
rc = sys_pselect(nfds, readfds, writefds, exceptfds, tsp, &ss);
} else if (!IsWindows()) {
rc = sys_pselect(nfds, readfds, writefds, exceptfds, timeout, sigmask);
} else {

View file

@ -1,5 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/timespec.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -10,6 +12,8 @@ struct pollfd {
};
int poll(struct pollfd *, uint64_t, int32_t);
int ppoll(struct pollfd *, uint64_t, const struct timespec *,
const struct sigset *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -8,7 +8,7 @@ COSMOPOLITAN_C_START_
int32_t sys_poll(struct pollfd *, uint64_t, signed) hidden;
int sys_ppoll(struct pollfd *, size_t, const struct timespec *,
const sigset_t *);
const sigset_t *, size_t);
int sys_poll_metal(struct pollfd *, size_t, unsigned);
int sys_poll_nt(struct pollfd *, uint64_t, uint64_t *, const sigset_t *) hidden;