Skip to content

Commit

Permalink
Merge branch 'master' into new-st
Browse files Browse the repository at this point in the history
  • Loading branch information
panantoni01 committed Jan 9, 2024
2 parents f9ff401 + 71ac66a commit 4060a10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/libc/sys/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <errno.h>
#include <signal.h>

int pselect(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timespec *timeout,
const sigset_t *sigmask) {
int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
fd_set *restrict exceptfds, const struct timespec *restrict timeout,
const sigset_t *restrict sigmask) {
int kq;
int ret;
struct kevent *events;
Expand All @@ -21,10 +21,15 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds,
return -1;
}

kq = kqueue1(O_CLOEXEC);
if (kq < 0)
if (sigmask && sigprocmask(SIG_SETMASK, sigmask, &sigs))
return -1;

kq = kqueue1(O_CLOEXEC);
if (kq < 0) {
ret = -1;
goto restore_sigs;
}

events = malloc(2 * nfds * sizeof(struct kevent));
if (!events) {
errno = ENOMEM;
Expand All @@ -44,9 +49,6 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds,
if (writefds != NULL)
FD_ZERO(writefds);

if (sigmask && sigprocmask(SIG_SETMASK, sigmask, &sigs))
return -1;

ret = kevent(kq, events, nevents, events, nevents, timeout);
if (ret == -1)
goto end;
Expand All @@ -65,10 +67,11 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds,

end:
free(events);
if (sigmask && sigprocmask(SIG_SETMASK, &sigs, NULL))
ret = -1;
close_kq:
close(kq);
restore_sigs:
if (sigmask && sigprocmask(SIG_SETMASK, &sigs, NULL))
ret = -1;
return ret;
}

Expand Down
5 changes: 5 additions & 0 deletions sys/kern/vm_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ static int cow_page_fault(vm_map_t *map, vm_map_entry_t *ent, size_t off,
if (old == NULL)
return 0;

/* This check is safe. We are the only owner of this anon and the ref count
* will not change because we are under vm_map:mtx. */
if (old->ref_cnt == 1)
return 0;

/* Current mapping will be replaced with new one so remove it from pmap. */
vaddr_t fault_page = off * PAGESIZE + ent->start;
pmap_remove(map->pmap, fault_page, fault_page + PAGESIZE);
Expand Down

0 comments on commit 4060a10

Please sign in to comment.