Threads
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:
parent
2372806862
commit
f4d7f9100d
19 changed files with 1300 additions and 248 deletions
|
|
@ -664,7 +664,7 @@ do_dma(uint64 argp)
|
|||
|
||||
struct vma *v = 0;
|
||||
for (int i = 0; i < NVMA; i++)
|
||||
if (!p->vma[i].used) { v = &p->vma[i]; break; }
|
||||
if (!p->mm->vma[i].used) { v = &p->mm->vma[i]; break; }
|
||||
if (!v) {
|
||||
blk->proc = 0;
|
||||
return -ENOMEM;
|
||||
|
|
@ -672,9 +672,9 @@ do_dma(uint64 argp)
|
|||
|
||||
// Its own mapping in the caller, taken from the same bump allocator mmap
|
||||
// uses so the two cannot collide.
|
||||
if (p->mmap_next == 0)
|
||||
p->mmap_next = 0x40000000;
|
||||
uint64 va = p->mmap_next;
|
||||
if (p->mm->mmap_next == 0)
|
||||
p->mm->mmap_next = 0x40000000;
|
||||
uint64 va = p->mm->mmap_next;
|
||||
if (va + size < va || va + size > KERNBASE) {
|
||||
blk->proc = 0;
|
||||
return -ENOMEM;
|
||||
|
|
@ -685,7 +685,7 @@ do_dma(uint64 argp)
|
|||
blk->proc = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
p->mmap_next += size;
|
||||
p->mm->mmap_next += size;
|
||||
|
||||
uint64 phys = dma_phys(kva);
|
||||
if (mappages(p->pgdir, (void *)va, size, phys, PTE_W | PTE_U) < 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue