aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2020-11-11 08:48:43 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2020-11-11 08:48:43 +0000
commitcf31cadeb6b96b86cc8619a0a849f8e61b479a9a (patch)
tree8ebdd99de477d3567144c77a1dae023858526d10
parent26676c47dc98b725dff800d752e5ad04bab13fa4 (diff)
downloadsrc-cf31cadeb6b96b86cc8619a0a849f8e61b479a9a.tar.gz
src-cf31cadeb6b96b86cc8619a0a849f8e61b479a9a.zip
thread: fix thread0 tid allocation
Startup code hardcodes the value instead of allocating it. The first spawned thread would then be a duplicate. Pointy hat: mjg
Notes
Notes: svn path=/head/; revision=367583
-rw-r--r--sys/kern/init_main.c3
-rw-r--r--sys/kern/kern_thread.c4
-rw-r--r--sys/sys/proc.h1
3 files changed, 6 insertions, 2 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index ef95da7cbc98..49e353ddad47 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -496,8 +496,7 @@ proc0_init(void *dummy __unused)
p->p_klist = knlist_alloc(&p->p_mtx);
STAILQ_INIT(&p->p_ktr);
p->p_nice = NZERO;
- /* pid_max cannot be greater than PID_MAX */
- td->td_tid = PID_MAX + 1;
+ td->td_tid = THREAD0_TID;
LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash);
td->td_state = TDS_RUNNING;
td->td_pri_class = PRI_TIMESHARE;
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index 29d9b4699ae6..1408180b8327 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -354,6 +354,7 @@ extern int max_threads_per_proc;
void
threadinit(void)
{
+ lwpid_t tid0;
uint32_t flags;
/*
@@ -374,6 +375,9 @@ threadinit(void)
mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF);
tid_bitmap = bit_alloc(maxthread, M_TIDHASH, M_WAITOK);
+ tid0 = tid_alloc();
+ if (tid0 != THREAD0_TID)
+ panic("tid0 %d != %d\n", tid0, THREAD0_TID);
flags = UMA_ZONE_NOFREE;
#ifdef __aarch64__
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 20e37599466a..47669d4af23a 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -855,6 +855,7 @@ MALLOC_DECLARE(M_SUBPROC);
*/
#define PID_MAX 99999
#define NO_PID 100000
+#define THREAD0_TID NO_PID
extern pid_t pid_max;
#define SESS_LEADER(p) ((p)->p_session->s_leader == (p))