/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _THREAD_H_ #define _THREAD_H_ #include #include #include #include #include #include struct ehdr; struct phdr; extern mem_cache_t *thread_slab; #define THREAD_STATE_RUNNING 0 #define THREAD_STATE_WAITING 1 #define THREAD_STATE_DNS 2 #define THREAD_STATE_BLOCKED 3 #define THREAD_STATE_ZOMBIE 4 typedef u64 tid_t; struct vm_area { vaddr_t start; size_t len; u64 flags; }; struct file { dirent_t *dirent; u64 flags; u64 offset; u64 refcount; spinlock_t lock; }; struct thread { tid_t tid; uaddr_t kstack_ptr; uaddr_t kstack_top; uaddr_t ustack_top; size_t stack_size; u64 state; u64 tls_base; struct thread *next; tid_t group; pgd_t *pgd; spinlock_t mem_lock; rbtree_t memmap; spinlock_t alloc_lock; rbtree_t alloc_map; uaddr_t entry; spinlock_t fd_lock; size_t fd_array_size; struct file *fdt; struct ehdr *ehdr; struct phdr *phdrs; size_t n_phdrs; char *name; }; void thread_mmap(struct thread *thread, paddr_t p, vaddr_t v, size_t len, u64 flags); ssize_t thread_load_file(const char *file, struct thread *thread); struct thread *thread_create(void); struct thread *thread_fork(struct thread *parent); int thread_set_entry(struct thread *thread, uaddr_t entry); struct thread *kthread_create(void *fn, void *arg, const char *name); void thread_free(struct thread *thread); void thread_init(); tid_t alloc_tid(); void schedule(); #endif /* _THREAD_H_ */