sync code with last improvements from OpenBSD

This commit is contained in:
purplerain 2023-09-28 08:40:30 +00:00
parent 4de47ea988
commit f463301edc
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
142 changed files with 4045 additions and 1295 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: kern_clockintr.c,v 1.56 2023/09/17 15:24:35 cheloha Exp $ */
/* $OpenBSD: kern_clockintr.c,v 1.58 2023/09/25 00:29:31 cheloha Exp $ */
/*
* Copyright (c) 2003 Dale Rahn <drahn@openbsd.org>
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@ -455,7 +455,6 @@ clockqueue_pend_delete(struct clockintr_queue *cq, struct clockintr *cl)
CLR(cl->cl_flags, CLST_PENDING);
}
void
clockqueue_pend_insert(struct clockintr_queue *cq, struct clockintr *cl,
uint64_t expiration)
@ -577,12 +576,14 @@ db_show_all_clockintr(db_expr_t addr, int haddr, db_expr_t count, char *modif)
struct timespec now;
struct cpu_info *ci;
CPU_INFO_ITERATOR cii;
int width = sizeof(long) * 2 + 2; /* +2 for "0x" prefix */
nanouptime(&now);
db_printf("%20s\n", "UPTIME");
db_printf("%10lld.%09ld\n", now.tv_sec, now.tv_nsec);
db_printf("\n");
db_printf("%20s %5s %3s %s\n", "EXPIRATION", "STATE", "CPU", "NAME");
db_printf("%20s %5s %3s %*s %s\n",
"EXPIRATION", "STATE", "CPU", width, "ARG", "NAME");
CPU_INFO_FOREACH(cii, ci) {
if (ISSET(ci->ci_queue.cq_flags, CQ_INIT))
db_show_clockintr_cpu(ci);
@ -612,13 +613,15 @@ db_show_clockintr(const struct clockintr *cl, const char *state, u_int cpu)
struct timespec ts;
char *name;
db_expr_t offset;
int width = sizeof(long) * 2;
NSEC_TO_TIMESPEC(cl->cl_expiration, &ts);
db_find_sym_and_offset((vaddr_t)cl->cl_func, &name, &offset);
if (name == NULL)
name = "?";
db_printf("%10lld.%09ld %5s %3u %s\n",
ts.tv_sec, ts.tv_nsec, state, cpu, name);
db_printf("%10lld.%09ld %5s %3u 0x%0*lx %s\n",
ts.tv_sec, ts.tv_nsec, state, cpu,
width, (unsigned long)cl->cl_arg, name);
}
#endif /* DDB */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: kern_exit.c,v 1.215 2023/09/13 14:25:49 claudio Exp $ */
/* $OpenBSD: kern_exit.c,v 1.216 2023/09/21 13:49:25 claudio Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@ -165,8 +165,6 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
/* main thread gotta wait because it has the pid, et al */
while (pr->ps_threadcnt > 1)
tsleep_nsec(&pr->ps_threads, PWAIT, "thrdeath", INFSLP);
if (pr->ps_flags & PS_PROFIL)
stopprofclock(pr);
}
rup = pr->ps_ru;
@ -190,6 +188,9 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
#endif
if ((p->p_flag & P_THREAD) == 0) {
if (pr->ps_flags & PS_PROFIL)
stopprofclock(pr);
sigio_freelist(&pr->ps_sigiolst);
/* close open files and release open-file table */
@ -224,6 +225,15 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
p->p_fd = NULL; /* zap the thread's copy */
/* Release the thread's read reference of resource limit structure. */
if (p->p_limit != NULL) {
struct plimit *limit;
limit = p->p_limit;
p->p_limit = NULL;
lim_free(limit);
}
/*
* Remove proc from pidhash chain and allproc so looking
* it up won't work. We will put the proc on the
@ -342,15 +352,6 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
KASSERT(pr->ps_threadcnt > 0);
}
/* Release the thread's read reference of resource limit structure. */
if (p->p_limit != NULL) {
struct plimit *limit;
limit = p->p_limit;
p->p_limit = NULL;
lim_free(limit);
}
/*
* Other substructures are freed from reaper and wait().
*/

View file

@ -1,4 +1,4 @@
/* $OpenBSD: subr_log.c,v 1.77 2023/07/14 07:07:08 claudio Exp $ */
/* $OpenBSD: subr_log.c,v 1.78 2023/09/22 20:03:05 mvs Exp $ */
/* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */
/*
@ -50,6 +50,7 @@
#include <sys/filedesc.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/event.h>
#include <sys/fcntl.h>
#include <sys/mutex.h>
#include <sys/timeout.h>
@ -75,7 +76,7 @@
*/
struct logsoftc {
int sc_state; /* [L] see above for possibilities */
struct selinfo sc_selp; /* process waiting on select call */
struct klist sc_klist; /* process waiting on kevent call */
struct sigio_ref sc_sigio; /* async I/O registration */
int sc_need_wakeup; /* if set, wake up waiters */
struct timeout sc_tick; /* wakeup poll timeout */
@ -99,12 +100,16 @@ struct mutex log_mtx =
void filt_logrdetach(struct knote *kn);
int filt_logread(struct knote *kn, long hint);
int filt_logmodify(struct kevent *, struct knote *);
int filt_logprocess(struct knote *, struct kevent *);
const struct filterops logread_filtops = {
.f_flags = FILTEROP_ISFD,
.f_flags = FILTEROP_ISFD | FILTEROP_MPSAFE,
.f_attach = NULL,
.f_detach = filt_logrdetach,
.f_event = filt_logread,
.f_modify = filt_logmodify,
.f_process = filt_logprocess,
};
int dosendsyslog(struct proc *, const char *, size_t, int, enum uio_seg);
@ -191,11 +196,9 @@ msgbuf_getlen(struct msgbuf *mbp)
{
long len;
mtx_enter(&log_mtx);
len = mbp->msg_bufx - mbp->msg_bufr;
if (len < 0)
len += mbp->msg_bufs;
mtx_leave(&log_mtx);
return (len);
}
@ -205,6 +208,7 @@ logopen(dev_t dev, int flags, int mode, struct proc *p)
if (log_open)
return (EBUSY);
log_open = 1;
klist_init_mutex(&logsoftc.sc_klist, &log_mtx);
sigio_init(&logsoftc.sc_sigio);
timeout_set(&logsoftc.sc_tick, logtick, NULL);
timeout_add_msec(&logsoftc.sc_tick, LOG_TICK);
@ -225,6 +229,10 @@ logclose(dev_t dev, int flag, int mode, struct proc *p)
FRELE(fp, p);
log_open = 0;
timeout_del(&logsoftc.sc_tick);
klist_invalidate(&logsoftc.sc_klist);
klist_free(&logsoftc.sc_klist);
logsoftc.sc_state = 0;
sigio_free(&logsoftc.sc_sigio);
return (0);
@ -301,11 +309,10 @@ int
logkqfilter(dev_t dev, struct knote *kn)
{
struct klist *klist;
int s;
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &logsoftc.sc_selp.si_note;
klist = &logsoftc.sc_klist;
kn->kn_fop = &logread_filtops;
break;
default:
@ -313,10 +320,7 @@ logkqfilter(dev_t dev, struct knote *kn)
}
kn->kn_hook = (void *)msgbufp;
s = splhigh();
klist_insert_locked(klist, kn);
splx(s);
klist_insert(klist, kn);
return (0);
}
@ -324,11 +328,7 @@ logkqfilter(dev_t dev, struct knote *kn)
void
filt_logrdetach(struct knote *kn)
{
int s;
s = splhigh();
klist_remove_locked(&logsoftc.sc_selp.si_note, kn);
splx(s);
klist_remove(&logsoftc.sc_klist, kn);
}
int
@ -340,6 +340,30 @@ filt_logread(struct knote *kn, long hint)
return (kn->kn_data != 0);
}
int
filt_logmodify(struct kevent *kev, struct knote *kn)
{
int active;
mtx_enter(&log_mtx);
active = knote_modify(kev, kn);
mtx_leave(&log_mtx);
return (active);
}
int
filt_logprocess(struct knote *kn, struct kevent *kev)
{
int active;
mtx_enter(&log_mtx);
active = knote_process(kn, kev);
mtx_leave(&log_mtx);
return (active);
}
void
logwakeup(void)
{
@ -380,9 +404,9 @@ logtick(void *arg)
state = logsoftc.sc_state;
if (logsoftc.sc_state & LOG_RDWAIT)
logsoftc.sc_state &= ~LOG_RDWAIT;
knote_locked(&logsoftc.sc_klist, 0);
mtx_leave(&log_mtx);
selwakeup(&logsoftc.sc_selp);
if (state & LOG_ASYNC)
pgsigio(&logsoftc.sc_sigio, SIGIO, 0);
if (state & LOG_RDWAIT)
@ -401,7 +425,9 @@ logioctl(dev_t dev, u_long com, caddr_t data, int flag, struct proc *p)
/* return number of characters immediately available */
case FIONREAD:
mtx_enter(&log_mtx);
*(int *)data = (int)msgbuf_getlen(msgbufp);
mtx_leave(&log_mtx);
break;
case FIONBIO:

View file

@ -1,4 +1,4 @@
/* $OpenBSD: uipc_syscalls.c,v 1.213 2023/08/03 09:49:08 mvs Exp $ */
/* $OpenBSD: uipc_syscalls.c,v 1.214 2023/09/23 09:17:21 jan Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
@ -1214,16 +1214,12 @@ sys_setsockopt(struct proc *p, void *v, register_t *retval)
if (SCARG(uap, val)) {
m = m_get(M_WAIT, MT_SOOPTS);
if (SCARG(uap, valsize) > MLEN) {
MCLGET(m, M_DONTWAIT);
MCLGET(m, M_WAIT);
if ((m->m_flags & M_EXT) == 0) {
error = ENOBUFS;
goto bad;
}
}
if (m == NULL) {
error = ENOBUFS;
goto bad;
}
error = copyin(SCARG(uap, val), mtod(m, caddr_t),
SCARG(uap, valsize));
if (error) {