A thread is a struct proc that shares three counted objects with others of
its group: the address space (struct mm: page tables, heap top, VMAs and a
lock for changing them), the descriptor table, and the signal dispositions.
clone() shares what its flags say and fork() copies.

- clone(): pthread_create's shape (VM, FILES, SIGHAND, THREAD, SETTLS,
  PARENT_SETTID, CHILD_CLEARTID) and posix_spawn's (VM, VFORK, a stack).
- futex: WAIT, WAIT_BITSET with timeouts, WAKE, REQUEUE, CMP_REQUEUE, keyed
  by the word's kernel address so shared pages meet. set_tid_address keeps
  the word that exit zeroes and wakes, for pthread_join.
- exit ends a thread; exit_group, a fatal signal, or the leader exiting ends
  them all. reapd frees exited threads; the leader is reaped by its parent
  once the rest are gone. getpid is the group, gettid the thread.
- Stops and resumes reach every thread; other process signals the leader.
- exec kills the other threads and unshares the dispositions.
- No TLB shootdown, so pages unmapped from a shared address space are freed
  only once every CPU has reloaded CR3 or is idle.
- procfs: /proc lists processes, task/ lists threads, comm, Threads:, Tgid.
- The console honours VMIN 0 / VTIME (btop's input drain hung on it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
Nexoniarz 2026-10-25 03:03:50 +01:00
commit f4d7f9100d
19 changed files with 1300 additions and 248 deletions

View file

@ -62,6 +62,31 @@ void pciuser_release_all(struct proc*);
int pciuser_owner_pid(int idx);
int proc_reincarnate(int status);
int sig_default_stops(int);
struct mm* mm_alloc(void);
void mm_get(struct mm*);
void mm_put(struct mm*);
int mm_shared(struct mm*);
void mm_lock(struct mm*);
void mm_unlock(struct mm*);
struct files* files_alloc(void);
void files_get(struct files*);
void files_put(struct files*);
void files_lock(void);
void files_unlock(void);
struct sighand* sighand_alloc(void);
void sighand_get(struct sighand*);
void sighand_put(struct sighand*);
struct proc* proc_leader(struct proc*);
int proc_thread_count(int);
void thread_exit(void) __attribute__((noreturn));
int futex_wake_key(void*, int);
int futex_op(addr_t, int, int, addr_t, addr_t, int);
int clone_proc(uint64, uint64, uint64, uint64, uint64);
void proc_exec_threads(void);
void proc_exec_done(void);
void thread_reaper_start(void);
void vm_defer_tick(void);
void mm_release_shared(struct mm*);
void proc_stop(int);
int sig_attention(struct proc*);
int sig_blocking_check(void);
@ -774,7 +799,7 @@ uint64 memfd_size(int id);
int memfd_truncate(int id, uint64 len);
int memfd_rw(int id, int user, uint64 buf, uint64 off, int n, int writing);
void shm_detach(int id);
void proc_release_shared(struct proc *);
int copy_vma_range(pml4e_t *dstpgdir, pml4e_t *srcpgdir, uint64 va, uint64 length, int is_fb);
void clearpteu(pml4e_t *pgdir, char *uva);