summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2016-11-07 00:26:34 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2016-11-07 00:26:34 +0000
commitbd87d530432bb59e0e8e9945eb3552c2580af213 (patch)
tree094ceb36ef2db9352c5687de586c5176477f3c21 /sys
parent174c1a4b3e7ca128b5540d3419d42f4d056e96af (diff)
Split PID from TID, giving processes a PID unrelated to the TID of their
initial thread ok jsing@ kettenis@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/sparc64/sparc64/db_interface.c10
-rw-r--r--sys/dev/pci/drm/drm_irq.c4
-rw-r--r--sys/dev/wscons/wsdisplay.c4
-rw-r--r--sys/kern/exec_elf.c4
-rw-r--r--sys/kern/init_main.c5
-rw-r--r--sys/kern/kern_exit.c20
-rw-r--r--sys/kern/kern_fork.c38
-rw-r--r--sys/kern/kern_kthread.c4
-rw-r--r--sys/kern/kern_ktrace.c4
-rw-r--r--sys/kern/kern_proc.c31
-rw-r--r--sys/kern/kern_prot.c4
-rw-r--r--sys/kern/kern_sysctl.c5
-rw-r--r--sys/kern/sys_generic.c18
-rw-r--r--sys/kern/sys_process.c24
-rw-r--r--sys/kern/vfs_lockf.c6
-rw-r--r--sys/sys/proc.h26
-rw-r--r--sys/sys/selinfo.h4
-rw-r--r--sys/sys/sysctl.h8
-rw-r--r--sys/ufs/ffs/ffs_softdep.c14
-rw-r--r--sys/ufs/mfs/mfs_vfsops.c4
-rw-r--r--sys/ufs/mfs/mfs_vnops.c6
-rw-r--r--sys/ufs/mfs/mfsnode.h4
-rw-r--r--sys/uvm/uvm_map.c4
-rw-r--r--sys/uvm/uvm_page.c8
-rw-r--r--sys/uvm/uvm_page.h4
25 files changed, 150 insertions, 113 deletions
diff --git a/sys/arch/sparc64/sparc64/db_interface.c b/sys/arch/sparc64/sparc64/db_interface.c
index 039da18b58e..eb84bb99838 100644
--- a/sys/arch/sparc64/sparc64/db_interface.c
+++ b/sys/arch/sparc64/sparc64/db_interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_interface.c,v 1.46 2016/10/18 00:43:57 guenther Exp $ */
+/* $OpenBSD: db_interface.c,v 1.47 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: db_interface.c,v 1.61 2001/07/31 06:55:47 eeh Exp $ */
/*
@@ -1062,23 +1062,23 @@ db_setpcb(addr, have_addr, count, modif)
struct proc *p;
if (!have_addr) {
- db_printf("What PID do you want to map in?\n");
+ db_printf("What TID do you want to map in?\n");
return;
}
LIST_FOREACH(p, &allproc, p_list) {
- if (p->p_stat && p->p_pid == addr) {
+ if (p->p_stat && p->p_tid == addr) {
curproc = p;
curpcb = (struct pcb*)p->p_addr;
if (p->p_vmspace->vm_map.pmap->pm_ctx) {
switchtoctx(p->p_vmspace->vm_map.pmap->pm_ctx);
return;
}
- db_printf("PID %ld has a null context.\n", addr);
+ db_printf("TID %ld has a null context.\n", addr);
return;
}
}
- db_printf("PID %ld not found.\n", addr);
+ db_printf("TID %ld not found.\n", addr);
}
diff --git a/sys/dev/pci/drm/drm_irq.c b/sys/dev/pci/drm/drm_irq.c
index e8b4fbcc025..1f15e48cdeb 100644
--- a/sys/dev/pci/drm/drm_irq.c
+++ b/sys/dev/pci/drm/drm_irq.c
@@ -1111,7 +1111,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
}
e->pipe = pipe;
- e->base.pid = curproc->p_pid;
+ e->base.pid = curproc->p_tid; /* XXX */
e->event.base.type = DRM_EVENT_VBLANK;
e->event.base.length = sizeof e->event;
e->event.user_data = vblwait->request.signal;
@@ -1138,7 +1138,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
DRM_DEBUG("event on vblank count %d, current %d, crtc %d\n",
vblwait->request.sequence, seq, pipe);
- trace_drm_vblank_event_queued(curproc->p_pid, pipe,
+ trace_drm_vblank_event_queued(curproc->p_tid, pipe,
vblwait->request.sequence);
e->event.sequence = vblwait->request.sequence;
diff --git a/sys/dev/wscons/wsdisplay.c b/sys/dev/wscons/wsdisplay.c
index 3169c0aacfd..131c511fc79 100644
--- a/sys/dev/wscons/wsdisplay.c
+++ b/sys/dev/wscons/wsdisplay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsdisplay.c,v 1.124 2015/09/08 11:13:20 deraadt Exp $ */
+/* $OpenBSD: wsdisplay.c,v 1.125 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: wsdisplay.c,v 1.82 2005/02/27 00:27:52 perry Exp $ */
/*
@@ -1426,7 +1426,7 @@ wsdisplaystart(struct tty *tp)
splx(s);
return;
}
- if (tp->t_outq.c_cc == 0 && tp->t_wsel.si_selpid == 0)
+ if (tp->t_outq.c_cc == 0 && tp->t_wsel.si_seltid == 0)
goto low;
if ((scr = sc->sc_scr[WSDISPLAYSCREEN(tp->t_dev)]) == NULL) {
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c
index 87c850ffeef..d51aecd0669 100644
--- a/sys/kern/exec_elf.c
+++ b/sys/kern/exec_elf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_elf.c,v 1.128 2016/10/05 02:31:52 guenther Exp $ */
+/* $OpenBSD: exec_elf.c,v 1.129 2016/11/07 00:26:32 guenther Exp $ */
/*
* Copyright (c) 1996 Per Fogelstrom
@@ -1335,7 +1335,7 @@ ELFNAMEEND(coredump_note)(struct proc *p, void *iocookie, size_t *sizep)
size = 0;
snprintf(name, sizeof(name)-ELFROUNDSIZE, "%s@%d",
- "OpenBSD", p->p_pid);
+ "OpenBSD", p->p_tid + THREAD_PID_OFFSET);
namesize = strlen(name) + 1;
memset(name + namesize, 0, elfround(namesize) - namesize);
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 90cdd985516..47408b45081 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.261 2016/10/24 04:38:44 dlg Exp $ */
+/* $OpenBSD: init_main.c,v 1.262 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -272,6 +272,7 @@ main(void *framep)
process_initialize(pr, p);
LIST_INSERT_HEAD(&allprocess, pr, ps_list);
+ LIST_INSERT_HEAD(PIDHASH(0), pr, ps_hash);
atomic_setbits_int(&pr->ps_flags, PS_SYSTEM);
/* Set the default routing table/domain. */
@@ -279,7 +280,7 @@ main(void *framep)
LIST_INSERT_HEAD(&allproc, p, p_list);
pr->ps_pgrp = &pgrp0;
- LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
+ LIST_INSERT_HEAD(TIDHASH(0), p, p_hash);
LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
LIST_INIT(&pgrp0.pg_members);
LIST_INSERT_HEAD(&pgrp0.pg_members, pr, ps_pglist);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 54eba67f026..5d0f0915fad 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exit.c,v 1.157 2016/04/25 20:00:33 tedu Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.158 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@@ -265,6 +265,7 @@ exit1(struct proc *p, int rv, int flags)
LIST_REMOVE(p, p_list);
if ((p->p_flag & P_THREAD) == 0) {
+ LIST_REMOVE(pr, ps_hash);
LIST_REMOVE(pr, ps_list);
if ((pr->ps_flags & PS_NOZOMBIE) == 0)
@@ -275,7 +276,7 @@ exit1(struct proc *p, int rv, int flags)
* the lists scanned by ispidtaken(), so block
* fast reuse of the pid now.
*/
- freepid(p->p_pid);
+ freepid(pr->ps_pid);
}
/*
@@ -515,16 +516,17 @@ dowait4(struct proc *q, pid_t pid, int *statusp, int options,
loop:
nfound = 0;
LIST_FOREACH(pr, &q->p_p->ps_children, ps_sibling) {
- p = pr->ps_mainproc;
if ((pr->ps_flags & PS_NOZOMBIE) ||
(pid != WAIT_ANY &&
- p->p_pid != pid &&
+ pr->ps_pid != pid &&
pr->ps_pgid != -pid))
continue;
+ p = pr->ps_mainproc;
+
nfound++;
if (pr->ps_flags & PS_ZOMBIE) {
- retval[0] = p->p_pid;
+ retval[0] = pr->ps_pid;
if (statusp != NULL)
*statusp = p->p_xstat; /* convert to int */
@@ -540,7 +542,7 @@ loop:
single_thread_wait(pr);
atomic_setbits_int(&pr->ps_flags, PS_WAITED);
- retval[0] = p->p_pid;
+ retval[0] = pr->ps_pid;
if (statusp != NULL)
*statusp = W_STOPCODE(pr->ps_single->p_xstat);
@@ -554,7 +556,7 @@ loop:
(pr->ps_flags & PS_TRACED ||
options & WUNTRACED)) {
atomic_setbits_int(&pr->ps_flags, PS_WAITED);
- retval[0] = p->p_pid;
+ retval[0] = pr->ps_pid;
if (statusp != NULL)
*statusp = W_STOPCODE(p->p_xstat);
@@ -564,7 +566,7 @@ loop:
}
if ((options & WCONTINUED) && (p->p_flag & P_CONTINUED)) {
atomic_clearbits_int(&p->p_flag, P_CONTINUED);
- retval[0] = p->p_pid;
+ retval[0] = pr->ps_pid;
if (statusp != NULL)
*statusp = _WCONTINUED;
@@ -607,7 +609,7 @@ proc_finish_wait(struct proc *waiter, struct proc *p)
rup = &waiter->p_p->ps_cru;
ruadd(rup, pr->ps_ru);
LIST_REMOVE(pr, ps_list); /* off zombprocess */
- freepid(p->p_pid);
+ freepid(pr->ps_pid);
process_zap(pr);
}
}
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 5e8fde114b4..9a82d5bbe56 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.191 2016/10/22 02:55:36 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.192 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -76,7 +76,9 @@ struct forkstat forkstat;
void fork_return(void *);
void tfork_child_return(void *);
-int pidtaken(pid_t);
+pid_t alloctid(void);
+pid_t allocpid(void);
+int ispidtaken(pid_t);
void process_new(struct proc *, struct process *, int);
@@ -191,6 +193,7 @@ process_new(struct proc *p, struct process *parent, int flags)
(caddr_t)&pr->ps_endcopy - (caddr_t)&pr->ps_startcopy);
process_initialize(pr, p);
+ pr->ps_pid = allocpid();
/* post-copy fixups */
pr->ps_pptr = parent;
@@ -428,11 +431,12 @@ fork1(struct proc *curp, int flags, void *stack, pid_t *tidptr,
if (pr->ps_flags & PS_TRACED && flags & FORK_FORK)
newptstat = malloc(sizeof(*newptstat), M_SUBPROC, M_WAITOK);
- p->p_pid = allocpid();
+ p->p_tid = alloctid();
LIST_INSERT_HEAD(&allproc, p, p_list);
- LIST_INSERT_HEAD(PIDHASH(p->p_pid), p, p_hash);
+ LIST_INSERT_HEAD(TIDHASH(p->p_tid), p, p_hash);
if ((flags & FORK_THREAD) == 0) {
+ LIST_INSERT_HEAD(PIDHASH(pr->ps_pid), pr, ps_hash);
LIST_INSERT_AFTER(curpr, pr, ps_pglist);
LIST_INSERT_HEAD(&curpr->ps_children, pr, ps_sibling);
@@ -466,9 +470,9 @@ fork1(struct proc *curp, int flags, void *stack, pid_t *tidptr,
}
if (tidptr != NULL) {
- pid_t pid = p->p_pid + THREAD_PID_OFFSET;
+ pid_t tid = p->p_tid + THREAD_PID_OFFSET;
- if (copyout(&pid, tidptr, sizeof(pid)))
+ if (copyout(&tid, tidptr, sizeof(tid)))
psignal(curp, SIGSEGV);
}
@@ -500,7 +504,7 @@ fork1(struct proc *curp, int flags, void *stack, pid_t *tidptr,
* Notify any interested parties about the new process.
*/
if ((flags & FORK_THREAD) == 0)
- KNOTE(&curpr->ps_klist, NOTE_FORK | p->p_pid);
+ KNOTE(&curpr->ps_klist, NOTE_FORK | pr->ps_pid);
/*
* Update stats now that we know the fork was successful.
@@ -539,13 +543,27 @@ fork1(struct proc *curp, int flags, void *stack, pid_t *tidptr,
* marking us as parent via retval[1].
*/
if (retval != NULL) {
- retval[0] = p->p_pid +
- (flags & FORK_THREAD ? THREAD_PID_OFFSET : 0);
+ retval[0] = (flags & FORK_THREAD) == 0 ? pr->ps_pid :
+ (p->p_tid + THREAD_PID_OFFSET);
retval[1] = 0;
}
return (0);
}
+/* Find an unused tid */
+pid_t
+alloctid(void)
+{
+ pid_t tid;
+
+ do {
+ /* (0 .. TID_MASK+1] */
+ tid = 1 + (arc4random() & TID_MASK);
+ } while (pfind(tid) != NULL);
+
+ return (tid);
+}
+
/*
* Checks for current use of a pid, either as a pid or pgid.
*/
@@ -559,7 +577,7 @@ ispidtaken(pid_t pid)
if (pid == oldpids[i])
return (1);
- if (pfind(pid) != NULL)
+ if (prfind(pid) != NULL)
return (1);
if (pgfind(pid) != NULL)
return (1);
diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c
index 7b8ea85bbba..7b25abb16b7 100644
--- a/sys/kern/kern_kthread.c
+++ b/sys/kern/kern_kthread.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_kthread.c,v 1.38 2015/03/14 03:38:50 jsg Exp $ */
+/* $OpenBSD: kern_kthread.c,v 1.39 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: kern_kthread.c,v 1.3 1998/12/22 21:21:36 kleink Exp $ */
/*-
@@ -94,7 +94,7 @@ kthread_exit(int ecode)
*/
if (ecode != 0)
printf("WARNING: thread `%s' (%d) exits with status %d\n",
- curproc->p_comm, curproc->p_pid, ecode);
+ curproc->p_comm, curproc->p_tid, ecode);
exit1(curproc, W_EXITCODE(ecode, 0), EXIT_NORMAL);
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index 97c1074334a..2ba5dc967db 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_ktrace.c,v 1.88 2016/03/19 12:04:15 natano Exp $ */
+/* $OpenBSD: kern_ktrace.c,v 1.89 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */
/*
@@ -136,7 +136,7 @@ void
ktrinitheader(struct ktr_header *kth, struct proc *p, int type)
{
ktrinitheaderraw(kth, type, p->p_p->ps_pid,
- p->p_pid + THREAD_PID_OFFSET);
+ p->p_tid + THREAD_PID_OFFSET);
memcpy(kth->ktr_comm, p->p_comm, MAXCOMLEN);
}
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 51a428d2af8..c84276b4e1c 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_proc.c,v 1.70 2016/09/15 02:00:16 dlg Exp $ */
+/* $OpenBSD: kern_proc.c,v 1.71 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */
/*
@@ -56,6 +56,8 @@ u_long uihash; /* size of hash table - 1 */
/*
* Other process lists
*/
+struct tidhashhead *tidhashtbl;
+u_long tidhash;
struct pidhashhead *pidhashtbl;
u_long pidhash;
struct pgrphashhead *pgrphashtbl;
@@ -87,10 +89,11 @@ procinit(void)
LIST_INIT(&allproc);
- pidhashtbl = hashinit(maxthread / 4, M_PROC, M_NOWAIT, &pidhash);
+ tidhashtbl = hashinit(maxthread / 4, M_PROC, M_NOWAIT, &tidhash);
+ pidhashtbl = hashinit(maxprocess / 4, M_PROC, M_NOWAIT, &pidhash);
pgrphashtbl = hashinit(maxprocess / 4, M_PROC, M_NOWAIT, &pgrphash);
uihashtbl = hashinit(maxprocess / 16, M_PROC, M_NOWAIT, &uihash);
- if (!pidhashtbl || !pgrphashtbl || !uihashtbl)
+ if (!tidhashtbl || !pidhashtbl || !pgrphashtbl || !uihashtbl)
panic("procinit: malloc");
pool_init(&proc_pool, sizeof(struct proc), 0, IPL_NONE,
@@ -166,12 +169,12 @@ inferior(struct process *pr, struct process *parent)
* Locate a proc (thread) by number
*/
struct proc *
-pfind(pid_t pid)
+pfind(pid_t tid)
{
struct proc *p;
- LIST_FOREACH(p, PIDHASH(pid), p_hash)
- if (p->p_pid == pid)
+ LIST_FOREACH(p, TIDHASH(tid), p_hash)
+ if (p->p_tid == tid)
return (p);
return (NULL);
}
@@ -182,11 +185,11 @@ pfind(pid_t pid)
struct process *
prfind(pid_t pid)
{
- struct proc *p;
+ struct process *pr;
- LIST_FOREACH(p, PIDHASH(pid), p_hash)
- if (p->p_pid == pid)
- return (p->p_flag & P_THREAD ? NULL : p->p_p);
+ LIST_FOREACH(pr, PIDHASH(pid), ps_hash)
+ if (pr->ps_pid == pid)
+ return (pr);
return (NULL);
}
@@ -213,7 +216,7 @@ zombiefind(pid_t pid)
struct process *pr;
LIST_FOREACH(pr, &zombprocess, ps_list)
- if (pr->ps_mainproc->p_pid == pid)
+ if (pr->ps_pid == pid)
return (pr);
return (NULL);
}
@@ -418,7 +421,7 @@ proc_printit(struct proc *p, const char *modif,
else
pst = pstat[(int)p->p_stat - 1];
- (*pr)("PROC (%s) pid=%d stat=%s\n", p->p_comm, p->p_pid, pst);
+ (*pr)("PROC (%s) tid=%d stat=%s\n", p->p_comm, p->p_tid, pst);
(*pr)(" flags process=%b proc=%b\n",
p->p_p->ps_flags, PS_BITS, p->p_flag, P_BITS);
(*pr)(" pri=%u, usrpri=%u, nice=%d\n",
@@ -468,7 +471,7 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
"COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
break;
case 'n':
- db_printf(" TID %5s %5s %5s S %10s %-12s %-16s\n",
+ db_printf(" PID %5s %5s %5s S %10s %-12s %-16s\n",
"PPID", "PGRP", "UID", "FLAGS", "WAIT", "COMMAND");
break;
case 'w':
@@ -495,7 +498,7 @@ db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
continue;
}
db_printf("%c%5d ", p == curproc ? '*' : ' ',
- p->p_pid);
+ *mode == 'n' ? pr->ps_pid : p->p_tid);
switch (*mode) {
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index ec9322bc426..9fae1d747c6 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_prot.c,v 1.66 2016/09/02 18:11:28 tedu Exp $ */
+/* $OpenBSD: kern_prot.c,v 1.67 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
/*
@@ -78,7 +78,7 @@ int
sys_getthrid(struct proc *p, void *v, register_t *retval)
{
- *retval = p->p_pid + THREAD_PID_OFFSET;
+ *retval = p->p_tid + THREAD_PID_OFFSET;
return (0);
}
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 294b28b095c..27b53c83382 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.318 2016/10/24 04:38:44 dlg Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.319 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -1588,7 +1588,6 @@ fill_kproc(struct process *pr, struct kinfo_proc *ki, struct proc *p,
show_pointers);
/* stuff that's too painful to generalize into the macros */
- ki->p_pid = pr->ps_pid;
if (pr->ps_pptr)
ki->p_ppid = pr->ps_pptr->ps_pid;
if (s->s_leader)
@@ -1986,7 +1985,7 @@ sysctl_proc_vmmap(int *name, u_int namelen, void *oldp, size_t *oldlenp,
}
pid = name[0];
- if (pid == cp->p_pid) {
+ if (pid == cp->p_p->ps_pid) {
/* Self process mapping. */
findpr = cp->p_p;
} else if (pid > 0) {
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index a2c2f3fb72f..cf08a3022be 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_generic.c,v 1.112 2016/07/05 00:35:09 tedu Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.113 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
@@ -778,16 +778,16 @@ void
selrecord(struct proc *selector, struct selinfo *sip)
{
struct proc *p;
- pid_t mypid;
+ pid_t mytid;
- mypid = selector->p_pid;
- if (sip->si_selpid == mypid)
+ mytid = selector->p_tid;
+ if (sip->si_seltid == mytid)
return;
- if (sip->si_selpid && (p = pfind(sip->si_selpid)) &&
+ if (sip->si_seltid && (p = pfind(sip->si_seltid)) &&
p->p_wchan == (caddr_t)&selwait)
sip->si_flags |= SI_COLL;
else
- sip->si_selpid = mypid;
+ sip->si_seltid = mytid;
}
/*
@@ -800,15 +800,15 @@ selwakeup(struct selinfo *sip)
int s;
KNOTE(&sip->si_note, 0);
- if (sip->si_selpid == 0)
+ if (sip->si_seltid == 0)
return;
if (sip->si_flags & SI_COLL) {
nselcoll++;
sip->si_flags &= ~SI_COLL;
wakeup(&selwait);
}
- p = pfind(sip->si_selpid);
- sip->si_selpid = 0;
+ p = pfind(sip->si_seltid);
+ sip->si_seltid = 0;
if (p != NULL) {
SCHED_LOCK(s);
if (p->p_wchan == (caddr_t)&selwait) {
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index b295908c122..7c7b261cba3 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_process.c,v 1.73 2016/10/19 08:31:33 guenther Exp $ */
+/* $OpenBSD: sys_process.c,v 1.74 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */
/*-
@@ -109,6 +109,7 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
switch (req) {
case PT_TRACE_ME:
t = p;
+ tr = t->p_p;
break;
/* calls that only operate on the PID */
@@ -124,20 +125,22 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
case PT_GET_PROCESS_STATE:
case PT_GET_THREAD_FIRST:
case PT_GET_THREAD_NEXT:
+ case PT_DETACH:
default:
/* Find the process we're supposed to be operating on. */
- if ((t = pfind(SCARG(uap, pid))) == NULL)
- return (ESRCH);
- if (t->p_flag & P_THREAD)
+ if ((tr = prfind(SCARG(uap, pid))) == NULL)
return (ESRCH);
+ t = tr->ps_mainproc; /* XXX */
break;
/* calls that accept a PID or a thread ID */
case PT_CONTINUE:
- case PT_DETACH:
#ifdef PT_STEP
case PT_STEP:
#endif
+#ifdef PT_WCOOKIE
+ case PT_WCOOKIE:
+#endif
case PT_GETREGS:
case PT_SETREGS:
#ifdef PT_GETFPREGS
@@ -156,15 +159,14 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
t = pfind(SCARG(uap, pid) - THREAD_PID_OFFSET);
if (t == NULL)
return (ESRCH);
+ tr = t->p_p;
} else {
- if ((t = pfind(SCARG(uap, pid))) == NULL)
- return (ESRCH);
- if (t->p_flag & P_THREAD)
+ if ((tr = prfind(SCARG(uap, pid))) == NULL)
return (ESRCH);
+ t = tr->ps_mainproc; /* XXX */
}
break;
}
- tr = t->p_p;
if ((tr->ps_flags & PS_INEXEC) != 0)
return (EAGAIN);
@@ -327,7 +329,7 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
if (t == NULL)
pts.pts_tid = -1;
else
- pts.pts_tid = t->p_pid + THREAD_PID_OFFSET;
+ pts.pts_tid = t->p_tid + THREAD_PID_OFFSET;
return (copyout(&pts, SCARG(uap, addr), sizeof(pts)));
default: /* It was not a legal request. */
@@ -571,7 +573,7 @@ sys_ptrace(struct proc *p, void *v, register_t *retval)
if (tr->ps_single)
tr->ps_ptstat->pe_tid =
- tr->ps_single->p_pid + THREAD_PID_OFFSET;
+ tr->ps_single->p_tid + THREAD_PID_OFFSET;
return (copyout(tr->ps_ptstat, SCARG(uap, addr),
sizeof(*tr->ps_ptstat)));
diff --git a/sys/kern/vfs_lockf.c b/sys/kern/vfs_lockf.c
index 6ced82196a4..019090005be 100644
--- a/sys/kern/vfs_lockf.c
+++ b/sys/kern/vfs_lockf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_lockf.c,v 1.23 2016/09/15 02:00:16 dlg Exp $ */
+/* $OpenBSD: vfs_lockf.c,v 1.24 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: vfs_lockf.c,v 1.7 1996/02/04 02:18:21 christos Exp $ */
/*
@@ -693,7 +693,7 @@ lf_print(char *tag, struct lockf *lock)
printf("%s: lock %p for ", tag, lock);
if (lock->lf_flags & F_POSIX)
- printf("proc %d", ((struct proc *)(lock->lf_id))->p_pid);
+ printf("thread %d", ((struct proc *)(lock->lf_id))->p_tid);
else
printf("id %p", lock->lf_id);
printf(" %s, start %llx, end %llx",
@@ -719,7 +719,7 @@ lf_printlist(char *tag, struct lockf *lock)
for (lf = *lock->lf_head; lf; lf = lf->lf_next) {
printf("\tlock %p for ", lf);
if (lf->lf_flags & F_POSIX)
- printf("proc %d", ((struct proc*)(lf->lf_id))->p_pid);
+ printf("thread %d", ((struct proc*)(lf->lf_id))->p_tid);
else
printf("id %p", lf->lf_id);
printf(" %s, start %llx, end %llx",
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 13669b469ea..6227ed78de1 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.226 2016/09/03 08:47:24 tedu Exp $ */
+/* $OpenBSD: proc.h,v 1.227 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -168,11 +168,13 @@ struct process {
struct process *ps_pptr; /* Pointer to parent process. */
LIST_ENTRY(process) ps_sibling; /* List of sibling processes. */
LIST_HEAD(, process) ps_children;/* Pointer to list of children. */
+ LIST_ENTRY(process) ps_hash; /* Hash chain. */
struct sigacts *ps_sigacts; /* Signal actions, state */
struct vnode *ps_textvp; /* Vnode of executable. */
struct filedesc *ps_fd; /* Ptr to open files structure */
struct vmspace *ps_vmspace; /* Address space */
+ pid_t ps_pid; /* Process identifier. */
/* The following fields are all zeroed upon creation in process_new. */
#define ps_startzero ps_klist
@@ -236,7 +238,6 @@ struct process {
struct timeout ps_realit_to; /* real-time itimer trampoline. */
};
-#define ps_pid ps_mainproc->p_pid
#define ps_session ps_pgrp->pg_session
#define ps_pgid ps_pgrp->pg_id
@@ -294,7 +295,7 @@ struct proc {
char p_pad1[1];
u_char p_descfd; /* if not 255, fdesc permits this fd */
- pid_t p_pid; /* Process identifier. */
+ pid_t p_tid; /* Thread identifier. */
LIST_ENTRY(proc) p_hash; /* Hash chain. */
/* The following fields are all zeroed upon creation in fork. */
@@ -403,7 +404,7 @@ struct proc {
"\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\027XX" \
"\030CONTINUED" "\033THREAD" "\034SUSPSIG" "\035SOFTDEP" "\037CPUPEG")
-#define THREAD_PID_OFFSET 1000000
+#define THREAD_PID_OFFSET 100000
#ifdef _KERNEL
@@ -420,8 +421,15 @@ struct uidinfo *uid_find(uid_t);
* We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
* as it is used to represent "no process group".
* We set PID_MAX to 99999 to keep it in 5 columns in ps
+ * When exposed to userspace, thread IDs have THREAD_PID_OFFSET
+ * added to keep them from overlapping the PID range. For them,
+ * we use a * a (0 .. 2^n] range for cheapness, picking 'n' such
+ * that 2^n + THREAD_PID_OFFSET and THREAD_PID_OFFSET have
+ * the same number of columns when printed.
*/
-#define PID_MAX 99999
+#define PID_MAX 99999
+#define TID_MASK 0x7ffff
+
#define NO_PID (PID_MAX+1)
#define SESS_LEADER(pr) ((pr)->ps_session->s_leader == (pr))
@@ -453,8 +461,12 @@ struct uidinfo *uid_find(uid_t);
#define EXIT_THREAD 0x00000002
#define EXIT_THREAD_NOCHECK 0x00000003
+#define TIDHASH(tid) (&tidhashtbl[(tid) & tidhash])
+extern LIST_HEAD(tidhashhead, proc) *tidhashtbl;
+extern u_long tidhash;
+
#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
-extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
+extern LIST_HEAD(pidhashhead, process) *pidhashtbl;
extern u_long pidhash;
#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
@@ -484,8 +496,6 @@ extern struct pool ucred_pool; /* memory pool for ucreds */
extern struct pool session_pool; /* memory pool for sessions */
extern struct pool pgrp_pool; /* memory pool for pgrps */
-int ispidtaken(pid_t);
-pid_t allocpid(void);
void freepid(pid_t);
struct process *prfind(pid_t); /* Find process by id. */
diff --git a/sys/sys/selinfo.h b/sys/sys/selinfo.h
index b65a98db301..8235c8c0944 100644
--- a/sys/sys/selinfo.h
+++ b/sys/sys/selinfo.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: selinfo.h,v 1.3 2007/07/25 23:11:53 art Exp $ */
+/* $OpenBSD: selinfo.h,v 1.4 2016/11/07 00:26:32 guenther Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
* notified when I/O becomes possible.
*/
struct selinfo {
- pid_t si_selpid; /* process to be notified */
+ pid_t si_seltid; /* thread to be notified */
struct klist si_note; /* kernel note list */
short si_flags; /* see below */
};
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 53137675420..b701311df72 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.h,v 1.169 2016/10/07 19:04:44 tedu Exp $ */
+/* $OpenBSD: sysctl.h,v 1.170 2016/11/07 00:26:32 guenther Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
@@ -494,12 +494,13 @@ struct kinfo_vmentry {
* uc - source struct ucreds
* pg - source struct pgrp
* paddr - kernel address of the source struct proc
+ * praddr - kernel address of the source struct process
* sess - source struct session
* vm - source struct vmspace
* lim - source struct plimits
* sa - source struct sigacts
* There are some members that are not handled by these macros
- * because they're too painful to generalize: p_pid, p_ppid, p_sid, p_tdev,
+ * because they're too painful to generalize: p_ppid, p_sid, p_tdev,
* p_tpgid, p_tsess, p_vm_rssize, p_u[us]time_{sec,usec}, p_cpuid
*/
@@ -522,6 +523,7 @@ do { \
(kp)->p_stats = 0; \
(kp)->p_exitsig = 0; \
(kp)->p_flag = (p)->p_flag; \
+ (kp)->p_pid = (pr)->ps_pid; \
(kp)->p_psflags = (pr)->ps_flags; \
\
(kp)->p__pgid = (pg)->pg_id; \
@@ -543,7 +545,7 @@ do { \
if (isthread) { \
(kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec; \
(kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_nsec/1000; \
- (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET; \
+ (kp)->p_tid = (p)->p_tid + THREAD_PID_OFFSET; \
(kp)->p_uticks = (p)->p_tu.tu_uticks; \
(kp)->p_sticks = (p)->p_tu.tu_sticks; \
(kp)->p_iticks = (p)->p_tu.tu_iticks; \
diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c
index 6af3dbbe1c3..0c9e10c1052 100644
--- a/sys/ufs/ffs/ffs_softdep.c
+++ b/sys/ufs/ffs/ffs_softdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_softdep.c,v 1.134 2016/09/15 02:00:18 dlg Exp $ */
+/* $OpenBSD: ffs_softdep.c,v 1.135 2016/11/07 00:26:33 guenther Exp $ */
/*
* Copyright 1998, 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -227,13 +227,13 @@ acquire_lock(struct lockit *lk, int line)
holder = lk->lkt_held;
original_line = lk->lkt_line;
FREE_LOCK(lk);
- if (holder == CURPROC->p_pid)
+ if (holder == CURPROC->p_tid)
panic("softdep_lock: locking against myself, acquired at line %d, relocked at line %d", original_line, line);
else
panic("softdep_lock: lock held by %d, acquired at line %d, relocked at line %d", holder, original_line, line);
}
lk->lkt_spl = splbio();
- lk->lkt_held = CURPROC->p_pid;
+ lk->lkt_held = CURPROC->p_tid;
lk->lkt_line = line;
lockcnt++;
}
@@ -258,12 +258,12 @@ acquire_lock_interlocked(struct lockit *lk, int s, int line)
holder = lk->lkt_held;
original_line = lk->lkt_line;
FREE_LOCK_INTERLOCKED(lk);
- if (holder == CURPROC->p_pid)
+ if (holder == CURPROC->p_tid)
panic("softdep_lock: locking against myself, acquired at line %d, relocked at line %d", original_line, line);
else
panic("softdep_lock: lock held by %d, acquired at line %d, relocked at line %d", holder, original_line, line);
}
- lk->lkt_held = CURPROC->p_pid;
+ lk->lkt_held = CURPROC->p_tid;
lk->lkt_line = line;
lk->lkt_spl = s;
lockcnt++;
@@ -321,7 +321,7 @@ sema_get(struct sema *semap, struct lockit *interlock)
}
return (0);
}
- semap->holder = CURPROC->p_pid;
+ semap->holder = CURPROC->p_tid;
if (interlock != NULL)
FREE_LOCK(interlock);
return (1);
@@ -331,7 +331,7 @@ STATIC void
sema_release(struct sema *semap)
{
- if (semap->value <= 0 || semap->holder != CURPROC->p_pid) {
+ if (semap->value <= 0 || semap->holder != CURPROC->p_tid) {
#ifdef DEBUG
if (lk.lkt_held != -1)
FREE_LOCK(&lk);
diff --git a/sys/ufs/mfs/mfs_vfsops.c b/sys/ufs/mfs/mfs_vfsops.c
index 73fa6448e9f..1d7f7c9db0a 100644
--- a/sys/ufs/mfs/mfs_vfsops.c
+++ b/sys/ufs/mfs/mfs_vfsops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mfs_vfsops.c,v 1.52 2016/09/08 16:57:29 tedu Exp $ */
+/* $OpenBSD: mfs_vfsops.c,v 1.53 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: mfs_vfsops.c,v 1.10 1996/02/09 22:31:28 christos Exp $ */
/*
@@ -135,7 +135,7 @@ mfs_mount(struct mount *mp, const char *path, void *data,
mfsp->mfs_baseoff = args.base;
mfsp->mfs_size = args.size;
mfsp->mfs_vnode = devvp;
- mfsp->mfs_pid = p->p_pid;
+ mfsp->mfs_tid = p->p_tid;
bufq_init(&mfsp->mfs_bufq, BUFQ_FIFO);
if ((error = ffs_mountfs(devvp, mp, p)) != 0) {
mfsp->mfs_shutdown = 1;
diff --git a/sys/ufs/mfs/mfs_vnops.c b/sys/ufs/mfs/mfs_vnops.c
index dfae239885f..94faf2ea743 100644
--- a/sys/ufs/mfs/mfs_vnops.c
+++ b/sys/ufs/mfs/mfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mfs_vnops.c,v 1.48 2016/09/08 16:44:46 tedu Exp $ */
+/* $OpenBSD: mfs_vnops.c,v 1.49 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: mfs_vnops.c,v 1.8 1996/03/17 02:16:32 christos Exp $ */
/*
@@ -130,7 +130,7 @@ mfs_strategy(void *v)
panic("mfs_strategy: bad dev");
mfsp = VTOMFS(vp);
- if (p != NULL && mfsp->mfs_pid == p->p_pid) {
+ if (p != NULL && mfsp->mfs_tid == p->p_tid) {
mfs_doio(mfsp, bp);
} else {
bufq_queue(&mfsp->mfs_bufq, bp);
@@ -252,7 +252,7 @@ mfs_print(void *v)
struct vop_print_args *ap = v;
struct mfsnode *mfsp = VTOMFS(ap->a_vp);
- printf("tag VT_MFS, pid %d, base %p, size %ld\n", mfsp->mfs_pid,
+ printf("tag VT_MFS, tid %d, base %p, size %ld\n", mfsp->mfs_tid,
mfsp->mfs_baseoff, mfsp->mfs_size);
return (0);
}
diff --git a/sys/ufs/mfs/mfsnode.h b/sys/ufs/mfs/mfsnode.h
index 644c72a2e8e..f57db08e694 100644
--- a/sys/ufs/mfs/mfsnode.h
+++ b/sys/ufs/mfs/mfsnode.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mfsnode.h,v 1.14 2013/01/15 11:20:55 jsing Exp $ */
+/* $OpenBSD: mfsnode.h,v 1.15 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: mfsnode.h,v 1.3 1996/02/09 22:31:31 christos Exp $ */
/*
@@ -41,7 +41,7 @@ struct mfsnode {
struct bufq mfs_bufq; /* bufq for MFS I/O */
caddr_t mfs_baseoff; /* base of file system in memory */
long mfs_size; /* size of memory file system */
- pid_t mfs_pid; /* supporting process pid */
+ pid_t mfs_tid; /* supporting thread's tid */
struct buf *mfs_buflist; /* list of I/O requests */
int mfs_shutdown; /* shutdown request */
};
diff --git a/sys/uvm/uvm_map.c b/sys/uvm/uvm_map.c
index 7b3a51cd1af..10a9ab0601a 100644
--- a/sys/uvm/uvm_map.c
+++ b/sys/uvm/uvm_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_map.c,v 1.225 2016/09/16 02:35:42 dlg Exp $ */
+/* $OpenBSD: uvm_map.c,v 1.226 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: uvm_map.c,v 1.86 2000/11/27 08:40:03 chs Exp $ */
/*
@@ -2951,7 +2951,7 @@ uvm_page_printit(pg, full, pr)
pg->uobject, pg->uanon, (long long)pg->offset);
#if defined(UVM_PAGE_TRKOWN)
if (pg->pg_flags & PG_BUSY)
- (*pr)(" owning process = %d, tag=%s",
+ (*pr)(" owning thread = %d, tag=%s",
pg->owner, pg->owner_tag);
else
(*pr)(" page not busy, no owner");
diff --git a/sys/uvm/uvm_page.c b/sys/uvm/uvm_page.c
index 24a150c859f..4002c61dfad 100644
--- a/sys/uvm/uvm_page.c
+++ b/sys/uvm/uvm_page.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_page.c,v 1.145 2016/09/16 02:35:42 dlg Exp $ */
+/* $OpenBSD: uvm_page.c,v 1.146 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: uvm_page.c,v 1.44 2000/11/27 08:40:04 chs Exp $ */
/*
@@ -1077,7 +1077,7 @@ uvm_page_unbusy(struct vm_page **pgs, int npgs)
*
* => this is a debugging function that keeps track of who sets PG_BUSY
* and where they do it. it can be used to track down problems
- * such a process setting "PG_BUSY" and never releasing it.
+ * such a thread setting "PG_BUSY" and never releasing it.
* => if "tag" is NULL then we are releasing page ownership
*/
void
@@ -1087,11 +1087,11 @@ uvm_page_own(struct vm_page *pg, char *tag)
if (tag) {
if (pg->owner_tag) {
printf("uvm_page_own: page %p already owned "
- "by proc %d [%s]\n", pg,
+ "by thread %d [%s]\n", pg,
pg->owner, pg->owner_tag);
panic("uvm_page_own");
}
- pg->owner = (curproc) ? curproc->p_pid : (pid_t) -1;
+ pg->owner = (curproc) ? curproc->p_tid : (pid_t) -1;
pg->owner_tag = tag;
return;
}
diff --git a/sys/uvm/uvm_page.h b/sys/uvm/uvm_page.h
index ca1fc255d3c..6ea58655b01 100644
--- a/sys/uvm/uvm_page.h
+++ b/sys/uvm/uvm_page.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_page.h,v 1.62 2016/09/16 02:35:42 dlg Exp $ */
+/* $OpenBSD: uvm_page.h,v 1.63 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: uvm_page.h,v 1.19 2000/12/28 08:24:55 chs Exp $ */
/*
@@ -112,7 +112,7 @@ struct vm_page {
#if defined(UVM_PAGE_TRKOWN)
/* debugging fields to track page ownership */
- pid_t owner; /* proc that set PG_BUSY */
+ pid_t owner; /* thread that set PG_BUSY */
char *owner_tag; /* why it was set busy */
#endif
};