diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 3b32fa94..ebf67918 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -35,268 +35,289 @@ if (DOXYGEN_FOUND) ${CMAKE_SOURCE_DIR}/LICENSE.md ${CMAKE_SOURCE_DIR}/doc/signal.md ${CMAKE_SOURCE_DIR}/doc/syscall.md - - ${CMAKE_SOURCE_DIR}/mentos/inc/boot.h - ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/gdt.h - ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/idt.h - ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/isr.h - ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/tss.h - ${CMAKE_SOURCE_DIR}/mentos/inc/devices/fpu.h - ${CMAKE_SOURCE_DIR}/mentos/inc/devices/pci.h - ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/ata/ata.h - ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/ata/ata_types.h + + ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/rtc.h + ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/ps2.h ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/fdc.h - ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/keyboard/keyboard.h - ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/keyboard/keymap.h ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/mouse.h - ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/ps2.h - ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/rtc.h + ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/mem.h + ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/ata/ata_types.h + ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/ata/ata.h + ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/keyboard/keymap.h + ${CMAKE_SOURCE_DIR}/mentos/inc/drivers/keyboard/keyboard.h ${CMAKE_SOURCE_DIR}/mentos/inc/elf/elf.h - ${CMAKE_SOURCE_DIR}/mentos/inc/fs/ext2.h - ${CMAKE_SOURCE_DIR}/mentos/inc/fs/ioctl.h - ${CMAKE_SOURCE_DIR}/mentos/inc/fs/procfs.h - ${CMAKE_SOURCE_DIR}/mentos/inc/fs/vfs.h - ${CMAKE_SOURCE_DIR}/mentos/inc/fs/vfs_types.h + ${CMAKE_SOURCE_DIR}/mentos/inc/multiboot.h + ${CMAKE_SOURCE_DIR}/mentos/inc/process/scheduler_feedback.h + ${CMAKE_SOURCE_DIR}/mentos/inc/process/prio.h + ${CMAKE_SOURCE_DIR}/mentos/inc/process/process.h + ${CMAKE_SOURCE_DIR}/mentos/inc/process/wait.h + ${CMAKE_SOURCE_DIR}/mentos/inc/process/scheduler.h + ${CMAKE_SOURCE_DIR}/mentos/inc/version.h + ${CMAKE_SOURCE_DIR}/mentos/inc/proc_access.h + ${CMAKE_SOURCE_DIR}/mentos/inc/mem/gfp.h + ${CMAKE_SOURCE_DIR}/mentos/inc/mem/zone_allocator.h + ${CMAKE_SOURCE_DIR}/mentos/inc/mem/paging.h + ${CMAKE_SOURCE_DIR}/mentos/inc/mem/slab.h + ${CMAKE_SOURCE_DIR}/mentos/inc/mem/kheap.h + ${CMAKE_SOURCE_DIR}/mentos/inc/mem/vmem_map.h + ${CMAKE_SOURCE_DIR}/mentos/inc/mem/buddysystem.h + ${CMAKE_SOURCE_DIR}/mentos/inc/hardware/timer.h ${CMAKE_SOURCE_DIR}/mentos/inc/hardware/cpuid.h ${CMAKE_SOURCE_DIR}/mentos/inc/hardware/pic8259.h - ${CMAKE_SOURCE_DIR}/mentos/inc/hardware/timer.h - ${CMAKE_SOURCE_DIR}/mentos/inc/io/proc_modules.h - ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga.h - ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga_font.h - ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga_mode.h - ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga_palette.h - ${CMAKE_SOURCE_DIR}/mentos/inc/io/video.h ${CMAKE_SOURCE_DIR}/mentos/inc/kernel.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/compiler.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/hashmap.h + ${CMAKE_SOURCE_DIR}/mentos/inc/link_access.h + ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/gdt.h + ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/tss.h + ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/isr.h + ${CMAKE_SOURCE_DIR}/mentos/inc/descriptor_tables/idt.h + ${CMAKE_SOURCE_DIR}/mentos/inc/ipc/ipc.h ${CMAKE_SOURCE_DIR}/mentos/inc/klib/irqflags.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/list.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/list_head.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/mutex.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/ndtree.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/rbtree.h ${CMAKE_SOURCE_DIR}/mentos/inc/klib/spinlock.h - ${CMAKE_SOURCE_DIR}/mentos/inc/klib/stack_helper.h ${CMAKE_SOURCE_DIR}/mentos/inc/klib/stdatomic.h - ${CMAKE_SOURCE_DIR}/mentos/inc/link_access.h - ${CMAKE_SOURCE_DIR}/mentos/inc/mem/buddysystem.h - ${CMAKE_SOURCE_DIR}/mentos/inc/mem/gfp.h - ${CMAKE_SOURCE_DIR}/mentos/inc/mem/kheap.h - ${CMAKE_SOURCE_DIR}/mentos/inc/mem/paging.h - ${CMAKE_SOURCE_DIR}/mentos/inc/mem/slab.h - ${CMAKE_SOURCE_DIR}/mentos/inc/mem/vmem_map.h - ${CMAKE_SOURCE_DIR}/mentos/inc/mem/zone_allocator.h - ${CMAKE_SOURCE_DIR}/mentos/inc/multiboot.h - ${CMAKE_SOURCE_DIR}/mentos/inc/process/prio.h - ${CMAKE_SOURCE_DIR}/mentos/inc/process/process.h - ${CMAKE_SOURCE_DIR}/mentos/inc/process/scheduler.h - ${CMAKE_SOURCE_DIR}/mentos/inc/process/wait.h - ${CMAKE_SOURCE_DIR}/mentos/inc/proc_access.h - ${CMAKE_SOURCE_DIR}/mentos/inc/sys/errno.h - ${CMAKE_SOURCE_DIR}/mentos/inc/sys/ipc.h - ${CMAKE_SOURCE_DIR}/mentos/inc/sys/module.h - ${CMAKE_SOURCE_DIR}/mentos/inc/sys/reboot.h + ${CMAKE_SOURCE_DIR}/mentos/inc/klib/ndtree.h + ${CMAKE_SOURCE_DIR}/mentos/inc/klib/stack_helper.h + ${CMAKE_SOURCE_DIR}/mentos/inc/klib/mutex.h + ${CMAKE_SOURCE_DIR}/mentos/inc/klib/compiler.h + ${CMAKE_SOURCE_DIR}/mentos/inc/klib/rbtree.h + ${CMAKE_SOURCE_DIR}/mentos/inc/klib/hashmap.h + ${CMAKE_SOURCE_DIR}/mentos/inc/klib/list.h + ${CMAKE_SOURCE_DIR}/mentos/inc/boot.h ${CMAKE_SOURCE_DIR}/mentos/inc/sys/types.h + ${CMAKE_SOURCE_DIR}/mentos/inc/sys/reboot.h + ${CMAKE_SOURCE_DIR}/mentos/inc/sys/module.h ${CMAKE_SOURCE_DIR}/mentos/inc/sys/utsname.h - ${CMAKE_SOURCE_DIR}/mentos/inc/system/panic.h + ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga_font.h + ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga.h + ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga_palette.h + ${CMAKE_SOURCE_DIR}/mentos/inc/io/vga/vga_mode.h + ${CMAKE_SOURCE_DIR}/mentos/inc/io/proc_modules.h + ${CMAKE_SOURCE_DIR}/mentos/inc/io/video.h + ${CMAKE_SOURCE_DIR}/mentos/inc/devices/pci.h + ${CMAKE_SOURCE_DIR}/mentos/inc/devices/fpu.h ${CMAKE_SOURCE_DIR}/mentos/inc/system/printk.h - ${CMAKE_SOURCE_DIR}/mentos/inc/system/signal.h + ${CMAKE_SOURCE_DIR}/mentos/inc/system/panic.h ${CMAKE_SOURCE_DIR}/mentos/inc/system/syscall.h - ${CMAKE_SOURCE_DIR}/mentos/inc/version.h + ${CMAKE_SOURCE_DIR}/mentos/inc/system/signal.h + ${CMAKE_SOURCE_DIR}/mentos/inc/fs/vfs.h + ${CMAKE_SOURCE_DIR}/mentos/inc/fs/ext2.h + ${CMAKE_SOURCE_DIR}/mentos/inc/fs/namei.h + ${CMAKE_SOURCE_DIR}/mentos/inc/fs/attr.h + ${CMAKE_SOURCE_DIR}/mentos/inc/fs/procfs.h + ${CMAKE_SOURCE_DIR}/mentos/inc/fs/vfs_types.h + ${CMAKE_SOURCE_DIR}/mentos/inc/fs/ioctl.h + ${CMAKE_SOURCE_DIR}/libc/inc/limits.h + ${CMAKE_SOURCE_DIR}/libc/inc/stdbool.h + ${CMAKE_SOURCE_DIR}/libc/inc/stdint.h + ${CMAKE_SOURCE_DIR}/libc/inc/time.h + ${CMAKE_SOURCE_DIR}/libc/inc/bits/termios-struct.h + ${CMAKE_SOURCE_DIR}/libc/inc/bits/ioctls.h + ${CMAKE_SOURCE_DIR}/libc/inc/bits/stat.h + ${CMAKE_SOURCE_DIR}/libc/inc/shadow.h + ${CMAKE_SOURCE_DIR}/libc/inc/fcvt.h + ${CMAKE_SOURCE_DIR}/libc/inc/string.h + ${CMAKE_SOURCE_DIR}/libc/inc/pwd.h + ${CMAKE_SOURCE_DIR}/libc/inc/readline.h + ${CMAKE_SOURCE_DIR}/libc/inc/crypt/sha256.h + ${CMAKE_SOURCE_DIR}/libc/inc/termios.h + ${CMAKE_SOURCE_DIR}/libc/inc/stdlib.h + ${CMAKE_SOURCE_DIR}/libc/inc/fcntl.h + ${CMAKE_SOURCE_DIR}/libc/inc/stdio.h + ${CMAKE_SOURCE_DIR}/libc/inc/ring_buffer.h + ${CMAKE_SOURCE_DIR}/libc/inc/err.h + ${CMAKE_SOURCE_DIR}/libc/inc/stdarg.h + ${CMAKE_SOURCE_DIR}/libc/inc/libgen.h + ${CMAKE_SOURCE_DIR}/libc/inc/sched.h + ${CMAKE_SOURCE_DIR}/libc/inc/assert.h + ${CMAKE_SOURCE_DIR}/libc/inc/stddef.h + ${CMAKE_SOURCE_DIR}/libc/inc/signal.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/errno.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/shm.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/bitops.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/types.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/sem.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/reboot.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/msg.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/ipc.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/wait.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/list_head.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/kernel_levels.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/dirent.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/ioctl.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/mman.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/utsname.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/unistd.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/stat.h + ${CMAKE_SOURCE_DIR}/libc/inc/sys/list_head_algorithm.h + ${CMAKE_SOURCE_DIR}/libc/inc/grp.h + ${CMAKE_SOURCE_DIR}/libc/inc/io/ansi_colors.h + ${CMAKE_SOURCE_DIR}/libc/inc/io/mm_io.h + ${CMAKE_SOURCE_DIR}/libc/inc/io/debug.h + ${CMAKE_SOURCE_DIR}/libc/inc/io/port_io.h + ${CMAKE_SOURCE_DIR}/libc/inc/ctype.h + ${CMAKE_SOURCE_DIR}/libc/inc/system/syscall_types.h + ${CMAKE_SOURCE_DIR}/libc/inc/array.h + ${CMAKE_SOURCE_DIR}/libc/inc/strerror.h + ${CMAKE_SOURCE_DIR}/libc/inc/math.h - ${CMAKE_SOURCE_DIR}/mentos/src/boot.c - ${CMAKE_SOURCE_DIR}/mentos/src/crypt/sha256.c - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/exception.c - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.c - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/idt.c - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.c - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/tss.c - ${CMAKE_SOURCE_DIR}/mentos/src/devices/fpu.c - ${CMAKE_SOURCE_DIR}/mentos/src/devices/pci.c - ${CMAKE_SOURCE_DIR}/mentos/src/drivers/ata.c + ${CMAKE_SOURCE_DIR}/mentos/src/drivers/mouse.c + ${CMAKE_SOURCE_DIR}/mentos/src/drivers/rtc.c + ${CMAKE_SOURCE_DIR}/mentos/src/drivers/mem.c ${CMAKE_SOURCE_DIR}/mentos/src/drivers/fdc.c - ${CMAKE_SOURCE_DIR}/mentos/src/drivers/keyboard/keyboard.c ${CMAKE_SOURCE_DIR}/mentos/src/drivers/keyboard/keymap.c - ${CMAKE_SOURCE_DIR}/mentos/src/drivers/mouse.c + ${CMAKE_SOURCE_DIR}/mentos/src/drivers/keyboard/keyboard.c ${CMAKE_SOURCE_DIR}/mentos/src/drivers/ps2.c - ${CMAKE_SOURCE_DIR}/mentos/src/drivers/rtc.c + ${CMAKE_SOURCE_DIR}/mentos/src/drivers/ata.c ${CMAKE_SOURCE_DIR}/mentos/src/elf/elf.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/ext2.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/ioctl.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/namei.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/open.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/procfs.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/readdir.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/read_write.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/stat.c - ${CMAKE_SOURCE_DIR}/mentos/src/fs/vfs.c - ${CMAKE_SOURCE_DIR}/mentos/src/hardware/cpuid.c - ${CMAKE_SOURCE_DIR}/mentos/src/hardware/pic8259.c + ${CMAKE_SOURCE_DIR}/mentos/src/process/scheduler_feedback.c + ${CMAKE_SOURCE_DIR}/mentos/src/process/process.c + ${CMAKE_SOURCE_DIR}/mentos/src/process/scheduler_algorithm.c + ${CMAKE_SOURCE_DIR}/mentos/src/process/scheduler.c + ${CMAKE_SOURCE_DIR}/mentos/src/process/wait.c + ${CMAKE_SOURCE_DIR}/mentos/src/crypt/sha256.c + ${CMAKE_SOURCE_DIR}/mentos/src/mem/zone_allocator.c + ${CMAKE_SOURCE_DIR}/mentos/src/mem/paging.c + ${CMAKE_SOURCE_DIR}/mentos/src/mem/buddysystem.c + ${CMAKE_SOURCE_DIR}/mentos/src/mem/kheap.c + ${CMAKE_SOURCE_DIR}/mentos/src/mem/slab.c + ${CMAKE_SOURCE_DIR}/mentos/src/mem/vmem_map.c ${CMAKE_SOURCE_DIR}/mentos/src/hardware/timer.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/debug.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/mm_io.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_running.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_system.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_video.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/stdio.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/vga/vga.c - ${CMAKE_SOURCE_DIR}/mentos/src/io/video.c - ${CMAKE_SOURCE_DIR}/mentos/src/ipc/msg.c + ${CMAKE_SOURCE_DIR}/mentos/src/hardware/pic8259.c + ${CMAKE_SOURCE_DIR}/mentos/src/hardware/cpuid.c + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.c + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.c + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/exception.c + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/tss.c + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/idt.c ${CMAKE_SOURCE_DIR}/mentos/src/ipc/sem.c + ${CMAKE_SOURCE_DIR}/mentos/src/ipc/msg.c + ${CMAKE_SOURCE_DIR}/mentos/src/ipc/ipc.c ${CMAKE_SOURCE_DIR}/mentos/src/ipc/shm.c - ${CMAKE_SOURCE_DIR}/mentos/src/kernel/sys.c - ${CMAKE_SOURCE_DIR}/mentos/src/kernel.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/assert.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/ctype.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/stdlib.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/rbtree.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/vsprintf.c ${CMAKE_SOURCE_DIR}/mentos/src/klib/fcvt.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/hashmap.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/vscanf.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/time.c ${CMAKE_SOURCE_DIR}/mentos/src/klib/libgen.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/list.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/math.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/string.c ${CMAKE_SOURCE_DIR}/mentos/src/klib/mutex.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/hashmap.c ${CMAKE_SOURCE_DIR}/mentos/src/klib/ndtree.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/rbtree.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/spinlock.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/assert.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/list.c ${CMAKE_SOURCE_DIR}/mentos/src/klib/strerror.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/string.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/time.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/vscanf.c - ${CMAKE_SOURCE_DIR}/mentos/src/klib/vsprintf.c - ${CMAKE_SOURCE_DIR}/mentos/src/mem/buddysystem.c - ${CMAKE_SOURCE_DIR}/mentos/src/mem/kheap.c - ${CMAKE_SOURCE_DIR}/mentos/src/mem/paging.c - ${CMAKE_SOURCE_DIR}/mentos/src/mem/slab.c - ${CMAKE_SOURCE_DIR}/mentos/src/mem/vmem_map.c - ${CMAKE_SOURCE_DIR}/mentos/src/mem/zone_allocator.c - ${CMAKE_SOURCE_DIR}/mentos/src/multiboot.c - ${CMAKE_SOURCE_DIR}/mentos/src/process/process.c - ${CMAKE_SOURCE_DIR}/mentos/src/process/scheduler.c - ${CMAKE_SOURCE_DIR}/mentos/src/process/scheduler_algorithm.c - ${CMAKE_SOURCE_DIR}/mentos/src/process/wait.c - ${CMAKE_SOURCE_DIR}/mentos/src/sys/module.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/ctype.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/spinlock.c + ${CMAKE_SOURCE_DIR}/mentos/src/klib/math.c ${CMAKE_SOURCE_DIR}/mentos/src/sys/utsname.c + ${CMAKE_SOURCE_DIR}/mentos/src/sys/module.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/debug.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/mm_io.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/vga/vga.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/stdio.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/video.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_video.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_running.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_feedback.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_ipc.c + ${CMAKE_SOURCE_DIR}/mentos/src/io/proc_system.c + ${CMAKE_SOURCE_DIR}/mentos/src/kernel.c + ${CMAKE_SOURCE_DIR}/mentos/src/devices/pci.c + ${CMAKE_SOURCE_DIR}/mentos/src/devices/fpu.c + ${CMAKE_SOURCE_DIR}/mentos/src/boot.c + ${CMAKE_SOURCE_DIR}/mentos/src/system/signal.c ${CMAKE_SOURCE_DIR}/mentos/src/system/errno.c ${CMAKE_SOURCE_DIR}/mentos/src/system/panic.c - ${CMAKE_SOURCE_DIR}/mentos/src/system/printk.c - ${CMAKE_SOURCE_DIR}/mentos/src/system/signal.c ${CMAKE_SOURCE_DIR}/mentos/src/system/syscall.c - - ${CMAKE_SOURCE_DIR}/mentos/src/boot.S - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/exception.S - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.S - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/idt.S - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.S - ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/tss.S - ${CMAKE_SOURCE_DIR}/mentos/src/process/user.S - - ${CMAKE_SOURCE_DIR}/libc/inc/array.h - ${CMAKE_SOURCE_DIR}/libc/inc/assert.h - ${CMAKE_SOURCE_DIR}/libc/inc/bits/ioctls.h - ${CMAKE_SOURCE_DIR}/libc/inc/bits/stat.h - ${CMAKE_SOURCE_DIR}/libc/inc/bits/termios-struct.h - ${CMAKE_SOURCE_DIR}/libc/inc/crypt/sha256.h - ${CMAKE_SOURCE_DIR}/libc/inc/ctype.h - ${CMAKE_SOURCE_DIR}/libc/inc/fcntl.h - ${CMAKE_SOURCE_DIR}/libc/inc/fcvt.h - ${CMAKE_SOURCE_DIR}/libc/inc/grp.h - ${CMAKE_SOURCE_DIR}/libc/inc/io/ansi_colors.h - ${CMAKE_SOURCE_DIR}/libc/inc/io/debug.h - ${CMAKE_SOURCE_DIR}/libc/inc/io/mm_io.h - ${CMAKE_SOURCE_DIR}/libc/inc/io/port_io.h - ${CMAKE_SOURCE_DIR}/libc/inc/ipc/ipc.h - ${CMAKE_SOURCE_DIR}/libc/inc/ipc/msg.h - ${CMAKE_SOURCE_DIR}/libc/inc/ipc/sem.h - ${CMAKE_SOURCE_DIR}/libc/inc/ipc/shm.h - ${CMAKE_SOURCE_DIR}/libc/inc/libgen.h - ${CMAKE_SOURCE_DIR}/libc/inc/limits.h - ${CMAKE_SOURCE_DIR}/libc/inc/math.h - ${CMAKE_SOURCE_DIR}/libc/inc/pwd.h - ${CMAKE_SOURCE_DIR}/libc/inc/ring_buffer.h - ${CMAKE_SOURCE_DIR}/libc/inc/sched.h - ${CMAKE_SOURCE_DIR}/libc/inc/signal.h - ${CMAKE_SOURCE_DIR}/libc/inc/stdarg.h - ${CMAKE_SOURCE_DIR}/libc/inc/stdbool.h - ${CMAKE_SOURCE_DIR}/libc/inc/stddef.h - ${CMAKE_SOURCE_DIR}/libc/inc/stdint.h - ${CMAKE_SOURCE_DIR}/libc/inc/stdio.h - ${CMAKE_SOURCE_DIR}/libc/inc/stdlib.h - ${CMAKE_SOURCE_DIR}/libc/inc/strerror.h - ${CMAKE_SOURCE_DIR}/libc/inc/string.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/bitops.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/dirent.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/errno.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/ioctl.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/kernel_levels.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/reboot.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/stat.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/types.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/unistd.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/utsname.h - ${CMAKE_SOURCE_DIR}/libc/inc/sys/wait.h - ${CMAKE_SOURCE_DIR}/libc/inc/system/syscall_types.h - ${CMAKE_SOURCE_DIR}/libc/inc/termios.h - ${CMAKE_SOURCE_DIR}/libc/inc/time.h - - ${CMAKE_SOURCE_DIR}/libc/src/abort.c - ${CMAKE_SOURCE_DIR}/libc/src/assert.c - ${CMAKE_SOURCE_DIR}/libc/src/ctype.c - ${CMAKE_SOURCE_DIR}/libc/src/fcvt.c - ${CMAKE_SOURCE_DIR}/libc/src/grp.c - ${CMAKE_SOURCE_DIR}/libc/src/io/debug.c - ${CMAKE_SOURCE_DIR}/libc/src/io/mm_io.c - ${CMAKE_SOURCE_DIR}/libc/src/ipc/ipc.c + ${CMAKE_SOURCE_DIR}/mentos/src/system/printk.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/open.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/readdir.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/ext2.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/read_write.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/stat.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/ioctl.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/vfs.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/attr.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/procfs.c + ${CMAKE_SOURCE_DIR}/mentos/src/fs/namei.c + ${CMAKE_SOURCE_DIR}/mentos/src/multiboot.c + ${CMAKE_SOURCE_DIR}/mentos/src/kernel/sys.c + ${CMAKE_SOURCE_DIR}/libc/src/stdlib.c ${CMAKE_SOURCE_DIR}/libc/src/libc_start.c - ${CMAKE_SOURCE_DIR}/libc/src/libgen.c - ${CMAKE_SOURCE_DIR}/libc/src/math.c - ${CMAKE_SOURCE_DIR}/libc/src/pwd.c - ${CMAKE_SOURCE_DIR}/libc/src/sched.c ${CMAKE_SOURCE_DIR}/libc/src/setenv.c - ${CMAKE_SOURCE_DIR}/libc/src/stdio.c - ${CMAKE_SOURCE_DIR}/libc/src/stdlib.c - ${CMAKE_SOURCE_DIR}/libc/src/strerror.c - ${CMAKE_SOURCE_DIR}/libc/src/string.c - ${CMAKE_SOURCE_DIR}/libc/src/sys/errno.c - ${CMAKE_SOURCE_DIR}/libc/src/sys/ioctl.c - ${CMAKE_SOURCE_DIR}/libc/src/sys/unistd.c - ${CMAKE_SOURCE_DIR}/libc/src/sys/utsname.c - ${CMAKE_SOURCE_DIR}/libc/src/termios.c - ${CMAKE_SOURCE_DIR}/libc/src/time.c - ${CMAKE_SOURCE_DIR}/libc/src/crypt/sha256.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/chdir.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/close.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/creat.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/exec.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/signal.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/reboot.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/exit.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/fork.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/getcwd.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/getdents.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/getgid.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/getpgid.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/getpid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/setuid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/open.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/kill.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/getppid.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/getsid.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/getuid.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/interval.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/kill.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/lseek.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/mkdir.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/nice.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/open.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/symlink.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/getsid.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/read.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/reboot.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/readlink.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/chmod.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/mkdir.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/getdents.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/rmdir.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/setgid.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/setpgid.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/setsid.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/setuid.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/signal.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/stat.c - ${CMAKE_SOURCE_DIR}/libc/src/unistd/unlink.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/getgid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/dup.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/getpid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/getuid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/exec.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/getcwd.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/setpgid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/close.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/waitpid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/chown.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/creat.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/nice.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/lseek.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/setgid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/getpgid.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/chdir.c + ${CMAKE_SOURCE_DIR}/libc/src/unistd/unlink.c ${CMAKE_SOURCE_DIR}/libc/src/unistd/write.c - ${CMAKE_SOURCE_DIR}/libc/src/vscanf.c ${CMAKE_SOURCE_DIR}/libc/src/vsprintf.c + ${CMAKE_SOURCE_DIR}/libc/src/fcvt.c + ${CMAKE_SOURCE_DIR}/libc/src/abort.c + ${CMAKE_SOURCE_DIR}/libc/src/stdio.c + ${CMAKE_SOURCE_DIR}/libc/src/vscanf.c + ${CMAKE_SOURCE_DIR}/libc/src/time.c + ${CMAKE_SOURCE_DIR}/libc/src/err.c + ${CMAKE_SOURCE_DIR}/libc/src/crypt/sha256.c + ${CMAKE_SOURCE_DIR}/libc/src/pwd.c + ${CMAKE_SOURCE_DIR}/libc/src/libgen.c + ${CMAKE_SOURCE_DIR}/libc/src/string.c + ${CMAKE_SOURCE_DIR}/libc/src/assert.c + ${CMAKE_SOURCE_DIR}/libc/src/grp.c + ${CMAKE_SOURCE_DIR}/libc/src/shadow.c + ${CMAKE_SOURCE_DIR}/libc/src/sched.c + ${CMAKE_SOURCE_DIR}/libc/src/strerror.c + ${CMAKE_SOURCE_DIR}/libc/src/sys/mman.c + ${CMAKE_SOURCE_DIR}/libc/src/sys/errno.c + ${CMAKE_SOURCE_DIR}/libc/src/sys/ipc.c + ${CMAKE_SOURCE_DIR}/libc/src/sys/unistd.c + ${CMAKE_SOURCE_DIR}/libc/src/sys/ioctl.c + ${CMAKE_SOURCE_DIR}/libc/src/sys/utsname.c + ${CMAKE_SOURCE_DIR}/libc/src/ctype.c + ${CMAKE_SOURCE_DIR}/libc/src/readline.c + ${CMAKE_SOURCE_DIR}/libc/src/termios.c + ${CMAKE_SOURCE_DIR}/libc/src/io/debug.c + ${CMAKE_SOURCE_DIR}/libc/src/io/mm_io.c + ${CMAKE_SOURCE_DIR}/libc/src/math.c + ${CMAKE_SOURCE_DIR}/mentos/src/process/user.S + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/exception.S + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/idt.S + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.S + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.S + ${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/tss.S + ${CMAKE_SOURCE_DIR}/mentos/src/boot.S ${CMAKE_SOURCE_DIR}/libc/src/crt0.S ) endif (DOXYGEN_FOUND) \ No newline at end of file diff --git a/libc/inc/err.h b/libc/inc/err.h index 0a60d3a5..803f0444 100644 --- a/libc/inc/err.h +++ b/libc/inc/err.h @@ -7,14 +7,51 @@ #include -/// @brief Print formatted error message on stderr and exit -/// @param eval The exit value. -/// @param fmt The format string. +/// @brief Print a formatted error message on stderr and exit the program. +/// +/// @details This function prints an error message to stderr, formatted +/// according to the given format string, followed by a system error message if +/// applicable. It then terminates the program with the specified exit value. +/// This is typically used when a system call fails. +/// +/// @param eval The exit value to use when terminating the program. +/// @param fmt The format string for the error message. void err(int eval, const char *fmt, ...); + +/// @brief Print a formatted error message on stderr using a va_list and exit +/// the program. +/// +/// @details This function is similar to `err()`, but accepts a `va_list` to +/// support variable arguments. This allows you to pass a list of arguments that +/// can be formatted into the error message. The program exits with the +/// specified exit value. +/// +/// @param eval The exit value to use when terminating the program. +/// @param fmt The format string for the error message. +/// @param args The variable argument list. void verr(int eval, const char *fmt, va_list args); -/// @brief Print formatted message on stderr without appending an error message and exit -/// @param eval The exit value. -/// @param fmt The format string. +/// @brief Print a formatted message on stderr without appending an error +/// message and exit. +/// +/// @details This function prints a formatted message to stderr without +/// appending a system error message (such as those related to errno). It then +/// terminates the program with the specified exit value. This is useful when +/// the error isn't related to a system call failure but requires exiting the +/// program. +/// +/// @param eval The exit value to use when terminating the program. +/// @param fmt The format string for the message. void errx(int eval, const char *fmt, ...); + +/// @brief Print a formatted message on stderr using a va_list and exit without +/// appending an error message. +/// +/// @details This function is similar to `errx()`, but accepts a `va_list` to +/// handle variable arguments. It prints the formatted message and exits the +/// program without appending a system error message. +/// +/// @param eval The exit value to use when terminating the program. +/// @param fmt The format string for the message. +/// @param args The variable argument list. void verrx(int eval, const char *fmt, va_list args); diff --git a/libc/inc/shadow.h b/libc/inc/shadow.h index 5f6dd645..f39f5e4f 100644 --- a/libc/inc/shadow.h +++ b/libc/inc/shadow.h @@ -1,22 +1,52 @@ -// @file shadow.h -/// @brief Secret password file routines +/// @file shadow.h +/// @brief Defines structures and functions for working with the shadow password +/// file. +/// @copyright (c) 2014-2024 This file is distributed under the MIT License. +/// See LICENSE.md for details. + #pragma once #include "stddef.h" -#define SHADOW "/etc/shadow" +#define SHADOW "/etc/shadow" ///< Path to the shadow password file. +/// @brief Structure representing a shadow password record. +/// @details This structure is used to store details from the shadow password +/// file (`/etc/shadow`), including information such as the user's encrypted +/// password and password change policies. struct spwd { - char *sp_namp; ///< user login name. - char *sp_pwdp; ///< encrypted password. - long int sp_lstchg; ///< last password change. - long int sp_min; ///< days until change allowed. - long int sp_max; ///< days before change required. - long int sp_warn; ///< days warning for expiration. - long int sp_inact; ///< days before account inactive. - long int sp_expire; ///< date when account expires. - unsigned long int sp_flag; ///< reserved for future use. + char *sp_namp; ///< User login name. + char *sp_pwdp; ///< Encrypted password. + long int sp_lstchg; ///< Date of the last password change, in days since the epoch. + long int sp_min; ///< Minimum number of days until the next password change is allowed. + long int sp_max; ///< Maximum number of days before a password change is required. + long int sp_warn; ///< Number of days before the password expires to warn the user. + long int sp_inact; ///< Number of days after expiration until the account is considered inactive. + long int sp_expire; ///< Date when the account expires, in days since the epoch. + unsigned long int sp_flag; ///< Reserved for future use. }; -struct spwd *getspnam(const char *); -int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **); +/// @brief Retrieves a shadow password record by username. +/// +/// @details This function retrieves the shadow password entry for a specific +/// user from the shadow password file (`/etc/shadow`). It uses a static buffer +/// to store the result, which is overwritten on each call. +/// +/// @param name The login name of the user to search for. +/// @return Pointer to the `spwd` structure with the user's shadow password entry, or NULL if not found. +struct spwd *getspnam(const char * name); + +/// @brief Retrieves a shadow password record by username (reentrant version). +/// +/// @details This function retrieves the shadow password entry for a specific +/// user in a reentrant manner. It stores the result in user-provided buffers to +/// avoid race conditions. This is the safer, thread-safe version of +/// `getspnam()`. +/// +/// @param name The login name of the user to search for. +/// @param spwd_buf Pointer to a user-provided `spwd` structure where the result will be stored. +/// @param buf Buffer to hold additional string data like the encrypted password. +/// @param buflen Size of the buffer provided. +/// @param result Pointer to the result. On success, this will point to `spwd_buf`, or NULL on failure. +/// @return 0 on success, or a non-zero error code on failure. +int getspnam_r(const char *name, struct spwd *spwd_buf, char *buf, size_t buflen, struct spwd **result); diff --git a/libc/inc/sys/mman.h b/libc/inc/sys/mman.h index 0dc897f0..5d33fdd3 100644 --- a/libc/inc/sys/mman.h +++ b/libc/inc/sys/mman.h @@ -14,8 +14,6 @@ #define MAP_SHARED 0x01 ///< The memory is shared. #define MAP_PRIVATE 0x02 ///< The memory is private. -#ifndef __KERNEL__ - /// @brief creates a new mapping in the virtual address space of the calling process. /// @param addr the starting address for the new mapping. /// @param length specifies the length of the mapping (which must be greater than 0). @@ -31,23 +29,3 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) /// @param length the length of the mapped area. /// @return 0 on success, -1 on falure and errno is set. int munmap(void *addr, size_t length); - -#else - -/// @brief creates a new mapping in the virtual address space of the calling process. -/// @param addr the starting address for the new mapping. -/// @param length specifies the length of the mapping (which must be greater than 0). -/// @param prot describes the desired memory protection of the mapping (and must not conflict with the open mode of the file). -/// @param flags determines whether updates to the mapping are visible to other processes mapping the same region. -/// @param fd in case of file mapping, the file descriptor to use. -/// @param offset offset in the file, which must be a multiple of the page size PAGE_SIZE. -/// @return returns a pointer to the mapped area, -1 and errno is set. -void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); - -/// @brief deletes the mappings for the specified address range. -/// @param addr the starting address. -/// @param length the length of the mapped area. -/// @return 0 on success, -1 on falure and errno is set. -int sys_munmap(void *addr, size_t length); - -#endif diff --git a/libc/inc/sys/sem.h b/libc/inc/sys/sem.h index 451c8d9b..a6a6929d 100644 --- a/libc/inc/sys/sem.h +++ b/libc/inc/sys/sem.h @@ -26,8 +26,9 @@ #define SEM_STAT 18 ///< Return a semid_ds structure. #define SEM_INFO 19 ///< Return a seminfo structure. -/// }@ +/// @} +/// @brief Defines the maximum number of semaphores in a semaphore set. #define SEM_SET_MAX 256 /// @brief Optional argument for semctl() function diff --git a/libc/src/shadow.c b/libc/src/shadow.c index 9ff32ce3..91c1c0e0 100644 --- a/libc/src/shadow.c +++ b/libc/src/shadow.c @@ -1,7 +1,8 @@ /// @file shadow.c -/// @brief +/// @brief Functions for handling the shadow password file (`/etc/shadow`). /// @copyright (c) 2005-2020 Rich Felker, et al. /// This file is based on the code from libmusl. + #include #include #include @@ -12,103 +13,126 @@ #include #include +/// Defines the buffer size for reading lines from the shadow file. +#define LINE_LIM 256 + +/// @brief Converts a string to a long integer. +/// +/// @details Parses a string into a long integer and advances the string pointer. +/// If the string starts with a colon or newline, returns -1. +/// +/// @param s Pointer to the string to convert. +/// @return The parsed long integer. static long xatol(char **s) { - long x; - if (**s == ':' || **s == '\n') return -1; - for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); - return x; + long x; + if (**s == ':' || **s == '\n') return -1; + for (x = 0; **s - '0' < 10U; ++*s) x = 10 * x + (**s - '0'); + return x; } +/// @brief Parses a shadow password entry from a string. +/// +/// @details This function parses a line from the shadow password file into a `spwd` structure. +/// The fields in the shadow password file are separated by colons. +/// +/// @param s The string containing the shadow password entry. +/// @param sp Pointer to the `spwd` structure where the parsed data will be stored. +/// @return 0 on success, -1 on failure. int __parsespent(char *s, struct spwd *sp) { - sp->sp_namp = s; - if (!(s = strchr(s, ':'))) return -1; - *s = 0; - - sp->sp_pwdp = ++s; - if (!(s = strchr(s, ':'))) return -1; - *s = 0; - - s++; sp->sp_lstchg = xatol(&s); - if (*s != ':') return -1; - - s++; sp->sp_min = xatol(&s); - if (*s != ':') return -1; - - s++; sp->sp_max = xatol(&s); - if (*s != ':') return -1; - - s++; sp->sp_warn = xatol(&s); - if (*s != ':') return -1; - - s++; sp->sp_inact = xatol(&s); - if (*s != ':') return -1; - - s++; sp->sp_expire = xatol(&s); - if (*s != ':') return -1; - - s++; sp->sp_flag = xatol(&s); - if (*s != '\n') return -1; - return 0; + sp->sp_namp = s; + if (!(s = strchr(s, ':'))) return -1; + *s = 0; + + sp->sp_pwdp = ++s; + if (!(s = strchr(s, ':'))) return -1; + *s = 0; + + s++; + sp->sp_lstchg = xatol(&s); + if (*s != ':') return -1; + + s++; + sp->sp_min = xatol(&s); + if (*s != ':') return -1; + + s++; + sp->sp_max = xatol(&s); + if (*s != ':') return -1; + + s++; + sp->sp_warn = xatol(&s); + if (*s != ':') return -1; + + s++; + sp->sp_inact = xatol(&s); + if (*s != ':') return -1; + + s++; + sp->sp_expire = xatol(&s); + if (*s != ':') return -1; + + s++; + sp->sp_flag = xatol(&s); + if (*s != '\n') return -1; + return 0; } -int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct spwd **res) +struct spwd *getspnam(const char *name) { - char path[20+NAME_MAX]; - int rv = 0; - int fd; - size_t k, l = strlen(name); - int skip = 0; - int cs; - int orig_errno = errno; - - *res = 0; - - /* Disallow potentially-malicious user names */ - if (*name=='.' || strchr(name, '/') || !l) - return errno = EINVAL; - - /* Buffer size must at least be able to hold name, plus some.. */ - if (size < l+100) - return errno = ERANGE; - - fd = open(SHADOW, O_RDONLY, 0); - if (fd < 0) { - return errno; - } - - while (fgets(buf, size, fd) && (k=strlen(buf))>0) { - if (skip || strncmp(name, buf, l) || buf[l]!=':') { - skip = buf[k-1] != '\n'; - continue; - } - if (buf[k-1] != '\n') { - rv = ERANGE; - break; - } - - if (__parsespent(buf, sp) < 0) continue; - *res = sp; - break; - } - errno = rv ? rv : orig_errno; - return rv; + static struct spwd spwd_buf; + static char *line; + struct spwd *result; + int e; + int orig_errno = errno; + + if (!line) line = malloc(LINE_LIM); + if (!line) return 0; + e = getspnam_r(name, &spwd_buf, line, LINE_LIM, &result); + errno = e ? e : orig_errno; + return result; } -#define LINE_LIM 256 - -struct spwd *getspnam(const char *name) +int getspnam_r(const char *name, struct spwd *spwd_buf, char *buf, size_t buflen, struct spwd **result) { - static struct spwd sp; - static char *line; - struct spwd *res; - int e; - int orig_errno = errno; - - if (!line) line = malloc(LINE_LIM); - if (!line) return 0; - e = getspnam_r(name, &sp, line, LINE_LIM, &res); - errno = e ? e : orig_errno; - return res; + char path[20 + NAME_MAX]; + int rv = 0; + int fd; + size_t k, l = strlen(name); + int skip = 0; + int cs; + int orig_errno = errno; + + *result = 0; + + /* Disallow potentially-malicious user names */ + if (*name == '.' || strchr(name, '/') || !l) + return errno = EINVAL; + + /* Buffer size must at least be able to hold name, plus some.. */ + if (buflen < l + 100) + return errno = ERANGE; + + fd = open(SHADOW, O_RDONLY, 0); + if (fd < 0) { + return errno; + } + + while (fgets(buf, buflen, fd) && (k = strlen(buf)) > 0) { + if (skip || strncmp(name, buf, l) || buf[l] != ':') { + skip = buf[k - 1] != '\n'; + continue; + } + if (buf[k - 1] != '\n') { + rv = ERANGE; + break; + } + + if (__parsespent(buf, spwd_buf) < 0) continue; + *result = spwd_buf; + break; + } + errno = rv ? rv : orig_errno; + return rv; } diff --git a/libc/src/sys/ipc.c b/libc/src/sys/ipc.c index 2ac03097..58c04d46 100644 --- a/libc/src/sys/ipc.c +++ b/libc/src/sys/ipc.c @@ -5,19 +5,12 @@ #include "sys/ipc.h" -#include "io/debug.h" -#include "io/debug.h" -#include "stddef.h" -#include "stdio.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" -#include "sys/errno.h" -#include "sys/msg.h" -#include "sys/sem.h" #include "sys/shm.h" +#include "sys/sem.h" +#include "sys/msg.h" +#include "sys/errno.h" #include "sys/stat.h" -#include "sys/unistd.h" +#include "io/debug.h" #include "system/syscall_types.h" _syscall3(void *, shmat, int, shmid, const void *, shmaddr, int, shmflg) diff --git a/mentos/inc/fs/attr.h b/mentos/inc/fs/attr.h index 384d4505..73c67da7 100644 --- a/mentos/inc/fs/attr.h +++ b/mentos/inc/fs/attr.h @@ -1,16 +1,55 @@ /// @file attr.h -/// @brief change file attributes +/// @brief Change file attributes. +/// @details This header provides declarations for system calls that handle file +/// ownership and permissions, such as changing the owner, group, and mode of +/// files or file descriptors. /// @copyright (c) 2024 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "stddef.h" -int sys_chown(const char* path, uid_t owner, gid_t group); +/// @brief Change the owner and group of a file by path. It modifies the file's +/// ownership attributes to the provided `owner` and `group`. +/// +/// @param path Path to the file. +/// @param owner The user ID of the new owner. +/// @param group The group ID of the new group. +/// @return 0 on success, or -1 on error. +int sys_chown(const char *path, uid_t owner, gid_t group); -int sys_lchown(const char* path, uid_t owner, gid_t group); +/// @brief Change the owner and group of a symbolic link. It modifies the +/// symbolic link's ownership attributes to the provided `owner` and `group`. +/// This does not follow symbolic links, modifying only the link itself. +/// +/// @param path Path to the symbolic link. +/// @param owner The user ID of the new owner. +/// @param group The group ID of the new group. +/// @return 0 on success, or -1 on error. +int sys_lchown(const char *path, uid_t owner, gid_t group); +/// @brief Change the owner and group of a file by file descriptor. It modifies +/// the file's ownership attributes to the provided `owner` and `group`. +/// +/// @param fd File descriptor referring to the file. +/// @param owner The user ID of the new owner. +/// @param group The group ID of the new group. +/// @return 0 on success, or -1 on error. int sys_fchown(int fd, uid_t owner, gid_t group); -int sys_chmod(const char* path, mode_t mode); +/// @brief Change the mode (permissions) of a file by path. It modifies the +/// file's permissions to the provided `mode`, determining the file's access +/// permissions. +/// +/// @param path Path to the file. +/// @param mode The new file mode (permissions). +/// @return 0 on success, or -1 on error. +int sys_chmod(const char *path, mode_t mode); +/// @brief Change the mode (permissions) of a file by file descriptor. It +/// modifies the file's permissions to the provided `mode`, determining the +/// file's access permissions. +/// +/// @param fd File descriptor referring to the file. +/// @param mode The new file mode (permissions). +/// @return 0 on success, or -1 on error. int sys_fchmod(int fd, mode_t mode); diff --git a/mentos/inc/fs/namei.h b/mentos/inc/fs/namei.h index 116ade9b..189852df 100644 --- a/mentos/inc/fs/namei.h +++ b/mentos/inc/fs/namei.h @@ -1,5 +1,8 @@ /// @file namei.h -/// @brief Headers for path resolution +/// @brief Headers for path resolution. +/// @details This header provides definitions and function declarations for +/// resolving paths, including symbolic links and handling different flags that +/// control the behavior of the path resolution process. /// @copyright (c) 2024 This file is distributed under the MIT License. /// See LICENSE.md for details. @@ -7,11 +10,20 @@ #include "stddef.h" +/// Flag to remove any trailing slash from the path. #define REMOVE_TRAILING_SLASH 1 << 0 -#define FOLLOW_LINKS 1 << 1 -#define CREAT_LAST_COMPONENT 1 << 2 +/// Flag to follow symbolic links during path resolution. +#define FOLLOW_LINKS 1 << 1 +/// Flag to create the last component of the path if it doesn't exist. +#define CREAT_LAST_COMPONENT 1 << 2 /// @brief Resolve the given path by following all symbolic links. +/// +/// @details This function resolves a file path, following any symbolic links +/// encountered along the way, and returns the absolute path. The behavior can +/// be controlled with flags such as whether to follow symbolic links and how to +/// handle trailing slashes. +/// /// @param path The path to resolve, can include symbolic links. /// @param buffer The buffer where the resolved absolute path will be stored. /// @param buflen The size of the buffer, which should be large enough to hold the resolved path. diff --git a/mentos/inc/ipc/ipc.h b/mentos/inc/ipc/ipc.h index 422645fc..36fe2594 100644 --- a/mentos/inc/ipc/ipc.h +++ b/mentos/inc/ipc/ipc.h @@ -11,15 +11,23 @@ #error "How did you include this file... include `libc/inc/sys/ipc.h` instead!" #endif +/// @brief Validate IPC permissions based on flags and the given permission structure. +/// @param flags Flags that control the validation behavior. +/// @param perm Pointer to the IPC permission structure to validate. +/// @return 0 if the permissions are valid, or a non-zero value on failure. int ipc_valid_permissions(int flags, struct ipc_perm *perm); +/// @brief Register an IPC resource with a given key and mode. +/// @param key The key associated with the IPC resource. +/// @param mode The mode (permissions) for the IPC resource. +/// @return A `struct ipc_perm` representing the registered IPC resource. struct ipc_perm register_ipc(key_t key, mode_t mode); /// @brief Initializes the semaphore system. /// @return 0 on success, 1 on failure. int sem_init(void); -/// @brief Initializes the shared memory. +/// @brief Initializes the shared memory system. /// @return 0 on success, 1 on failure. int shm_init(void); diff --git a/mentos/inc/system/syscall.h b/mentos/inc/system/syscall.h index 3367da18..ca91c4cc 100644 --- a/mentos/inc/system/syscall.h +++ b/mentos/inc/system/syscall.h @@ -363,3 +363,19 @@ ssize_t sys_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) /// @param buf used with IPC_STAT and IPC_SET. /// @return 0 on success, -1 on failure and errno is set to indicate the error. int sys_msgctl(int msqid, int cmd, struct msqid_ds *buf); + +/// @brief creates a new mapping in the virtual address space of the calling process. +/// @param addr the starting address for the new mapping. +/// @param length specifies the length of the mapping (which must be greater than 0). +/// @param prot describes the desired memory protection of the mapping (and must not conflict with the open mode of the file). +/// @param flags determines whether updates to the mapping are visible to other processes mapping the same region. +/// @param fd in case of file mapping, the file descriptor to use. +/// @param offset offset in the file, which must be a multiple of the page size PAGE_SIZE. +/// @return returns a pointer to the mapped area, -1 and errno is set. +void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); + +/// @brief deletes the mappings for the specified address range. +/// @param addr the starting address. +/// @param length the length of the mapped area. +/// @return 0 on success, -1 on falure and errno is set. +int sys_munmap(void *addr, size_t length); diff --git a/mentos/src/fs/attr.c b/mentos/src/fs/attr.c index 13314200..9db3b78c 100644 --- a/mentos/src/fs/attr.c +++ b/mentos/src/fs/attr.c @@ -17,58 +17,78 @@ #include "system/printk.h" #include "system/syscall.h" -static int __setattr(const char *path, struct iattr* attr, bool_t follow_links) { - // Allocate a variable for the path. +/// @brief Sets attributes on a file or directory. +/// +/// @param path The path of the file or directory whose attributes are to be set. +/// @param attr A pointer to the iattr structure containing the attributes to set. +/// @param follow_links A flag to indicate whether symbolic links should be followed. +/// @return 0 on success, or an appropriate error code on failure. +static int __setattr(const char *path, struct iattr *attr, bool_t follow_links) +{ + // Allocate a variable for the resolved absolute path. char absolute_path[PATH_MAX]; - int ret = resolve_path(path, absolute_path, sizeof(absolute_path), follow_links ? FOLLOW_LINKS: 0); + // Resolve the path to its absolute form, optionally following symbolic links. + int ret = resolve_path(path, absolute_path, sizeof(absolute_path), follow_links ? FOLLOW_LINKS : 0); if (ret < 0) { - pr_err("__setattr(%s): Cannot get the absolute path.", path); - return ret; + pr_err("__setattr(%s): Cannot resolve the absolute path\n", path); + return ret; // Return the error from resolve_path. } - + // Retrieve the superblock for the resolved absolute path. super_block_t *sb = vfs_get_superblock(absolute_path); if (sb == NULL) { - pr_err("do_chown(%s): Cannot find the superblock!\n", absolute_path); - return -ENOENT; + pr_err("__setattr(%s): Cannot find the superblock!\n", absolute_path); + return -ENOENT; // Return error if superblock is not found. } + // Retrieve the root of the superblock. vfs_file_t *sb_root = sb->root; if (sb_root == NULL) { - pr_err("do_chown(%s): Cannot find the superblock root!\n", absolute_path); - return -ENOENT; + pr_err("__setattr(%s): Cannot find the superblock root!\n", absolute_path); + return -ENOENT; // Return error if the superblock root is not found. } - - // Check if the function is implemented. + // Check if the setattr operation is supported by the filesystem. if (sb_root->sys_operations->setattr_f == NULL) { - pr_err("setattr(%s): Function not supported in current filesystem.", absolute_path); - return -ENOSYS; + pr_err("__setattr(%s): Function not supported in current filesystem\n", absolute_path); + return -ENOSYS; // Return error if setattr is not implemented. } + // Call the setattr operation with the resolved absolute path and attribute. return sb_root->sys_operations->setattr_f(absolute_path, attr); } -static inline void __iattr_set_owner_or_group(struct iattr *attr, uid_t owner, gid_t group) { - if (owner != -1) { - attr->ia_valid |= ATTR_UID; - attr->ia_uid = owner; - } - if (group != -1) { - attr->ia_valid |= ATTR_GID; - attr->ia_gid = group; +/// @brief Sets the owner and/or group in the iattr structure. +/// +/// @param attr A pointer to the iattr structure to update. +/// @param owner The new owner UID to set (use `-1` to leave unchanged). +/// @param group The new group GID to set (use `-1` to leave unchanged). +static inline void __iattr_set_owner_or_group(struct iattr *attr, uid_t owner, gid_t group) +{ + // Set the owner UID if the provided owner is not -1. + if (owner != (uid_t)-1) { + attr->ia_valid |= ATTR_UID; // Mark the UID as valid. + attr->ia_uid = owner; // Set the UID. + } + // Set the group GID if the provided group is not -1. + if (group != (gid_t)-1) { + attr->ia_valid |= ATTR_GID; // Mark the GID as valid. + attr->ia_gid = group; // Set the GID. } } -int sys_chown(const char* path, uid_t owner, gid_t group) { - struct iattr attr = {0}; +int sys_chown(const char *path, uid_t owner, gid_t group) +{ + struct iattr attr = { 0 }; __iattr_set_owner_or_group(&attr, owner, group); return __setattr(path, &attr, true); } -int sys_lchown(const char* path, uid_t owner, gid_t group) { - struct iattr attr = {0}; +int sys_lchown(const char *path, uid_t owner, gid_t group) +{ + struct iattr attr = { 0 }; __iattr_set_owner_or_group(&attr, owner, group); return __setattr(path, &attr, false); } -int sys_fchown(int fd, uid_t owner, gid_t group) { +int sys_fchown(int fd, uid_t owner, gid_t group) +{ task_struct *task = scheduler_get_current_process(); // Check the current FD. @@ -98,17 +118,19 @@ int sys_fchown(int fd, uid_t owner, gid_t group) { pr_err("No setattr function found for the current filesystem.\n"); return -ENOSYS; } - struct iattr attr = {0}; + struct iattr attr = { 0 }; __iattr_set_owner_or_group(&attr, owner, group); return file->fs_operations->setattr_f(file, &attr); } -int sys_chmod(const char* path, mode_t mode) { +int sys_chmod(const char *path, mode_t mode) +{ struct iattr attr = IATTR_CHMOD(mode); return __setattr(path, &attr, true); } -int sys_fchmod(int fd, mode_t mode) { +int sys_fchmod(int fd, mode_t mode) +{ task_struct *task = scheduler_get_current_process(); // Check the current FD. diff --git a/mentos/src/io/proc_feedback.c b/mentos/src/io/proc_feedback.c index 95fb2f52..2eff31c3 100644 --- a/mentos/src/io/proc_feedback.c +++ b/mentos/src/io/proc_feedback.c @@ -9,15 +9,28 @@ #include "string.h" #include "sys/errno.h" +/// @brief Reads data from the /proc/feedback file. +/// +/// @param file A pointer to the vfs_file_t structure representing the file to read from. +/// @param buf A buffer to store the read data (unused in this example). +/// @param offset The offset from where the read operation should begin (unused in this example). +/// @param nbyte The number of bytes to read (unused in this example). +/// @return Always returns 0 on success, or -ENOENT if the file is NULL. static ssize_t procfb_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte) { + // Check if the file pointer is NULL. if (!file) { - pr_err("Received a NULL file.\n"); - return -ENOENT; + pr_err("procfb_read: Received a NULL file.\n"); + return -ENOENT; // Return an error if the file is NULL. } + + // Check if the file name matches "/proc/feedback". if (!strcmp(file->name, "/proc/feedback")) { - pr_alert("Return scheduling feedback information.\n"); + pr_alert("procfb_read: Returning scheduling feedback information.\n"); + // TODO: Add logic to return actual feedback information here. } + + // Return 0 to indicate success. return 0; } diff --git a/mentos/src/io/video.c b/mentos/src/io/video.c index 4c8d7d1a..20be4e0b 100644 --- a/mentos/src/io/video.c +++ b/mentos/src/io/video.c @@ -222,7 +222,9 @@ static inline void __move_cursor_forward(int erase, int amount) video_update_cursor_position(); } -void __parse_cursor_escape_code(int shape) +/// @brief Parses the cursor shape escape code and sets the cursor shape accordingly. +/// @param shape The integer representing the cursor shape code. +static inline void __parse_cursor_escape_code(int shape) { switch (shape) { case 0: // Default blinking block cursor diff --git a/mentos/src/ipc/ipc.c b/mentos/src/ipc/ipc.c index 6076bbfd..e480e6d1 100644 --- a/mentos/src/ipc/ipc.c +++ b/mentos/src/ipc/ipc.c @@ -11,16 +11,32 @@ #include "io/debug.h" #include "process/scheduler.h" -int ipc_check_perm( +/// @brief Checks IPC permissions for a task. +/// @param task Pointer to the task structure. +/// @param perm Pointer to the IPC permissions structure. +/// @param usr Permission flag for user. +/// @param grp Permission flag for group. +/// @param oth Permission flag for others. +/// @return 1 if permissions are granted, 0 otherwise. +static inline int ipc_check_perm( task_struct *task, struct ipc_perm *perm, int usr, int grp, int oth) { - assert(task && "Received a NULL task."); - assert(perm && "Received a NULL perm."); + // Check if task is NULL. + if (!task) { + pr_err("Received a NULL task.\n"); + return 0; + } + // Check if perm is NULL. + if (!perm) { + pr_err("Received a NULL perm.\n"); + return 0; + } int check_parent = (perm->key < 0) && task->parent && (task->parent->pid != 0); + // Check user permissions. if (perm->mode & usr) { if ((perm->uid == task->uid) || (perm->cuid == task->uid)) { return 1; @@ -29,6 +45,7 @@ int ipc_check_perm( return 1; } } + // Check group permissions. if (perm->mode & grp) { if ((perm->gid == task->gid) || (perm->cgid == task->gid)) { return 1; @@ -37,6 +54,7 @@ int ipc_check_perm( return 1; } } + // Check other permissions. if (perm->mode & oth) { if (check_parent && ((perm->uid != task->parent->uid) || (perm->cuid != task->parent->uid))) { return 1; @@ -45,6 +63,7 @@ int ipc_check_perm( return 1; } } + // No permissions granted. return 0; } diff --git a/mentos/src/ipc/shm.c b/mentos/src/ipc/shm.c index 5c25fc6d..7dd7a06e 100644 --- a/mentos/src/ipc/shm.c +++ b/mentos/src/ipc/shm.c @@ -2,7 +2,6 @@ /// @brief /// @copyright (c) 2014-2024 This file is distributed under the MIT License. /// See LICENSE.md for details. -///! @cond Doxygen_Suppress // ============================================================================ // Setup the logging for this file (do this before any other include). @@ -29,15 +28,15 @@ ///@brief A value to compute the shmid value. int __shm_id = 0; -// @brief Shared memory management structure. +/// @brief Shared memory management structure. typedef struct { - /// @brief ID associated to the shared memory. + /// @brief Shared memory ID. int id; - /// @brief The shared memory data strcutre. + /// @brief Shared memory data structure. struct shmid_ds shmid; - /// Where shm created is memorized. + /// @brief Location where shared memory is stored. page_t *shm_location; - /// Reference inside the list of shared memory management structures. + /// @brief List reference for shared memory structures. list_head list; } shm_info_t; @@ -48,19 +47,23 @@ list_head shm_list; // MEMORY MANAGEMENT (Private) // ============================================================================ -/// @brief Allocates the memory for shared memory structure. -/// @param key IPC_KEY associated with the shared memory. -/// @param shmflg flags used to create the shared memory. -/// @return a pointer to the allocated shared memory structure. +/// @brief Allocates memory for a shared memory structure. +/// @param key IPC key associated with the shared memory. +/// @param size Size of the shared memory segment. +/// @param shmflg Flags used to create the shared memory. +/// @return Pointer to the allocated shared memory structure, or NULL on failure. static inline shm_info_t *__shm_info_alloc(key_t key, size_t size, int shmflg) { - // Allocate the memory. + // Allocate memory for shm_info_t. shm_info_t *shm_info = (shm_info_t *)kmalloc(sizeof(shm_info_t)); - // Check the allocated memory. - assert(shm_info && "Failed to allocate memory for a shared memory structure."); - // Clean the memory. + // Check if memory allocation for shm_info failed. + if (!shm_info) { + pr_err("Failed to allocate memory for shared memory structure.\n"); + return NULL; + } + // Initialize the allocated memory to zero. memset(shm_info, 0, sizeof(shm_info_t)); - // Initialize its values. + // Initialize shm_info values. shm_info->id = ++__shm_id; shm_info->shmid.shm_perm = register_ipc(key, shmflg & 0x1FF); shm_info->shmid.shm_segsz = size; @@ -70,10 +73,17 @@ static inline shm_info_t *__shm_info_alloc(key_t key, size_t size, int shmflg) shm_info->shmid.shm_cpid = 0; shm_info->shmid.shm_lpid = 0; shm_info->shmid.shm_nattch = 0; - // Allocate the memory. - uint32_t order = find_nearest_order_greater(0, size); + // Determine the order for memory allocation. + uint32_t order = find_nearest_order_greater(0, size); + // Allocate the shared memory pages. shm_info->shm_location = _alloc_pages(GFP_KERNEL, order); - // Return the shared memory structure. + // Check if memory allocation for shm_location failed. + if (!shm_info->shm_location) { + pr_err("Failed to allocate shared memory pages.\n"); + kfree(shm_info); + return NULL; + } + // Return the allocated shared memory structure. return shm_info; } @@ -149,15 +159,21 @@ static inline shm_info_t *__list_find_shm_info_by_page(page_t *page) return NULL; } +/// @brief Adds a shared memory info structure to the list. +/// @param shm_info Pointer to the shared memory info structure. static inline void __list_add_shm_info(shm_info_t *shm_info) { + // Check if shm_info is NULL. assert(shm_info && "Received a NULL pointer."); // Add the new item at the end. list_head_insert_before(&shm_info->list, &shm_list); } +/// @brief Removes a shared memory info structure from the list. +/// @param shm_info Pointer to the shared memory info structure. static inline void __list_remove_shm_info(shm_info_t *shm_info) { + // Check if shm_info is NULL. assert(shm_info && "Received a NULL pointer."); // Delete the item from the list. list_head_remove(&shm_info->list); @@ -184,6 +200,9 @@ long sys_shmget(key_t key, size_t size, int shmflg) } while (__list_find_shm_info_by_key(key)); // We have a unique key, create the shared memory. shm_info = __shm_info_alloc(key, size, shmflg); + if (!shm_info) { + return -ENOENT; + } // Add the shared memory to the list. __list_add_shm_info(shm_info); } else { @@ -209,6 +228,9 @@ long sys_shmget(key_t key, size_t size, int shmflg) if (shm_info == NULL) { // Create the shared memory. shm_info = __shm_info_alloc(key, size, shmflg); + if (!shm_info) { + return -ENOENT; + } // Add the shared memory to the list. __list_add_shm_info(shm_info); } @@ -339,28 +361,38 @@ long sys_shmctl(int shmid, int cmd, struct shmid_ds *buf) // PROCFS FUNCTIONS // ============================================================================ +/// @brief Reads data from a shared memory segment. +/// @param file Pointer to the file structure associated with the shared memory. +/// @param buf Buffer where the read data will be stored. +/// @param offset Offset from where to start reading. +/// @param nbyte Number of bytes to read. +/// @return Number of bytes read on success, or -1 on error. ssize_t procipc_shm_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte) { + // Check if file is NULL. if (!file) { pr_err("Received a NULL file.\n"); return -ENOENT; } + size_t buffer_len = 0, read_pos = 0, ret = 0; ssize_t write_count = 0; shm_info_t *shm_info = NULL; char buffer[BUFSIZ]; - // Prepare a buffer. + // Prepare a buffer and initialize it to zero. memset(buffer, 0, BUFSIZ); + // Prepare the header. ret = sprintf(buffer, "key shmid perms segsz uid gid cuid cgid atime dtime ctime cpid lpid nattch\n"); // Iterate through the list of shared memory. list_for_each_decl(it, &shm_list) { - // Get the current entry. + // Get the current entry from the list. shm_info = list_entry(it, shm_info_t, list); - // Add the line. + + // Add information about the current shared memory entry to the buffer. ret += sprintf( buffer + ret, "%8d %5d %10d %7d %5d %4d %5d %9d %10d %10d %10d %5d %5d %5d\n", abs(shm_info->shmid.shm_perm.key), @@ -378,19 +410,24 @@ ssize_t procipc_shm_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte shm_info->shmid.shm_lpid, shm_info->shmid.shm_nattch); } + + // Terminate the buffer with a newline. sprintf(buffer + ret, "\n"); - // Perform read. + // Get the length of the buffer. buffer_len = strlen(buffer); read_pos = offset; + + // Perform the read operation if offset is within bounds. if (read_pos < buffer_len) { while ((write_count < nbyte) && (read_pos < buffer_len)) { buf[write_count] = buffer[read_pos]; // Move the pointers. - ++read_pos, ++write_count; + ++read_pos; + ++write_count; } } + + // Return the number of bytes read. return write_count; } - -///! @endcond diff --git a/mentos/src/ipc/shm.old.c b/mentos/src/ipc/shm.old.c deleted file mode 100644 index 85013753..00000000 --- a/mentos/src/ipc/shm.old.c +++ /dev/null @@ -1,495 +0,0 @@ -/// @file shm.c -/// @brief -/// @copyright (c) 2014-2024 This file is distributed under the MIT License. -/// See LICENSE.md for details. -///! @cond Doxygen_Suppress - -// ============================================================================ -// Setup the logging for this file (do this before any other include). -#include "sys/kernel_levels.h" // Include kernel log levels. -#define __DEBUG_HEADER__ "[IPCshm]" ///< Change header. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. -#include "io/debug.h" // Include debugging functions. -// ============================================================================ - -#include "ipc/ipc.h" -#include "sys/shm.h" - -#include "assert.h" -#include "mem/kheap.h" -#include "stdio.h" -#include "string.h" -#include "sys/errno.h" -#include "sys/list_head.h" - -// #include "process/process.h" - -///@brief A value to compute the shmid value. -int __shm_id = 0; - -// @brief Shared memory management structure. -typedef struct { - /// @brief ID associated to the shared memory. - int id; - /// @brief The shared memory data strcutre. - struct shmid_ds shmid; - /// Where shm created is memorized. - void *shm_location; - /// Reference inside the list of shared memory management structures. - list_head list; -} shm_info_t; - -/// @brief List of all current active shared memorys. -list_head shm_list; - -// ============================================================================ -// MEMORY MANAGEMENT (Private) -// ============================================================================ - -/// @brief Allocates the memory for shared memory structure. -/// @param key IPC_KEY associated with the shared memory. -/// @param shmflg flags used to create the shared memory. -/// @return a pointer to the allocated shared memory structure. -static inline shm_info_t *__shm_info_alloc(key_t key, size_t size, int shmflg) -{ - // Allocate the memory. - shm_info_t *shm_info = (shm_info_t *)kmalloc(sizeof(shm_info_t)); - // Check the allocated memory. - assert(shm_info && "Failed to allocate memory for a shared memory structure."); - // Clean the memory. - memset(shm_info, 0, sizeof(shm_info_t)); - // Initialize its values. - shm_info->id = ++__shm_id; - shm_info->shmid.shm_perm = register_ipc(key, shmflg & 0x1FF); - shm_info->shmid.shm_segsz = size; - shm_info->shmid.shm_atime = 0; - shm_info->shmid.shm_dtime = 0; - shm_info->shmid.shm_ctime = 0; - shm_info->shmid.shm_cpid = 0; - shm_info->shmid.shm_lpid = 0; - shm_info->shmid.shm_nattch = 0; - // Return the shared memory structure. - return shm_info; -} - -/// @brief Frees the memory of a shared memory structure. -/// @param shm_info pointer to the shared memory structure. -static inline void __shm_info_dealloc(shm_info_t *shm_info) -{ - assert(shm_info && "Received a NULL pointer."); - // Deallocate the shmid memory. - kfree(shm_info); -} - -#if 0 -struct shmid_ds *head = NULL; -static ushort shm_descriptor = 0; - -int syscall_shmctl(int *args) -{ - int shmid = args[0]; - int cmd = args[1]; - - // TODO: for IPC_STAT - // struct shmid_ds * buf = (struct shmid_ds *) args[2]; - - struct shmid_ds *myshmid_ds = find_shm_fromid(shmid); - - if (myshmid_ds == NULL) { - return -1; - } - - // Upgrade shm info. - myshmid_ds->shm_lpid = scheduler_get_current_process()->pid; - myshmid_ds->shm_ctime = time(NULL); - - switch (cmd) { - case IPC_RMID: - if (myshmid_ds->shm_nattch == 0) { - kfree(myshmid_ds->shm_location); - - // Manage list. - if (myshmid_ds == head) { - head = head->next; - } else { - // Finding the previous shmid_ds. - struct shmid_ds *prev = head; - while (prev->next != myshmid_ds) { - prev = prev->next; - } - prev->next = myshmid_ds->next; - } - kfree(myshmid_ds); - } else { - (myshmid_ds->shm_perm).mode |= SHM_DEST; - } - - return 0; - - case IPC_STAT: - break; - case IPC_SET: - break; - case SHM_LOCK: - break; - case SHM_UNLOCK: - break; - default: - break; - } - - return -1; -} - -// Get shared memory segment. -int syscall_shmget(int *args) -{ - int flags = args[2]; - key_t key = (key_t)args[0]; - size_t size = (size_t)args[1]; - - struct shmid_ds *shmid_ds; - - if (flags & IPC_EXCL) { - return -1; - } - - if (flags & IPC_CREAT) { - shmid_ds = find_shm_fromkey(key); - - if (shmid_ds != NULL) { - return -1; - } - - shmid_ds = kmalloc(sizeof(struct shmid_ds)); - pr_default("\n[SHM] shmget() shmid_ds : 0x%p", shmid_ds); - - shmid_ds->shm_location = kmalloc_align(size); - pr_default("\n[SHM] shmget() Location : 0x%p", - shmid_ds->shm_location); - pr_default("\n[SHM] shmget() physLocation : 0x%p", - paging_virtual_to_physical(get_current_page_directory(), - shmid_ds->shm_location)); - - shmid_ds->next = head; - head = shmid_ds; - - shmid_ds->shm_segsz = size; - shmid_ds->shm_atime = 0; - shmid_ds->shm_dtime = 0; - shmid_ds->shm_ctime = 0; - shmid_ds->shm_cpid = scheduler_get_current_process()->pid; - shmid_ds->shm_lpid = scheduler_get_current_process()->pid; - shmid_ds->shm_nattch = 0; - - // No user implementation. - (shmid_ds->shm_perm).cuid = 0; - // No group implementation. - (shmid_ds->shm_perm).cgid = 0; - // No user implementation - (shmid_ds->shm_perm).uid = 0; - // No group implementation. - (shmid_ds->shm_perm).gid = 0; - (shmid_ds->shm_perm).mode = flags & 0777; - (shmid_ds->shm_perm).seq = shm_descriptor++; - (shmid_ds->shm_perm).key = key; - } else { - shmid_ds = find_shm_fromkey(key); - pr_default("\n[SHM] shmget() shmid_ds found : 0x%p", shmid_ds); - - if (shmid_ds == NULL) { - return -1; - } - - if ((flags & 0777) > ((shmid_ds->shm_perm).mode & 0777)) { - return -1; - } - shmid_ds->shm_lpid = scheduler_get_current_process()->pid; - } - - return (shmid_ds->shm_perm).seq; -} - -// Attach shared memory segment. -void *syscall_shmat(int *args) -{ - int shmid = args[0]; - void *shmaddr = (void *)args[1]; - - // TODO: for more settings - // int flags = args[2]; - - struct shmid_ds *myshmid_ds = find_shm_fromid(shmid); - pr_default("\n[SHM] shmat() shmid_ds found : 0x%p", myshmid_ds); - - if (myshmid_ds == NULL) { - return (void *)-1; - } - - void *shm_start = myshmid_ds->shm_location; - - if (shmaddr == NULL) { - void *ret = kmalloc_align(myshmid_ds->shm_segsz); - - uint32_t shm_vaddr_start = (uint32_t)ret & 0xfffff000; - uint32_t shm_vaddr_end = - ((uint32_t)ret + myshmid_ds->shm_segsz) & 0xfffff000; - - uint32_t shm_paddr_start = (uint32_t)paging_virtual_to_physical( - get_current_page_directory(), shm_start); - - free_map_region(get_current_page_directory(), shm_vaddr_start, - shm_vaddr_end, true); - - while (shm_vaddr_start <= shm_vaddr_end) { - paging_allocate_page(get_current_page_directory(), shm_vaddr_start, - shm_paddr_start / PAGE_SIZE, true, true); - shm_vaddr_start += PAGE_SIZE; - shm_paddr_start += PAGE_SIZE; - } - - pr_default("\n[SHM] shmat() vaddr : 0x%p", ret); - pr_default("\n[SHM] shmat() paddr : 0x%p", - (void *)shm_paddr_start); - pr_default("\n[SHM] shmat() paddr after map: 0x%p", - paging_virtual_to_physical(get_current_page_directory(), - ret)); - - // Upgrade shm info. - myshmid_ds->shm_lpid = scheduler_get_current_process()->pid; - (myshmid_ds->shm_nattch)++; - myshmid_ds->shm_atime = time(NULL); - - return ret; - } - - return (void *)-1; -} - -// Detach shared memory segment. -int syscall_shmdt(int *args) -{ - void *shmaddr = (void *)args[0]; - - if (shmaddr == NULL) { - return -1; - } - - struct shmid_ds *myshmid_ds = find_shm_fromvaddr(shmaddr); - pr_default("\n[SHM] shmdt() shmid_ds found : 0x%p", myshmid_ds); - - if (myshmid_ds == NULL) { - return -1; - } - - // ===== Test ============================================================== - uint32_t shm_vaddr_start = (uint32_t)shmaddr & 0xfffff000; - uint32_t shm_vaddr_end = - ((uint32_t)shmaddr + myshmid_ds->shm_segsz) & 0xfffff000; - - free_map_region(get_current_page_directory(), shm_vaddr_start, - shm_vaddr_end, false); - - while (shm_vaddr_start <= shm_vaddr_end) { - paging_allocate_page(get_current_page_directory(), shm_vaddr_start, - shm_vaddr_start / PAGE_SIZE, true, true); - shm_vaddr_start += PAGE_SIZE; - } - // ========================================================================= - - kfree(shmaddr); - - // Upgrade shm info. - myshmid_ds->shm_lpid = scheduler_get_current_process()->pid; - (myshmid_ds->shm_nattch)--; - myshmid_ds->shm_dtime = time(NULL); - - // Manage SHM_DEST flag on. - if (myshmid_ds->shm_nattch == 0 && (myshmid_ds->shm_perm).mode & SHM_DEST) { - kfree(myshmid_ds->shm_location); - - // Manage list. - if (myshmid_ds == head) { - head = head->next; - } else { - // Finding the previous shmid_ds. - struct shmid_ds *prev = head; - while (prev->next != myshmid_ds) { - prev = prev->next; - } - prev->next = myshmid_ds->next; - } - kfree(myshmid_ds); - } - - return 0; -} - -int shmctl(int shmid, int cmd, struct shmid_ds *buf) -{ - int error; - - __asm__("movl %0, %%ecx\n" - "movl %1, %%ebx\n" - "movl %2, %%edx\n" - "movl $6, %%eax\n" - "int $80\n" - : - : "r"(shmid), "r"(cmd), "r"(buf)); - __asm__("movl %%eax, %0\n\t" - : "=r"(error)); - - return error; -} - -int shmget(key_t key, size_t size, int flags) -{ - int id; - - __asm__("movl %0, %%ecx\n" - "movl %1, %%ebx\n" - "movl %2, %%edx\n" - "movl $3, %%eax\n" - "int $80\n" - : - : "r"(key), "r"(size), "r"(flags)); - __asm__("movl %%eax, %0\n\t" - : "=r"(id)); - - return id; -} - -void *shmat(int shmid, void *shmaddr, int flag) -{ - void *addr; - - __asm__("movl %0, %%ecx\n" - "movl %1, %%ebx\n" - "movl %2, %%edx\n" - "movl $4, %%eax\n" - "int $80\n" - : - : "r"(shmid), "r"(shmaddr), "r"(flag)); - // The kernel is serving my system call - - // Now I have the control - __asm__("movl %%eax, %0\n\t" - : "=r"(addr)); - - return addr; -} - -int shmdt(void *shmaddr) -{ - int error; - - __asm__("movl %0, %%ecx\n" - "movl $5, %%eax\n" - "int $80\n" - : - : "r"(shmaddr)); - __asm__("movl %%eax, %0\n\t" - : "=r"(error)); - - return error; -} - -struct shmid_ds *find_shm_fromid(int shmid) -{ - struct shmid_ds *res = head; - - while (res != NULL) { - if ((res->shm_perm).seq == shmid) { - return res; - } - res = res->next; - } - - return NULL; -} - -struct shmid_ds *find_shm_fromkey(key_t key) -{ - struct shmid_ds *res = head; - - while (res != NULL) { - if ((res->shm_perm).key == key) { - return res; - } - res = res->next; - } - - return NULL; -} - -struct shmid_ds *find_shm_fromvaddr(void *shmvaddr) -{ - void *shmpaddr = - paging_virtual_to_physical(get_current_page_directory(), shmvaddr); - void *paddr; - struct shmid_ds *res = head; - - while (res != NULL) { - paddr = paging_virtual_to_physical(get_current_page_directory(), - res->shm_location); - if (paddr == shmpaddr) { - return res; - } - res = res->next; - } - - return NULL; -} -#endif - -void *sys_shmat(int shmid, const void *shmaddr, int shmflg) -{ - return 0; -} - -int sys_shmget(key_t key, size_t size, int flag) -{ - return 0; -} - -long sys_shmdt(const void *shmaddr) -{ - return 0; -} - -long sys_shmctl(int shmid, int cmd, struct shmid_ds *buf) -{ - return 0; -} - -ssize_t procipc_shm_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte) -{ - if (!file) { - pr_err("Received a NULL file.\n"); - return -ENOENT; - } - size_t buffer_len = 0, read_pos = 0, write_count = 0, ret = 0; - char buffer[BUFSIZ]; - - // Prepare a buffer. - memset(buffer, 0, BUFSIZ); - // Prepare the header. - ret = sprintf(buffer, "key shmid ...\n"); - - // Implementation goes here... - sprintf(buffer + ret, "\n"); - - // Perform read. - buffer_len = strlen(buffer); - read_pos = offset; - if (read_pos < buffer_len) { - while ((write_count < nbyte) && (read_pos < buffer_len)) { - buf[write_count] = buffer[read_pos]; - // Move the pointers. - ++read_pos, ++write_count; - } - } - return write_count; -} - -///! @endcond diff --git a/mentos/src/process/scheduler_feedback.c b/mentos/src/process/scheduler_feedback.c index 01b7e8f1..d63c91bd 100644 --- a/mentos/src/process/scheduler_feedback.c +++ b/mentos/src/process/scheduler_feedback.c @@ -58,11 +58,16 @@ unsigned long next_log; /// session. size_t total_occurrences; -/// @brief A structure that keeps track of scheduling statistics. +/// @brief Structure that keeps track of scheduling statistics. struct statistic { + /// @brief Pointer to the task structure. task_struct *task; + /// @brief Number of times the task has been scheduled. unsigned long occur; -} arr_stats[PID_MAX_LIMIT]; +}; + +/// @brief Keeps track of scheduling statistics. +struct statistic arr_stats[PID_MAX_LIMIT]; /// @brief Updates when the logging should happen. static inline void __scheduler_feedback_deadline_advance(void)