Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
process.c File Reference
#include "procc/process.h"
#include "hal/cpu/paging.h"
#include "init/init.h"
#include "libk/executable/elf.h"
#include "libk/math.h"
#include "libk/serial.h"
#include "memory/kalloc.h"
#include "memory/memory_utils.h"
#include "memory/phys_base_allocator.h"
#include "memory/slab.h"
#include "memory/vm_manager.h"
#include "procc/scheduler.h"
#include "procc/thread.h"
#include "string.h"
#include "sys/fd.h"
#include "tty/tty.h"
#include "type.h"
#include "vfs/dentry.h"
#include "vfs/enum.h"
#include "vfs/vnode.h"
#include <str.h>
#include <sys/syscall.h>

Go to the source code of this file.

Macros

#define AT_NULL   0
 
#define AT_IGNORE   1
 
#define AT_EXECFD   2 /* File descriptor from program */
 
#define AT_PHDR   3 /* Program Headers Address from main executable */
 
#define AT_PHENT   4 /* program heder entry size */
 
#define AT_PHNUM   5 /* Program Headers num*/
 
#define AT_PAGESZ   6 /* page size (4096) */
 
#define AT_BASE   7 /* Base address dari interpreter (ld.so) jika ada */
 
#define AT_FLAGS   8 /* Flags */
 
#define AT_ENTRY   9 /* Entry point dari executable utama */
 
#define AT_NOTELF   10 /* Program not ELF */
 
#define AT_UID   11 /* Real User ID */
 
#define AT_EUID   12 /* Effective User ID */
 
#define AT_GID   13 /* Real Group ID */
 
#define AT_EGID   14 /* Effective Group ID */
 
#define AT_PLATFORM   15 /* String CPU format (ex: "x86_64") */
 
#define AT_HWCAP   16 /* Bitmask CPU capability */
 
#define AT_CLKTCK   17 /* clock freq, for times() */
 
#define AT_SECURE
 
#define AT_RANDOM   25 /* Pointer into 16 byte random for stack canary/ASLR */
 
#define AT_EXECFN   31 /* String path name executbale file */
 
#define AT_SYSINFO_EHDR   33
 
#define USER_STACK_PAGES   256
 
#define USER_STACK_SIZE   (USER_STACK_PAGES * 4096)
 

Functions

 __attribute__ ((unused))
 
 INIT (Process)
 
static uintptr_t elf_prepare_stack (uintptr_t stack_top_kernel, uintptr_t stack_top_user, int argc, char *const *argv, char *const *envp, Elf64_Ehdr *ehdr, uintptr_t entry_addr, uintptr_t phdr_vaddr, uintptr_t interp_base_addr)
 
int execve (const char *path, char *const *argv, char *const *envp)
 
pid_t alloc_pid (void)
 
void free_pid (pid_t pid)
 
process_t * create_process (char *name, thread_t *main_thread)
 

Variables

static struct slab_cacheprocess_cache = 0
 
static uint8_tpid_bitmap = 0
 
static dentry_ptr process_dentry = 0
 
static process_t * _process_list = 0
 

Macro Definition Documentation

◆ AT_BASE

#define AT_BASE   7 /* Base address dari interpreter (ld.so) jika ada */

Definition at line 45 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_CLKTCK

#define AT_CLKTCK   17 /* clock freq, for times() */

Definition at line 58 of file process.c.

◆ AT_EGID

#define AT_EGID   14 /* Effective Group ID */

Definition at line 53 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_ENTRY

#define AT_ENTRY   9 /* Entry point dari executable utama */

Definition at line 47 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_EUID

#define AT_EUID   12 /* Effective User ID */

Definition at line 51 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_EXECFD

#define AT_EXECFD   2 /* File descriptor from program */

Definition at line 40 of file process.c.

◆ AT_EXECFN

#define AT_EXECFN   31 /* String path name executbale file */

Definition at line 63 of file process.c.

◆ AT_FLAGS

#define AT_FLAGS   8 /* Flags */

Definition at line 46 of file process.c.

◆ AT_GID

#define AT_GID   13 /* Real Group ID */

Definition at line 52 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_HWCAP

#define AT_HWCAP   16 /* Bitmask CPU capability */

Definition at line 57 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_IGNORE

#define AT_IGNORE   1

Definition at line 39 of file process.c.

◆ AT_NOTELF

#define AT_NOTELF   10 /* Program not ELF */

Definition at line 48 of file process.c.

◆ AT_NULL

#define AT_NULL   0

Definition at line 38 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_PAGESZ

#define AT_PAGESZ   6 /* page size (4096) */

Definition at line 44 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_PHDR

#define AT_PHDR   3 /* Program Headers Address from main executable */

Definition at line 41 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_PHENT

#define AT_PHENT   4 /* program heder entry size */

Definition at line 42 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_PHNUM

#define AT_PHNUM   5 /* Program Headers num*/

Definition at line 43 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_PLATFORM

#define AT_PLATFORM   15 /* String CPU format (ex: "x86_64") */

Definition at line 56 of file process.c.

◆ AT_RANDOM

#define AT_RANDOM   25 /* Pointer into 16 byte random for stack canary/ASLR */

Definition at line 62 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_SECURE

#define AT_SECURE
Value:
23 /* secure mode (boolean 1/0), used for setuid/setgid \
*/

Definition at line 60 of file process.c.

Referenced by elf_prepare_stack().

◆ AT_SYSINFO_EHDR

#define AT_SYSINFO_EHDR   33

Definition at line 64 of file process.c.

◆ AT_UID

#define AT_UID   11 /* Real User ID */

Definition at line 50 of file process.c.

Referenced by elf_prepare_stack().

◆ USER_STACK_PAGES

#define USER_STACK_PAGES   256

Definition at line 66 of file process.c.

Referenced by execve().

◆ USER_STACK_SIZE

#define USER_STACK_SIZE   (USER_STACK_PAGES * 4096)

Definition at line 67 of file process.c.

Referenced by execve().

Function Documentation

◆ __attribute__()

__attribute__ ( (unused) )

Definition at line 27 of file process.c.

◆ alloc_pid()

pid_t alloc_pid ( void )

Definition at line 529 of file process.c.

References INVALID_PID, MAX_PID_ALLOWED, and pid_bitmap.

Referenced by create_process().

◆ create_process()

◆ elf_prepare_stack()

static uintptr_t elf_prepare_stack ( uintptr_t stack_top_kernel,
uintptr_t stack_top_user,
int argc,
char *const * argv,
char *const * envp,
Elf64_Ehdr * ehdr,
uintptr_t entry_addr,
uintptr_t phdr_vaddr,
uintptr_t interp_base_addr )
static

◆ execve()

int execve ( const char * path,
char *const * argv,
char *const * envp )

Definition at line 173 of file process.c.

References ALIGN_UP, attach_to_scheduler(), base_addr, BLOCK_SIZE, kstring::c_str, create_process(), create_thread(), create_vmm_page(), dentry_put(), Elf64_Ehdr::e_entry, Elf64_Ehdr::e_ident, Elf64_Ehdr::e_phentsize, Elf64_Ehdr::e_phnum, Elf64_Ehdr::e_phoff, Elf64_Ehdr::e_type, Elf64_Ehdr::e_version, elf_count_load_size(), elf_dyn_map_all(), elf_get_phdr_dynamic(), elf_gnu_hash_parse(), elf_load(), elf_prepare_stack(), ELF_PTR, elf_relocate_dyn(), elf_section_map_all(), ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, entry_addr, ET_DYN, ET_EXEC, get_kernel_vmm_page(), get_root_dentry(), elf_section_map::gnuhash, heap_start, kalloc(), kfree2(), LOG2_ERROR, LOG2_INFO, LOG_ERROR, LOG_INFO, elf_load_mmap_table::mapped, memcopy(), min(), dentry::name, elf_dynamic_map::needed, NULL, ops, vnode::ops, Elf64_Phdr::p_memsz, Elf64_Phdr::p_offset, Elf64_Phdr::p_type, Elf64_Phdr::p_vaddr, page, paging_create_page_directory(), paging_get_highest_page_map(), paging_setup(), paging_unmap_page(), dentry::parent, path, phys_base_alloc(), print_dentry_tree(), PT_INTERP, PT_LOAD, resolve_dentry(), serial2_printf(), serial_printf(), serial_trace, size, vector_uint64_t::size, vnode::size, str(), str_release(), elf_dynamic_map::strtab, THREAD_USER, vnode::type, USER_STACK_PAGES, USER_STACK_SIZE, USER_STACK_VADDR, elf_load_mmap_table::vaddr, VFS_OK, vma_lookup_free_vaddr(), VMA_REGION_A, VMA_REGION_PROCESS, vma_register(), vma_unregister(), dentry::vnode, VNODE_TYPE_FILE, VNODE_TYPE_LNK, and vxMultipleMmap().

Referenced by __attribute__(), and execve().

◆ free_pid()

void free_pid ( pid_t pid)

Definition at line 546 of file process.c.

References pid, and pid_bitmap.

◆ INIT()

INIT ( Process )

Variable Documentation

◆ _process_list

process_t* _process_list = 0
static

Definition at line 28 of file process.c.

Referenced by create_process().

◆ pid_bitmap

uint8_t* pid_bitmap = 0
static

Definition at line 25 of file process.c.

Referenced by alloc_pid(), free_pid(), and INIT().

◆ process_cache

struct slab_cache* process_cache = 0
static

Definition at line 24 of file process.c.

Referenced by create_process(), and INIT().

◆ process_dentry

dentry_ptr process_dentry = 0
static

Definition at line 26 of file process.c.

Referenced by create_process(), and INIT().