Merge branch 'release/v0.6.0'
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
symbol-file ./mentos/kernel.bin
|
||||
exec-file ./mentos/kernel.bin
|
||||
target remote localhost:1234
|
||||
@@ -1,57 +0,0 @@
|
||||
name: MacOS
|
||||
on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- "releases/**"
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
- ".gitignore"
|
||||
- "ubuntu.yml"
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
- ".gitignore"
|
||||
- "ubuntu.yml"
|
||||
jobs:
|
||||
doxygen:
|
||||
name: Doxygen
|
||||
runs-on: macos-latest
|
||||
env:
|
||||
# We globally set CC and CXX.
|
||||
CC: x86_64-elf-gcc
|
||||
CXX: x86_64-elf-g++
|
||||
steps:
|
||||
- name: Clone repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
brew update
|
||||
brew install x86_64-elf-binutils x86_64-elf-gcc git cmake qemu nasm e2fsprogs doxygen
|
||||
|
||||
- name: Generate documentation
|
||||
run: |
|
||||
cmake -B build -D DOXYGEN_WARN_AS_ERROR=NO
|
||||
cmake --build build --target mentos_documentation
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: macos-latest
|
||||
# Set environment variables
|
||||
env:
|
||||
# We globally set CC and CXX.
|
||||
CC: x86_64-elf-gcc
|
||||
CXX: x86_64-elf-g++
|
||||
steps:
|
||||
- name: Clone repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
brew update
|
||||
brew install x86_64-elf-binutils x86_64-elf-gcc git cmake qemu nasm e2fsprogs
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -B build
|
||||
cmake --build build --parallel 2
|
||||
@@ -6,12 +6,14 @@ on:
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
- ".gitignore"
|
||||
- "macos.yml"
|
||||
- "**/macos.yml"
|
||||
- "**/windows.yml"
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- "**.md"
|
||||
- ".gitignore"
|
||||
- "macos.yml"
|
||||
- "**/macos.yml"
|
||||
- "**/windows.yml"
|
||||
jobs:
|
||||
doxygen:
|
||||
name: Doxygen
|
||||
@@ -19,73 +21,65 @@ jobs:
|
||||
steps:
|
||||
- name: Clone repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y doxygen nasm
|
||||
|
||||
- name: Generate documentation
|
||||
run: |
|
||||
cmake -B build -D DOXYGEN_WARN_AS_ERROR=NO
|
||||
cmake --build build --target mentos_documentation
|
||||
|
||||
build:
|
||||
name: Build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include: [
|
||||
# You can access the following values via ${{ matrix.??? }}
|
||||
#
|
||||
# pkgs : apt-get package names. It can include multiple package names which are delimited by space.
|
||||
# cc : C compiler executable.
|
||||
# cxx : C++ compiler executable for `make ctocpptest`.
|
||||
# x32 : Set 'true' if compiler supports x32. Otherwise, set 'false'.
|
||||
# Set 'fail' if it supports x32 but fails for now. 'fail' cases must be removed.
|
||||
# x86 : Set 'true' if compiler supports x86 (-m32). Otherwise, set 'false'.
|
||||
# Set 'fail' if it supports x86 but fails for now. 'fail' cases must be removed.
|
||||
# cxxtest : Set 'true' if it can be compiled as C++ code. Otherwise, set 'false'.
|
||||
# freestanding : Set 'true' if it can be compiled and execute freestanding code. Otherwise, set 'false'.
|
||||
# Usually, it requires Linux, x86_64 and gcc/g++.
|
||||
# os : GitHub Actions YAML workflow label. See https://github.com/actions/virtual-environments#available-environments
|
||||
# gcc
|
||||
{ pkgs: 'nasm', cc: gcc, cxx: g++, os: ubuntu-latest, },
|
||||
{ pkgs: 'gcc-12 g++-12 nasm', cc: gcc-12, cxx: g++-12, os: ubuntu-22.04, },
|
||||
{ pkgs: 'gcc-11 g++-11 nasm', cc: gcc-11, cxx: g++-11, os: ubuntu-22.04, },
|
||||
{ pkgs: 'gcc-10 g++-10 nasm', cc: gcc-10, cxx: g++-10, os: ubuntu-22.04, },
|
||||
{ pkgs: 'gcc-9 g++-9 nasm', cc: gcc-9, cxx: g++-9, os: ubuntu-22.04, },
|
||||
{ pkgs: 'gcc-8 g++-8 nasm', cc: gcc-8, cxx: g++-8, os: ubuntu-20.04, },
|
||||
{ pkgs: 'gcc-7 g++-7 nasm', cc: gcc-7, cxx: g++-7, os: ubuntu-20.04, },
|
||||
# clang
|
||||
{ pkgs: 'nasm', cc: clang, cxx: clang++, os: ubuntu-latest, },
|
||||
{ pkgs: 'clang-14 nasm', cc: clang-14, cxx: clang++-14, os: ubuntu-22.04, },
|
||||
{ pkgs: 'clang-13 nasm', cc: clang-13, cxx: clang++-13, os: ubuntu-22.04, },
|
||||
{ pkgs: 'clang-12 nasm', cc: clang-12, cxx: clang++-12, os: ubuntu-22.04, },
|
||||
{ pkgs: 'clang-11 nasm', cc: clang-11, cxx: clang++-11, os: ubuntu-22.04, },
|
||||
{ pkgs: 'clang-10 nasm', cc: clang-10, cxx: clang++-10, os: ubuntu-20.04, },
|
||||
{ pkgs: 'clang-9 nasm', cc: clang-9, cxx: clang++-9, os: ubuntu-20.04, },
|
||||
{ pkgs: 'clang-8 nasm', cc: clang-8, cxx: clang++-8, os: ubuntu-20.04, },
|
||||
{ pkgs: 'clang-7 nasm', cc: clang-7, cxx: clang++-7, os: ubuntu-20.04, },
|
||||
]
|
||||
|
||||
# You can access the following values via ${{ matrix.??? }}
|
||||
#
|
||||
# pkgs : apt-get package names. It can include multiple package names which are delimited by space.
|
||||
# cc : C compiler executable.
|
||||
# cxx : C++ compiler executable for `make ctocpptest`.
|
||||
# x32 : Set 'true' if compiler supports x32. Otherwise, set 'false'.
|
||||
# Set 'fail' if it supports x32 but fails for now. 'fail' cases must be removed.
|
||||
# x86 : Set 'true' if compiler supports x86 (-m32). Otherwise, set 'false'.
|
||||
# Set 'fail' if it supports x86 but fails for now. 'fail' cases must be removed.
|
||||
# cxxtest : Set 'true' if it can be compiled as C++ code. Otherwise, set 'false'.
|
||||
# freestanding : Set 'true' if it can be compiled and execute freestanding code. Otherwise, set 'false'.
|
||||
# Usually, it requires Linux, x86_64 and gcc/g++.
|
||||
# os : GitHub Actions YAML workflow label. See https://github.com/actions/virtual-environments#available-environments
|
||||
# gcc
|
||||
{ pkgs: "nasm", cc: gcc, cxx: g++, os: ubuntu-latest },
|
||||
{ pkgs: "gcc-12 g++-12 nasm", cc: gcc-12, cxx: g++-12, os: ubuntu-22.04 },
|
||||
{ pkgs: "gcc-11 g++-11 nasm", cc: gcc-11, cxx: g++-11, os: ubuntu-22.04 },
|
||||
{ pkgs: "gcc-10 g++-10 nasm", cc: gcc-10, cxx: g++-10, os: ubuntu-22.04 },
|
||||
{ pkgs: "gcc-9 g++-9 nasm", cc: gcc-9, cxx: g++-9, os: ubuntu-22.04 },
|
||||
{ pkgs: "gcc-8 g++-8 nasm", cc: gcc-8, cxx: g++-8, os: ubuntu-20.04 },
|
||||
{ pkgs: "gcc-7 g++-7 nasm", cc: gcc-7, cxx: g++-7, os: ubuntu-20.04 },
|
||||
# clang
|
||||
{ pkgs: "nasm", cc: clang, cxx: clang++, os: ubuntu-latest },
|
||||
{ pkgs: "clang-14 nasm", cc: clang-14, cxx: clang++-14, os: ubuntu-22.04 },
|
||||
{ pkgs: "clang-13 nasm", cc: clang-13, cxx: clang++-13, os: ubuntu-22.04 },
|
||||
{ pkgs: "clang-12 nasm", cc: clang-12, cxx: clang++-12, os: ubuntu-22.04 },
|
||||
{ pkgs: "clang-11 nasm", cc: clang-11, cxx: clang++-11, os: ubuntu-22.04 },
|
||||
{ pkgs: "clang-10 nasm", cc: clang-10, cxx: clang++-10, os: ubuntu-20.04 },
|
||||
{ pkgs: "clang-9 nasm", cc: clang-9, cxx: clang++-9, os: ubuntu-20.04 },
|
||||
{ pkgs: "clang-8 nasm", cc: clang-8, cxx: clang++-8, os: ubuntu-20.04 },
|
||||
{ pkgs: "clang-7 nasm", cc: clang-7, cxx: clang++-7, os: ubuntu-20.04 },
|
||||
]
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
# Set environment variables
|
||||
env:
|
||||
# We globally set CC and CXX.
|
||||
CC: ${{ matrix.cc }}
|
||||
CXX: ${{ matrix.cxx }}
|
||||
|
||||
steps:
|
||||
- name: Clone repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ${{ matrix.pkgs }}
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -B build
|
||||
|
||||
+2
-2
@@ -118,5 +118,5 @@ files/bin/**
|
||||
# ISO creation files.
|
||||
iso/boot/*.bin
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
# ClangD stuff.
|
||||
.cache
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "gdb",
|
||||
"request": "attach",
|
||||
"name": "(gdb) Attach",
|
||||
"target": "localhost:1234",
|
||||
"remote": true,
|
||||
"cwd": "${workspaceRoot}/build",
|
||||
"valuesFormatting": "parseText"
|
||||
}
|
||||
]
|
||||
}
|
||||
+104
-40
@@ -1,15 +1,13 @@
|
||||
# =============================================================================
|
||||
# PROJECT SETUP
|
||||
# =============================================================================
|
||||
|
||||
# Set the minimum required version of cmake.
|
||||
cmake_minimum_required(VERSION 3.1...3.22)
|
||||
#
|
||||
set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
|
||||
|
||||
# Initialize the project.
|
||||
project(mentos C ASM)
|
||||
|
||||
# =============================================================================
|
||||
# BUILD TYPE (Debug/Release)
|
||||
# =============================================================================
|
||||
|
||||
# Set the default build type to Debug.
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
message(STATUS "Setting build type to 'Debug' as none was specified.")
|
||||
@@ -17,12 +15,7 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
endif()
|
||||
|
||||
# =============================================================================
|
||||
# DOCUMENTATION
|
||||
# =============================================================================
|
||||
add_subdirectory(doc)
|
||||
|
||||
# =============================================================================
|
||||
# OS-SPECIFIC COMPILERS
|
||||
# OS-SPECIFIC COMPILERS SETUP
|
||||
# =============================================================================
|
||||
|
||||
# Add operating system specific option.
|
||||
@@ -63,7 +56,73 @@ else()
|
||||
endif()
|
||||
|
||||
# =============================================================================
|
||||
# COMPILATION
|
||||
# ASSEMBLY COMPILER
|
||||
# =============================================================================
|
||||
|
||||
# Find the NASM compiler.
|
||||
find_program(ASM_COMPILER NAMES nasm HINTS /usr/bin/ /usr/local/bin/)
|
||||
# Mark the variable ASM_COMPILER as advanced.
|
||||
mark_as_advanced(ASM_COMPILER)
|
||||
# Check that we have found the compiler.
|
||||
if(NOT ASM_COMPILER)
|
||||
message(FATAL_ERROR "ASM compiler not found!")
|
||||
endif(NOT ASM_COMPILER)
|
||||
# Set the asm compiler.
|
||||
set(CMAKE_ASM_COMPILER ${ASM_COMPILER})
|
||||
# Set the assembly compiler flags.
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -f elf -g -O0 -F dwarf -o <OBJECT> <SOURCE>")
|
||||
else()
|
||||
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -f elf -g -O3 -o <OBJECT> <SOURCE>")
|
||||
endif()
|
||||
|
||||
# =============================================================================
|
||||
# GLOBAL COMPILATION FLAGS
|
||||
# =============================================================================
|
||||
|
||||
# Warning flags.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
|
||||
# Disable some specific warnings.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-variable")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-command-line-argument")
|
||||
|
||||
# Set the compiler options.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdlib")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon")
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
||||
# Set the assembly compiler flags.
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32")
|
||||
|
||||
# =============================================================================
|
||||
# SUB-DIRECTORIES SETUP
|
||||
# =============================================================================
|
||||
|
||||
# Add the sub-directories.
|
||||
@@ -71,6 +130,7 @@ add_subdirectory(programs)
|
||||
add_subdirectory(programs/tests)
|
||||
add_subdirectory(mentos)
|
||||
add_subdirectory(libc)
|
||||
add_subdirectory(doc)
|
||||
|
||||
# =============================================================================
|
||||
# FILESYSTEM
|
||||
@@ -89,7 +149,7 @@ add_custom_target(filesystem
|
||||
COMMAND echo '============================================================================='
|
||||
COMMAND echo 'Done!'
|
||||
COMMAND echo '============================================================================='
|
||||
DEPENDS all_programs all_tests
|
||||
DEPENDS programs tests
|
||||
)
|
||||
|
||||
# =============================================================================
|
||||
@@ -126,18 +186,18 @@ set(EMULATOR_FLAGS ${EMULATOR_FLAGS} -vga std)
|
||||
# Set the amount of memory.
|
||||
set(EMULATOR_FLAGS ${EMULATOR_FLAGS} -m 1096M)
|
||||
# Set the EXT2 drive.
|
||||
set(EMULATOR_FLAGS ${EMULATOR_FLAGS} -drive file=${CMAKE_BINARY_DIR}/rootfs.img,format=raw)
|
||||
set(EMULATOR_FLAGS ${EMULATOR_FLAGS} -drive file=${CMAKE_BINARY_DIR}/rootfs.img,format=raw,index=0,media=disk)
|
||||
|
||||
# =============================================================================
|
||||
# Booting with QEMU for fun
|
||||
# =============================================================================
|
||||
|
||||
# This first target runs the emualtor passing the kernel binary file.
|
||||
# This first target runs the emulator passing the kernel binary file.
|
||||
add_custom_target(
|
||||
qemu
|
||||
COMMAND test -e ${CMAKE_BINARY_DIR}/rootfs.img || ${CMAKE_COMMAND} -E cmake_echo_color --red "No filesystem file detected, you need to run: make filesystem"
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -kernel ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin
|
||||
DEPENDS kernel-bootloader.bin
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -kernel ${CMAKE_BINARY_DIR}/mentos/bootloader.bin
|
||||
DEPENDS bootloader.bin
|
||||
)
|
||||
|
||||
# =============================================================================
|
||||
@@ -148,17 +208,19 @@ add_custom_target(
|
||||
# executables.
|
||||
add_custom_target(
|
||||
gdbinit
|
||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/scripts/get_text_address.sh ${CMAKE_BINARY_DIR}/mentos/kernel.bin > ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/scripts/get_text_address.sh ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/scripts/get_text_address.sh ${CMAKE_BINARY_DIR}/programs/tests/test_* >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/scripts/get_text_address.sh ${CMAKE_BINARY_DIR}/programs/prog_* >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND echo "break boot.c: boot_main" >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND echo "break kernel.c: kmain" >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND echo "target remote localhost:1234" >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
DEPENDS kernel-bootloader.bin
|
||||
DEPENDS all_programs
|
||||
DEPENDS all_tests
|
||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/gdb.run
|
||||
# Create the generic gdb configuration.
|
||||
COMMAND echo "add-symbol-file ${CMAKE_BINARY_DIR}/mentos/kernel.bin" > ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND echo "add-symbol-file ${CMAKE_BINARY_DIR}/mentos/bootloader.bin" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND find ${CMAKE_SOURCE_DIR}/files/bin -type f | xargs realpath | sed 's/^/add-symbol-file /' >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND echo "break boot.c: boot_main" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND echo "break kernel.c: kmain" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
# Create the GDB connection file.
|
||||
COMMAND echo "target remote localhost:1234" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/mentos/bootloader.bin
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/mentos/kernel.bin
|
||||
DEPENDS programs
|
||||
DEPENDS tests
|
||||
DEPENDS libc
|
||||
)
|
||||
|
||||
@@ -168,15 +230,17 @@ add_custom_target(
|
||||
add_custom_target(
|
||||
qemu-gdb
|
||||
COMMAND test -e ${CMAKE_BINARY_DIR}/rootfs.img || ${CMAKE_COMMAND} -E cmake_echo_color --red "No filesystem file detected, you need to run: make filesystem"
|
||||
COMMAND echo "\n\n"
|
||||
COMMAND echo "Now, QEMU has loaded the kernel, and it is waiting that you\n"
|
||||
COMMAND echo "remotely connect to it. To start debugging, open a new shell\n"
|
||||
COMMAND echo "in THIS same folder, and just type :\n"
|
||||
COMMAND printf " cgdb -q -iex %q" "add-auto-load-safe-path ."
|
||||
COMMAND echo "\n\n"
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -s -S -kernel ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin
|
||||
DEPENDS kernel-bootloader.bin
|
||||
DEPENDS .gdbinit
|
||||
COMMAND echo ""
|
||||
COMMAND echo "Now, QEMU has loaded the kernel, and it is waiting that you"
|
||||
COMMAND echo "remotely connect to it. To start debugging, open a new shell"
|
||||
COMMAND echo "in THIS same folder, and just type:"
|
||||
COMMAND echo " gdb --quiet --command=gdb.run"
|
||||
COMMAND echo "or if you want to use cgdb, type:"
|
||||
COMMAND echo " cgdb --quiet --command=gdb.run"
|
||||
COMMAND echo ""
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -s -S -kernel ${CMAKE_BINARY_DIR}/mentos/bootloader.bin
|
||||
DEPENDS bootloader.bin
|
||||
DEPENDS gdbinit
|
||||
)
|
||||
|
||||
# =============================================================================
|
||||
@@ -187,9 +251,9 @@ add_custom_target(
|
||||
add_custom_target(
|
||||
cdrom.iso
|
||||
COMMAND cp -rf ${CMAKE_SOURCE_DIR}/iso .
|
||||
COMMAND cp ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin ${CMAKE_BINARY_DIR}/iso/boot
|
||||
COMMAND cp ${CMAKE_BINARY_DIR}/mentos/bootloader.bin ${CMAKE_BINARY_DIR}/iso/boot
|
||||
COMMAND grub-mkrescue -o ${CMAKE_BINARY_DIR}/cdrom.iso ${CMAKE_BINARY_DIR}/iso
|
||||
DEPENDS kernel-bootloader.bin
|
||||
DEPENDS bootloader.bin
|
||||
)
|
||||
|
||||
# This third target runs the emualtor, but this time, the kernel binary file is
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2022 MentOs-Team.
|
||||
Copyright (c) 2014-2024 MentOs-Team.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -5,22 +5,29 @@
|
||||
[](https://forthebadge.com)
|
||||
|
||||
[](https://github.com/mentos-team/MentOS/actions/workflows/ubuntu.yml)
|
||||
[](https://github.com/mentos-team/MentOS/actions/workflows/macos.yml)
|
||||
|
||||
## Table of Contents
|
||||
|
||||
1. [What is MentOS](#1-what-is-mentos)
|
||||
2. [Implemented features](#2-implemented-features)
|
||||
3. [Prerequisites](#3-prerequisites)
|
||||
4. [Compiling MentOS](#4-compiling-mentos)
|
||||
5. [Generating the EXT2 filesystem](#5-generating-the-ext2-filesystem)
|
||||
6. [Running MentOS](#6-running-mentos)
|
||||
7. [Kernel logging](#7-kernel-logging)
|
||||
8. [Change the scheduling algorithm](#8-change-the-scheduling-algorithm)
|
||||
9. [Debugging the kernel](#9-debugging-the-kernel)
|
||||
10. [Contributors](#10-contributors)
|
||||
- [MentOS (Mentoring Operating System)](#mentos-mentoring-operating-system)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [What is MentOS](#what-is-mentos)
|
||||
- [Implemented features](#implemented-features)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Installing the prerequisites](#installing-the-prerequisites)
|
||||
- [Compiling MentOS](#compiling-mentos)
|
||||
- [Generating the EXT2 filesystem](#generating-the-ext2-filesystem)
|
||||
- [Running MentOS](#running-mentos)
|
||||
- [Running MentOS from GRUB](#running-mentos-from-grub)
|
||||
- [Running and adding new programs to MentOS](#running-and-adding-new-programs-to-mentos)
|
||||
- [Create a new program](#create-a-new-program)
|
||||
- [Add the new program to the list of compiled sources](#add-the-new-program-to-the-list-of-compiled-sources)
|
||||
- [Running a program or a test](#running-a-program-or-a-test)
|
||||
- [Kernel logging](#kernel-logging)
|
||||
- [Change the scheduling algorithm](#change-the-scheduling-algorithm)
|
||||
- [Debugging the kernel](#debugging-the-kernel)
|
||||
- [Contributors](#contributors)
|
||||
|
||||
## 1. What is MentOS
|
||||
## What is MentOS
|
||||
|
||||
MentOS (Mentoring Operating System) is an open source educational operating
|
||||
system. The goal of MentOS is to provide a project environment that is realistic
|
||||
@@ -44,7 +51,8 @@ Gualandri.
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 2. Implemented features
|
||||
## Implemented features
|
||||
|
||||
Follows the list of implemented features:
|
||||
|
||||
**Processes and Events**
|
||||
@@ -79,26 +87,28 @@ Follows the list of implemented features:
|
||||
- [x] Video drivers;
|
||||
- [ ] VGA drivers;
|
||||
|
||||
**Inter-Process Communication (IPC)**
|
||||
- [X] Semaphore
|
||||
- [ ] Message queue
|
||||
- [ ] Shared memory
|
||||
- [ ] Named pipe
|
||||
|
||||
I will try to keep it updated...
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 3. Prerequisites
|
||||
## Prerequisites
|
||||
|
||||
MentOS is compatible with the main **unix-based** operating systems. It has been
|
||||
tested with *Ubuntu*, *WSL1*, *WSL2*, and *MacOS*.
|
||||
tested with *Ubuntu*, and under Windows with *WSL1* and *WSL2*.
|
||||
|
||||
### 3.1. Generic Prerequisites
|
||||
For **compiling** the system we need:
|
||||
|
||||
#### 3.1.1. Compile
|
||||
|
||||
For compiling the system:
|
||||
|
||||
- nasm
|
||||
- git
|
||||
- gcc
|
||||
- nasm
|
||||
- make
|
||||
- cmake
|
||||
- git
|
||||
- ccmake (suggested)
|
||||
- e2fsprogs (should be already installed)
|
||||
|
||||
@@ -107,43 +117,29 @@ Under **MacOS**, for compiling, you have additional dependencies:
|
||||
- i386-elf-binutils
|
||||
- i386-elf-gcc
|
||||
|
||||
#### 3.1.2. Execute
|
||||
|
||||
To execute the operating system, you need to install:
|
||||
For **executing** the operating system we need:
|
||||
|
||||
- qemu-system-i386 (or qemu-system-x86)
|
||||
|
||||
#### 3.1.3. Debug
|
||||
|
||||
For debugging we suggest using:
|
||||
For **debugging** we suggest using:
|
||||
|
||||
- gdb or cgdb
|
||||
|
||||
### 3.2. installation Prerequisites
|
||||
### Installing the prerequisites
|
||||
|
||||
Under **Ubuntu**, you can type the following commands:
|
||||
|
||||
```bash
|
||||
sudo apt-get update && sudo apt-get upgrade -y
|
||||
sudo apt-get install -y build-essential git cmake qemu-system-x86 nasm e2fsprogs
|
||||
sudo apt-get install -y git build-essential nasm make cmake cmake-curses-gui e2fsprogs
|
||||
sudo apt-get install -y qemu-system-x86
|
||||
sudo apt-get install -y gdb cgdb
|
||||
```
|
||||
Note: Older versions might have `qemu-system-i386` instead of `qemu-system-x86`.
|
||||
|
||||
Under **MacOS** you also need to install the i386-elf cross-compiler. The
|
||||
simplest installation method is through Homebrew package manager.
|
||||
Install [Homebrew](https://brew.sh/index_it) if you don't already have it, and
|
||||
then type the following commands:
|
||||
|
||||
```bash
|
||||
brew update && brew upgrade
|
||||
brew install i386-elf-binutils i386-elf-gcc git cmake qemu nasm e2fsprogs
|
||||
brew install gdb cgdb #<- for debug only
|
||||
```
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 4. Compiling MentOS
|
||||
## Compiling MentOS
|
||||
|
||||
Compile MentOS with:
|
||||
|
||||
@@ -157,7 +153,7 @@ make
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 5. Generating the EXT2 filesystem
|
||||
## Generating the EXT2 filesystem
|
||||
|
||||
Generate the EXT2 filesystem with:
|
||||
|
||||
@@ -168,7 +164,7 @@ you just need to generate the filesystem once. If you change a `program` you nee
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 6. Running MentOS
|
||||
## Running MentOS
|
||||
|
||||
Boot MentOS with qemu:
|
||||
|
||||
@@ -180,11 +176,91 @@ To login, use one of the usernames listed in `files/etc/passwd`.
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 7. Kernel logging
|
||||
## Running MentOS from GRUB
|
||||
|
||||
For booting MentOS from GRUB in QEMU we need the following tools:
|
||||
|
||||
- xorriso
|
||||
- grub-mkrescue (from grub-common)
|
||||
|
||||
We also need `grub-pc-bin`, otherwise GRUB won't start in QEMU.
|
||||
|
||||
Which can be installed in Ubuntu with the following command:
|
||||
```bash
|
||||
sudo apt-get update && sudo apt-get upgrade -y
|
||||
sudo apt-get install -y grub-common grub-pc-bin xorriso
|
||||
```
|
||||
|
||||
Boot MentOS with qemu through GRUB by calling:
|
||||
|
||||
```bash
|
||||
make qemu-grub
|
||||
```
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## Running and adding new programs to MentOS
|
||||
|
||||
This section explains how to add a new program to MentOS, and also how to run programs in mentos. It also explains how to add new tests, which are located in the `programs/tests` folder.
|
||||
|
||||
### Create a new program
|
||||
|
||||
Head to the `programs` (or the `programs/tests`) folder. Create and open a new program, for instance a file called `hello_world.c`, with your preferred editor, and add this content to the file:
|
||||
```C
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("Hello, World!\n\n");
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Add the new program to the list of compiled sources
|
||||
Now we can add the program to the list of files which are compiled and placed inside MentOS filesystem.
|
||||
The following procedure is the same for both `programs` and `programs/tests`, what changes is which `CMakeLists.txt` file we modify.
|
||||
|
||||
You need to modify the `CMakeLists.txt` file, either `programs/CMakeLists.txt` or `programs/tests/CMakeLists.txt`, and add your program to the list of files to be compiled:
|
||||
```Makefile
|
||||
# Add the executables (manually).
|
||||
set(PROGRAMS
|
||||
init.c
|
||||
...
|
||||
hello_world.c
|
||||
)
|
||||
```
|
||||
or
|
||||
```Makefile
|
||||
# Add the executables (manually).
|
||||
set(TESTS
|
||||
t_mem.c
|
||||
...
|
||||
hello_world.c
|
||||
)
|
||||
```
|
||||
|
||||
That's it, the `hello_world.c` file will be compiled and will appear inside the `/bin` or `/bin/tests` folder of MentOS.
|
||||
|
||||
### Running a program or a test
|
||||
Once you login into MentOS, if you placed your source code in `programs`, you can execute the program by simply typing:
|
||||
```bash
|
||||
hello_world
|
||||
```
|
||||
because the file resides in `/bin`, and that folder is listed in the `PATH` environment variable.
|
||||
|
||||
Now, if you placed your source code inside the `programs/tests` folder, the executable will end up inside the `/bin/tests` folder.
|
||||
However, the `/bin/tests` folder is not listed in `PATH`, so, if you want to execute a test from that folder you need to specify the full path:
|
||||
```bash
|
||||
/bin/tests/hello_world
|
||||
```
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## Kernel logging
|
||||
The kernel provides ways of printing logging messages *from* inside the kernel code *to* the bash where you executed the `make qemu`.
|
||||
|
||||
These *logging* functions are:
|
||||
```C++
|
||||
```C
|
||||
#define pr_emerg(...)
|
||||
#define pr_alert(...)
|
||||
#define pr_crit(...)
|
||||
@@ -197,7 +273,7 @@ These *logging* functions are:
|
||||
```
|
||||
|
||||
You use them like you would use a `printf`:
|
||||
```C++
|
||||
```C
|
||||
if (fd < 0) {
|
||||
pr_err("Failed to open file '%s', received file descriptor %d.\n", filename, fd);
|
||||
return 1;
|
||||
@@ -207,7 +283,7 @@ You use them like you would use a `printf`:
|
||||
By default only message that goes from `pr_notice` included down to `pr_emerg` are displayed.
|
||||
|
||||
Each logging function (they are actually macros) is a wrapper that automatically sets the desired **log level**. Each log level is identified by a number, and declared as follows:
|
||||
```C++
|
||||
```C
|
||||
#define LOGLEVEL_DEFAULT (-1) ///< default-level messages.
|
||||
#define LOGLEVEL_EMERG 0 ///< system is unusable.
|
||||
#define LOGLEVEL_ALERT 1 ///< action must be taken immediately.
|
||||
@@ -220,19 +296,21 @@ Each logging function (they are actually macros) is a wrapper that automatically
|
||||
```
|
||||
|
||||
You can change the logging level by including the following lines at the beginning of your source code:
|
||||
```C++
|
||||
```C
|
||||
// Include the kernel log levels.
|
||||
#include "sys/kernel_levels.h"
|
||||
/// Change the header.
|
||||
#define __DEBUG_HEADER__ "[ATA ]"
|
||||
/// Set the log level.
|
||||
#define __DEBUG_LEVEL__ LOGLEVEL_INFO
|
||||
// Include the debuggin header.
|
||||
#include "io/debug.h"
|
||||
```
|
||||
This example sets the `__DEBUG_LEVEL__`, so that all the messages from `INFO` and below are shown. While `__DEBUG_HEADER__` is just a string that is automatically prepended to your message, helping you identifying from which code the message is coming from.
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 8. Change the scheduling algorithm
|
||||
## Change the scheduling algorithm
|
||||
|
||||
MentOS supports scheduling algorithms for aperiodic:
|
||||
|
||||
@@ -300,7 +378,7 @@ make qemu
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 9. Debugging the kernel
|
||||
## Debugging the kernel
|
||||
|
||||
If you want to use GDB to debug MentOS, first you need to compile everything:
|
||||
|
||||
@@ -322,7 +400,11 @@ make qemu-gdb
|
||||
|
||||
If you did everything correctly, you should see an empty QEMU window. Basically, QEMU is waiting for you to connect *remotely* with gdb. Anyway, running `make qemu-gdb` will make your current shell busy, you cannot call `gdb` in it. You need to open a new shell inside the `build` folder and do a:
|
||||
```bash
|
||||
cgdb -q -iex 'add-auto-load-safe-path .'
|
||||
gdb --quiet --command=gdb.run
|
||||
```
|
||||
or
|
||||
```bash
|
||||
cgdb --quiet --command=gdb.run
|
||||
```
|
||||
|
||||
Now you should have in front of you:
|
||||
@@ -351,9 +433,12 @@ Breakpoint 2, kmain (...) at .../mentos/src/kernel.c:95
|
||||
95 {
|
||||
```
|
||||
|
||||
There is also a launch configuration for vscode in `.vscode/launch.json`, called `(gdb) Attach`, which should allow you
|
||||
to connect to the running process.
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
## 10. Contributors
|
||||
## Contributors
|
||||
|
||||
Project Manager:
|
||||
|
||||
@@ -375,5 +460,9 @@ Developers:
|
||||
- Soft IRQs
|
||||
- Timer
|
||||
- Signals
|
||||
* And many other valuable contributors
|
||||
* [rouseabout](https://github.com/rouseabout)
|
||||
* [seekbytes](https://github.com/seekbytes)
|
||||
* [fischerling](https://github.com/fischerling)
|
||||
|
||||
*[Back to the Table of Contents](#table-of-contents)*
|
||||
|
||||
+277
-268
@@ -3,7 +3,7 @@ find_package(Doxygen)
|
||||
|
||||
if (DOXYGEN_FOUND)
|
||||
# Read the file with the version.
|
||||
file(READ ${PROJECT_SOURCE_DIR}/mentos/inc/version.h version_file)
|
||||
file(READ ${CMAKE_SOURCE_DIR}/mentos/inc/version.h version_file)
|
||||
# Extract the OS version.
|
||||
string(REGEX MATCH "OS_MAJOR_VERSION ([0-9]*)" _ ${version_file})
|
||||
set(OS_MAJOR_VERSION ${CMAKE_MATCH_1})
|
||||
@@ -15,276 +15,285 @@ if (DOXYGEN_FOUND)
|
||||
set(DOXYGEN_PROJECT_NAME "MentOS")
|
||||
set(DOXYGEN_PROJECT_NUMBER "${OS_MAJOR_VERSION}.${OS_MINOR_VERSION}.${OS_MICRO_VERSION}")
|
||||
set(DOXYGEN_PROJECT_BRIEF "The Mentoring Operating System")
|
||||
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${PROJECT_SOURCE_DIR}/README.md)
|
||||
set(DOXYGEN_IMAGE_PATH ${PROJECT_SOURCE_DIR}/doc/resources)
|
||||
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${CMAKE_SOURCE_DIR}/README.md)
|
||||
set(DOXYGEN_IMAGE_PATH ${CMAKE_SOURCE_DIR}/doc/resources)
|
||||
set(DOXYGEN_SHOW_INCLUDE_FILES NO)
|
||||
set(DOXYGEN_GENERATE_TREEVIEW NO)
|
||||
set(DOXYGEN_WARN_NO_PARAMDOC YES)
|
||||
set(DOXYGEN_HTML_STYLESHEET ${PROJECT_SOURCE_DIR}/doc/doxygen.css)
|
||||
|
||||
set(DOXYGEN_ENABLE_PREPROCESSING YES)
|
||||
set(DOXYGEN_EXTRACT_STATIC YES)
|
||||
set(DOXYGEN_MACRO_EXPANSION YES)
|
||||
set(DOXYGEN_EXPAND_ONLY_PREDEF YES)
|
||||
set(DOXYGEN_PREDEFINED "__attribute__((x))= _syscall0= _syscall0(x)= _syscall1(x)= _syscall2(x)= _syscall3(x)=")
|
||||
|
||||
set(DOXYGEN_WARN_FORMAT "$file($line): $text")
|
||||
set(DOXYGEN_HTML_STYLESHEET ${CMAKE_SOURCE_DIR}/doc/doxygen.css)
|
||||
doxygen_add_docs(
|
||||
${PROJECT_NAME}_documentation
|
||||
${PROJECT_SOURCE_DIR}/README.md
|
||||
${PROJECT_SOURCE_DIR}/CODING_STYLE.md
|
||||
${PROJECT_SOURCE_DIR}/LICENSE.md
|
||||
${PROJECT_SOURCE_DIR}/TODO.md
|
||||
${PROJECT_SOURCE_DIR}/doc/signal.md
|
||||
${PROJECT_SOURCE_DIR}/doc/syscall.md
|
||||
${PROJECT_SOURCE_DIR}/libc/src/crt0.S
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/array.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/assert.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/bits/ioctls.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/bits/stat.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/bits/termios-struct.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/ctype.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/debug.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/fcntl.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/fcvt.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/grp.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/io/mm_io.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/io/port_io.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/ipc/ipc.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/ipc/msg.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/ipc/sem.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/ipc/shm.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/libgen.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/limits.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/math.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/pwd.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/ring_buffer.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sched.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/signal.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/stdarg.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/stdbool.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/stddef.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/stdint.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/stdio.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/stdlib.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/strerror.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/string.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/bitops.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/dirent.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/errno.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/ioctl.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/reboot.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/stat.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/types.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/unistd.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/utsname.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/sys/wait.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/system/syscall_types.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/termios.h
|
||||
${PROJECT_SOURCE_DIR}/libc/inc/time.h
|
||||
${PROJECT_SOURCE_DIR}/libc/src/abort.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/assert.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/ctype.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/debug.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/fcvt.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/grp.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/io/mm_io.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/io/port_io.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/ipc/ipc.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/libc_start.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/libgen.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/math.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/pwd.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/sched.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/setenv.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/stdio.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/stdlib.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/strerror.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/string.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/sys/errno.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/sys/ioctl.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/sys/unistd.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/sys/utsname.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/termios.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/time.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/chdir.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/close.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/creat.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/exec.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/exit.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/fork.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getcwd.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getdents.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getgid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getpgid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getpid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getppid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getsid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/getuid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/interval.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/kill.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/lseek.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/mkdir.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/nice.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/open.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/read.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/reboot.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/rmdir.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/setgid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/setpgid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/setsid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/setuid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/signal.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/stat.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/unlink.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/waitpid.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/unistd/write.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/vscanf.c
|
||||
${PROJECT_SOURCE_DIR}/libc/src/vsprintf.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/boot.S
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/exception.S
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.S
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/idt.S
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.S
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/tss.S
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/process/user.S
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/boot.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/descriptor_tables/gdt.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/descriptor_tables/idt.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/descriptor_tables/isr.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/descriptor_tables/tss.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/devices/fpu.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/devices/pci.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/drivers/ata.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/drivers/fdc.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/drivers/keyboard/keyboard.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/drivers/keyboard/keymap.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/drivers/mouse.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/drivers/ps2.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/drivers/rtc.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/elf/elf.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/fs/ext2.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/fs/ioctl.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/fs/procfs.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/fs/vfs.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/fs/vfs_types.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/hardware/cpuid.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/hardware/pic8259.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/hardware/timer.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/debug.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/mm_io.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/port_io.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/proc_modules.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/vga/vga.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/vga/vga_font.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/vga/vga_mode.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/vga/vga_palette.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/io/video.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/kernel.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/compiler.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/hashmap.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/irqflags.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/list.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/list_head.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/mutex.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/ndtree.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/rbtree.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/spinlock.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/stack_helper.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/klib/stdatomic.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/link_access.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/mem/buddysystem.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/mem/gfp.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/mem/kheap.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/mem/paging.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/mem/slab.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/mem/vmem_map.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/mem/zone_allocator.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/multiboot.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/process/prio.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/process/process.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/process/scheduler.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/process/wait.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/proc_access.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/sys/errno.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/sys/ipc.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/sys/kernel_levels.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/sys/module.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/sys/reboot.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/sys/types.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/sys/utsname.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/system/panic.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/system/printk.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/system/signal.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/system/syscall.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/inc/version.h
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/boot.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/exception.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/idt.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/tss.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/devices/fpu.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/devices/pci.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/drivers/ata.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/drivers/fdc.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/drivers/keyboard/keyboard.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/drivers/keyboard/keymap.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/drivers/mouse.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/drivers/ps2.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/drivers/rtc.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/elf/elf.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/ext2.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/ioctl.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/namei.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/open.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/procfs.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/readdir.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/read_write.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/stat.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/fs/vfs.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/hardware/cpuid.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/hardware/pic8259.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/hardware/timer.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/debug.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/mm_io.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/port_io.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/proc_running.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/proc_system.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/proc_video.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/stdio.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/vga/vga.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/io/video.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/ipc/msg.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/ipc/sem.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/ipc/shm.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/kernel/sys.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/kernel.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/assert.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/ctype.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/fcvt.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/hashmap.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/libgen.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/list.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/math.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/mutex.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/ndtree.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/rbtree.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/spinlock.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/strerror.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/string.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/time.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/vscanf.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/klib/vsprintf.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/mem/buddysystem.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/mem/kheap.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/mem/paging.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/mem/slab.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/mem/vmem_map.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/mem/zone_allocator.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/multiboot.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/process/process.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/process/scheduler.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/process/scheduler_algorithm.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/process/wait.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/sys/module.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/sys/utsname.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/system/errno.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/system/panic.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/system/printk.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/system/signal.c
|
||||
${PROJECT_SOURCE_DIR}/mentos/src/system/syscall.c
|
||||
mentos_documentation
|
||||
${CMAKE_SOURCE_DIR}/README.md
|
||||
${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/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/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/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/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/sys/types.h
|
||||
${CMAKE_SOURCE_DIR}/mentos/inc/sys/utsname.h
|
||||
${CMAKE_SOURCE_DIR}/mentos/inc/system/panic.h
|
||||
${CMAKE_SOURCE_DIR}/mentos/inc/system/printk.h
|
||||
${CMAKE_SOURCE_DIR}/mentos/inc/system/signal.h
|
||||
${CMAKE_SOURCE_DIR}/mentos/inc/system/syscall.h
|
||||
${CMAKE_SOURCE_DIR}/mentos/inc/version.h
|
||||
|
||||
${CMAKE_SOURCE_DIR}/mentos/src/boot.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/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/ps2.c
|
||||
${CMAKE_SOURCE_DIR}/mentos/src/drivers/rtc.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/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/ipc/sem.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/fcvt.c
|
||||
${CMAKE_SOURCE_DIR}/mentos/src/klib/hashmap.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/mutex.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/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/sys/utsname.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/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}/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/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/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/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/read.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/reboot.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/waitpid.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/crt0.S
|
||||
)
|
||||
endif (DOXYGEN_FOUND)
|
||||
+11
-10
@@ -7,6 +7,7 @@ specifically:
|
||||
|
||||
1. Implemented
|
||||
2. Tested
|
||||
X. Obsolete
|
||||
|
||||
If the column is empty it means that it's not implemented yet.
|
||||
|
||||
@@ -22,7 +23,7 @@ If the column is empty it means that it's not implemented yet.
|
||||
2 | 5 | sys_open | fs/open.c | const char * | int | int | - | - |
|
||||
2 | 6 | sys_close | fs/open.c | int | - | - | - | - |
|
||||
2 | 7 | sys_waitpid | kernel/exit.c | pid_t | unsigned int * | int | - | - |
|
||||
| 8 | sys_creat | fs/open.c | const char * | int | - | - | - |
|
||||
2 | 8 | sys_creat | fs/open.c | const char * | int | - | - | - |
|
||||
| 9 | sys_link | fs/namei.c | const char * | const char * | - | - | - |
|
||||
2 | 10 | sys_unlink | fs/namei.c | const char * | - | - | - | - |
|
||||
2 | 11 | sys_execve | arch/i386/kernel/process.c | struct pt_regs | - | - | - | - |
|
||||
@@ -36,11 +37,11 @@ If the column is empty it means that it's not implemented yet.
|
||||
2 | 20 | sys_getpid | kernel/sched.c | - | - | - | - | - |
|
||||
| 21 | sys_mount | fs/super.c | char * | char * | char * | - | - |
|
||||
| 22 | sys_oldumount | fs/super.c | char * | - | - | - | - |
|
||||
| 23 | sys_setuid | kernel/sys.c | uid_t | - | - | - | - |
|
||||
| 24 | sys_getuid | kernel/sched.c | - | - | - | - | - |
|
||||
2 | 23 | sys_setuid | kernel/sys.c | uid_t | - | - | - | - |
|
||||
2 | 24 | sys_getuid | kernel/sched.c | - | - | - | - | - |
|
||||
| 25 | sys_stime | kernel/time.c | int * | - | - | - | - |
|
||||
| 26 | sys_ptrace | arch/i386/kernel/ptrace.c | long | long | long | long | - |
|
||||
| 27 | sys_alarm | kernel/sched.c | unsigned int | - | - | - | - |
|
||||
2 | 27 | sys_alarm | kernel/sched.c | unsigned int | - | - | - | - |
|
||||
2 | 28 | sys_fstat | fs/stat.c | unsigned int | struct __old_kernel_stat * | - | - | - |
|
||||
| 29 | sys_pause | arch/i386/kernel/sys_i386.c | - | - | - | - | - |
|
||||
| 30 | sys_utime | fs/open.c | char * | struct utimbuf * | - | - | - |
|
||||
@@ -55,8 +56,8 @@ If the column is empty it means that it's not implemented yet.
|
||||
| 42 | sys_pipe | arch/i386/kernel/sys_i386.c | unsigned long * | - | - | - | - |
|
||||
| 43 | sys_times | kernel/sys.c | struct tms * | - | - | - | - |
|
||||
2 | 45 | sys_brk | mm/mmap.c | unsigned long | - | - | - | - |
|
||||
| 46 | sys_setgid | kernel/sys.c | gid_t | - | - | - | - |
|
||||
| 47 | sys_getgid | kernel/sched.c | - | - | - | - | - |
|
||||
2 | 46 | sys_setgid | kernel/sys.c | gid_t | - | - | - | - |
|
||||
2 | 47 | sys_getgid | kernel/sched.c | - | - | - | - | - |
|
||||
1 | 48 | sys_signal | kernel/signal.c | int | __sighandler_t | - | - | - |
|
||||
| 49 | sys_geteuid | kernel/sched.c | - | - | - | - | - |
|
||||
| 50 | sys_getegid | kernel/sched.c | - | - | - | - | - |
|
||||
@@ -64,7 +65,7 @@ If the column is empty it means that it's not implemented yet.
|
||||
| 52 | sys_umount | fs/super.c | char * | int | - | - | - |
|
||||
1 | 54 | sys_ioctl | fs/ioctl.c | unsigned int | unsigned int | unsigned long | - | - |
|
||||
| 55 | sys_fcntl | fs/fcntl.c | unsigned int | unsigned int | unsigned long | - | - |
|
||||
| 57 | sys_setpgid | kernel/sys.c | pid_t | pid_t | - | - | - |
|
||||
2 | 57 | sys_setpgid | kernel/sys.c | pid_t | pid_t | - | - | - |
|
||||
| 59 | sys_olduname | arch/i386/kernel/sys_i386.c | struct oldold_utsname * | - | - | - | - |
|
||||
| 60 | sys_umask | kernel/sys.c | int | - | - | - | - |
|
||||
| 61 | sys_chroot | fs/open.c | const char * | - | - | - | - |
|
||||
@@ -72,10 +73,10 @@ If the column is empty it means that it's not implemented yet.
|
||||
| 63 | sys_dup2 | fs/fcntl.c | unsigned int | unsigned int | - | - | - |
|
||||
2 | 64 | sys_getppid | kernel/sched.c | - | - | - | - | - |
|
||||
| 65 | sys_getpgrp | kernel/sys.c | - | - | - | - | - |
|
||||
| 66 | sys_setsid | kernel/sys.c | - | - | - | - | - |
|
||||
2 | 66 | sys_setsid | kernel/sys.c | - | - | - | - | - |
|
||||
1 | 67 | sys_sigaction | arch/i386/kernel/signal.c | int | const struct old_sigaction * | struct old_sigaction * | - | - |
|
||||
| 68 | sys_sgetmask | kernel/signal.c | - | - | - | - | - |
|
||||
| 69 | sys_ssetmask | kernel/signal.c | int | - | - | - | - |
|
||||
X | 68 | sys_sgetmask | kernel/signal.c | - | - | - | - | - |
|
||||
X | 69 | sys_ssetmask | kernel/signal.c | int | - | - | - | - |
|
||||
| 70 | sys_setreuid | kernel/sys.c | uid_t | uid_t | - | - | - |
|
||||
| 71 | sys_setregid | kernel/sys.c | gid_t | gid_t | - | - | - |
|
||||
| 72 | sys_sigsuspend | arch/i386/kernel/signal.c | int | int | old_sigset_t | - | - |
|
||||
|
||||
+2
-3
@@ -1,9 +1,8 @@
|
||||
MentOS 0.1
|
||||
MentOS 0.6.0
|
||||
|
||||
Welcome to the MentOS, the Mentoring Operating System.
|
||||
|
||||
If you want some help enter the "help" command into the cli.
|
||||
If you want some help enter the "man" command into the cli.
|
||||
|
||||
Bye,
|
||||
The Ment(OS) Team
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
io ti vi bi!
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../README
|
||||
@@ -1 +0,0 @@
|
||||
tanto questa e' solo una prova :\
|
||||
@@ -1 +0,0 @@
|
||||
ciao mondo
|
||||
@@ -1,3 +0,0 @@
|
||||
come va ?
|
||||
AAA
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
bho, io credo bene eh eh eh
|
||||
@@ -1 +0,0 @@
|
||||
tanto questa e' solo una prova :\
|
||||
@@ -1 +0,0 @@
|
||||
io ti vi bi!
|
||||
@@ -0,0 +1,5 @@
|
||||
SYNOPSIS
|
||||
ipcs [options]
|
||||
|
||||
DESCRIPTION
|
||||
Ipcs shows information on System V inter-process communication facilities.
|
||||
@@ -0,0 +1,12 @@
|
||||
SYNOPSIS
|
||||
start [OPTIONS] [FILE]
|
||||
|
||||
DESCRIPTION
|
||||
Start a recording session aimed at displaying an ordered list of 50 items
|
||||
containing information about the processes that the CPU has just processed.
|
||||
|
||||
|
||||
OPTIONS
|
||||
-h: shows command help. //non funziona per ora lol
|
||||
-p: start the session with generated children
|
||||
-f [FILE]: start the session launching a specified program
|
||||
@@ -1,4 +1,4 @@
|
||||
set timeout=1
|
||||
set timeout=5
|
||||
set default=0
|
||||
|
||||
menuentry "MentOS" {
|
||||
|
||||
+67
-138
@@ -1,148 +1,77 @@
|
||||
# =============================================================================
|
||||
# Author: Enrico Fraccaroli
|
||||
# =============================================================================
|
||||
# Set the minimum required version of cmake.
|
||||
cmake_minimum_required(VERSION 3.1...3.22)
|
||||
# Initialize the project.
|
||||
project(libc C ASM)
|
||||
|
||||
# =============================================================================
|
||||
# ASSEMBLY
|
||||
# LIBRARY
|
||||
# =============================================================================
|
||||
|
||||
# Enable the assembly language.
|
||||
enable_language(ASM)
|
||||
# Find the NASM compiler.
|
||||
find_program(ASM_COMPILER NAMES nasm HINTS /usr/bin/ /usr/local/bin/)
|
||||
# Mark the variable ASM_COMPILER as advanced.
|
||||
mark_as_advanced(ASM_COMPILER)
|
||||
# Check that we have found the compiler.
|
||||
if(NOT ASM_COMPILER)
|
||||
message(FATAL_ERROR "ASM compiler not found!")
|
||||
endif(NOT ASM_COMPILER)
|
||||
# Set the asm compiler.
|
||||
set(CMAKE_ASM_COMPILER ${ASM_COMPILER})
|
||||
# Set the assembly compiler flags.
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -f elf")
|
||||
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <FLAGS> -o <OBJECT> <SOURCE>")
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -g")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O0")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -F dwarf")
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -g")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O3")
|
||||
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
||||
# =============================================================================
|
||||
# C WARNINGs
|
||||
# =============================================================================
|
||||
|
||||
# Warning flags.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
|
||||
# Disable some specific warnings.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-variable")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces")
|
||||
|
||||
# Set the compiler options.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdlib")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
||||
# =============================================================================
|
||||
# Add the library.
|
||||
add_library(
|
||||
${PROJECT_NAME}
|
||||
|
||||
${PROJECT_SOURCE_DIR}/src/stdio.c
|
||||
${PROJECT_SOURCE_DIR}/src/ctype.c
|
||||
${PROJECT_SOURCE_DIR}/src/string.c
|
||||
${PROJECT_SOURCE_DIR}/src/stdlib.c
|
||||
${PROJECT_SOURCE_DIR}/src/math.c
|
||||
${PROJECT_SOURCE_DIR}/src/fcvt.c
|
||||
${PROJECT_SOURCE_DIR}/src/time.c
|
||||
${PROJECT_SOURCE_DIR}/src/strerror.c
|
||||
${PROJECT_SOURCE_DIR}/src/termios.c
|
||||
${PROJECT_SOURCE_DIR}/src/libgen.c
|
||||
${PROJECT_SOURCE_DIR}/src/vsprintf.c
|
||||
${PROJECT_SOURCE_DIR}/src/vscanf.c
|
||||
${PROJECT_SOURCE_DIR}/src/pwd.c
|
||||
${PROJECT_SOURCE_DIR}/src/grp.c
|
||||
${PROJECT_SOURCE_DIR}/src/sched.c
|
||||
${PROJECT_SOURCE_DIR}/src/setenv.c
|
||||
${PROJECT_SOURCE_DIR}/src/assert.c
|
||||
${PROJECT_SOURCE_DIR}/src/abort.c
|
||||
${PROJECT_SOURCE_DIR}/src/io/mm_io.c
|
||||
${PROJECT_SOURCE_DIR}/src/io/port_io.c
|
||||
${PROJECT_SOURCE_DIR}/src/ipc/ipc.c
|
||||
${PROJECT_SOURCE_DIR}/src/sys/unistd.c
|
||||
${PROJECT_SOURCE_DIR}/src/sys/errno.c
|
||||
${PROJECT_SOURCE_DIR}/src/sys/utsname.c
|
||||
${PROJECT_SOURCE_DIR}/src/sys/ioctl.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/creat.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getppid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getpid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/exit.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/setsid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getsid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/setpgid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getpgid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/setgid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getgid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/setuid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getuid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/fork.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/read.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/write.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/exec.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/nice.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/open.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/reboot.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/waitpid.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/chdir.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getcwd.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/close.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/stat.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/rmdir.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/mkdir.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/unlink.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/getdents.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/lseek.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/kill.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/signal.c
|
||||
${PROJECT_SOURCE_DIR}/src/unistd/interval.c
|
||||
${PROJECT_SOURCE_DIR}/src/libc_start.c
|
||||
${PROJECT_SOURCE_DIR}/src/debug.c
|
||||
${PROJECT_SOURCE_DIR}/src/crt0.S
|
||||
libc
|
||||
${CMAKE_SOURCE_DIR}/libc/src/stdio.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/ctype.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/string.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/stdlib.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/math.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/fcvt.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/time.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/strerror.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/termios.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/libgen.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/vsprintf.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/vscanf.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/pwd.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/grp.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/sched.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/readline.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/setenv.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/assert.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/abort.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/io/mm_io.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/io/debug.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/sys/ipc.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/sys/unistd.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/sys/errno.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/sys/utsname.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/sys/mman.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/sys/ioctl.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/creat.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getppid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getpid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/exit.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/setsid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getsid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/setpgid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getpgid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/setgid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getgid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/setuid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getuid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/fork.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/read.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/write.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/exec.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/nice.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/open.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/reboot.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/waitpid.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/chdir.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getcwd.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/close.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/stat.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/rmdir.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/mkdir.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/unlink.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/getdents.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/lseek.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/kill.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/signal.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/interval.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/symlink.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/unistd/readlink.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/libc_start.c
|
||||
${CMAKE_SOURCE_DIR}/libc/src/crt0.S
|
||||
)
|
||||
|
||||
# Add the includes.
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC inc)
|
||||
target_include_directories(libc PUBLIC inc)
|
||||
|
||||
# Remove the 'lib' prefix.
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(libc PROPERTIES PREFIX "")
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
/// @file array.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -34,5 +34,5 @@
|
||||
ARRAY_FREE(arr->buffer); \
|
||||
}
|
||||
|
||||
#undef ARRAY_ALLOC malloc
|
||||
#undef ARRAY_FREE free
|
||||
#undef ARRAY_ALLOC
|
||||
#undef ARRAY_FREE
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file assert.h
|
||||
/// @brief Defines the function and pre-processor macro for assertions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file ioctls.h
|
||||
/// @brief Input/Output ConTroL (IOCTL) numbers.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file stat.h
|
||||
/// @brief Defines the structure used by the functiosn fstat(), lstat(), and stat().
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file termios-struct.h
|
||||
/// @brief Definition of the `termios` structure.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -43,4 +43,4 @@ typedef struct termios {
|
||||
#define IEXTEN 0x00000400 ///< Enables implementation-defined input processing.
|
||||
|
||||
/// @brief Mask for extracting control values.
|
||||
#define CTRL(x) (x & 037)
|
||||
#define CTRL(x) ((x) & 037)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file ctype.h
|
||||
/// @brief Functions related to character handling.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/// @file debug.h
|
||||
/// @brief Debugging primitives.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DEBUG_HEADER__
|
||||
/// Header for identifying outputs coming from a mechanism.
|
||||
#define __DEBUG_HEADER__
|
||||
#endif
|
||||
|
||||
/// @brief Extract the filename from the full path provided by __FILE__.
|
||||
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
/// @brief Prints the given character to debug output.
|
||||
/// @param c The character to print.
|
||||
void dbg_putchar(char c);
|
||||
|
||||
/// @brief Prints the given string to debug output.
|
||||
/// @param s The string to print.
|
||||
void dbg_puts(const char *s);
|
||||
|
||||
/// @brief Prints the given string to the debug output.
|
||||
/// @param file The name of the file.
|
||||
/// @param fun The name of the function.
|
||||
/// @param line The line inside the file.
|
||||
/// @param format The format to used, see printf.
|
||||
/// @param ... The list of arguments.
|
||||
void dbg_printf(const char *file, const char *fun, int line, const char *format, ...);
|
||||
|
||||
/// @brief Transforms the given amount of bytes to a readable string.
|
||||
/// @param bytes The bytes to turn to string.
|
||||
/// @return String representing the bytes in human readable form.
|
||||
const char *to_human_size(unsigned long bytes);
|
||||
|
||||
/// @brief Transforms the given value to a binary string.
|
||||
/// @param value to print.
|
||||
/// @param length of the binary output.
|
||||
/// @return String representing the binary value.
|
||||
const char *dec_to_binary(unsigned long value, unsigned length);
|
||||
|
||||
/// Prints a debugging message.
|
||||
#define pr_debug(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__ __VA_ARGS__)
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
/// @file fcntl.h
|
||||
/// @brief Headers of functions fcntl() and open().
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -22,18 +22,18 @@
|
||||
#define S_ISUID 0x0800 ///< Set user id on execution
|
||||
#define S_ISGID 0x0400 ///< Set group id on execution
|
||||
#define S_ISVTX 0x0200 ///< Save swapped text even after use (Sticky Bit)
|
||||
#define S_IRWXU 0x01C0 ///< rwx------- : User can read/write/execute
|
||||
#define S_IRUSR 0x0100 ///< -r-------- : User can read
|
||||
#define S_IWUSR 0x0080 ///< --w------- : User can write
|
||||
#define S_IXUSR 0x0040 ///< ---x------ : User can execute
|
||||
#define S_IRWXG 0x0038 ///< ----rwx--- : Group can read/write/execute
|
||||
#define S_IRGRP 0x0020 ///< ----r----- : Group can read
|
||||
#define S_IWGRP 0x0010 ///< -----w---- : Group can write
|
||||
#define S_IXGRP 0x0008 ///< ------x--- : Group can execute
|
||||
#define S_IRWXO 0x0007 ///< -------rwx : Others can read/write/execute
|
||||
#define S_IROTH 0x0004 ///< -------r-- : Others can read
|
||||
#define S_IWOTH 0x0002 ///< --------w- : Others can write
|
||||
#define S_IXOTH 0x0001 ///< ---------x : Others can execute
|
||||
#define S_IRWXU 0x01C0 ///< rwx------ : User can read/write/execute
|
||||
#define S_IRUSR 0x0100 ///< r-------- : User can read
|
||||
#define S_IWUSR 0x0080 ///< -w------- : User can write
|
||||
#define S_IXUSR 0x0040 ///< --x------ : User can execute
|
||||
#define S_IRWXG 0x0038 ///< ---rwx--- : Group can read/write/execute
|
||||
#define S_IRGRP 0x0020 ///< ---r----- : Group can read
|
||||
#define S_IWGRP 0x0010 ///< ----w---- : Group can write
|
||||
#define S_IXGRP 0x0008 ///< -----x--- : Group can execute
|
||||
#define S_IRWXO 0x0007 ///< ------rwx : Others can read/write/execute
|
||||
#define S_IROTH 0x0004 ///< ------r-- : Others can read
|
||||
#define S_IWOTH 0x0002 ///< -------w- : Others can write
|
||||
#define S_IXOTH 0x0001 ///< --------x : Others can execute
|
||||
|
||||
#define S_ISDIR(m) (((m)&0170000) == 0040000) ///< directory.
|
||||
#define S_ISCHR(m) (((m)&0170000) == 0020000) ///< char special
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file fcvt.h
|
||||
/// @brief Declare the functions required to turn double values into a string.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file grp.h
|
||||
/// @brief Defines the structures and functions for managing groups.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/// @file ansi_colors.h
|
||||
/// @author Enrico Fraccaroli (enry.frak@gmail.com)
|
||||
/// @brief Macros for ANSI colors.
|
||||
/// @brief List of ANSI colors.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
/// @file debug.h
|
||||
/// @brief Debugging primitives.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sys/kernel_levels.h"
|
||||
|
||||
struct pt_regs;
|
||||
|
||||
#ifndef __DEBUG_LEVEL__
|
||||
/// Defines the debug level.
|
||||
/// Defines the debug level, by default we set it to notice.
|
||||
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
|
||||
#endif
|
||||
|
||||
@@ -28,7 +26,7 @@ void set_log_level(int level);
|
||||
|
||||
/// @brief Returns the current loglevel.
|
||||
/// @return The current loglevel
|
||||
int get_log_level();
|
||||
int get_log_level(void);
|
||||
|
||||
/// @brief Prints the given character to debug output.
|
||||
/// @param c The character to print.
|
||||
@@ -39,17 +37,14 @@ void dbg_putchar(char c);
|
||||
void dbg_puts(const char *s);
|
||||
|
||||
/// @brief Prints the given string to the debug output.
|
||||
/// @param file The name of the file.
|
||||
/// @param fun The name of the function.
|
||||
/// @param line The line inside the file.
|
||||
/// @param header The header to print.
|
||||
/// @param format The format to used, see printf.
|
||||
/// @param ... The list of arguments.
|
||||
void dbg_printf(const char *file, const char *fun, int line, char *header, const char *format, ...);
|
||||
|
||||
/// @brief Prints the registers on debug output.
|
||||
/// @param frame Pointer to the register.
|
||||
void dbg_print_regs(struct pt_regs *frame);
|
||||
/// @param file the name of the file.
|
||||
/// @param fun the name of the function.
|
||||
/// @param line the line inside the file.
|
||||
/// @param header the header to print.
|
||||
/// @param log_level the log level.
|
||||
/// @param format the format to used, see printf.
|
||||
/// @param ... the list of arguments.
|
||||
void dbg_printf(const char *file, const char *fun, int line, char *header, short log_level, const char *format, ...);
|
||||
|
||||
/// @brief Transforms the given amount of bytes to a readable string.
|
||||
/// @param bytes The bytes to turn to string.
|
||||
@@ -62,53 +57,71 @@ const char *to_human_size(unsigned long bytes);
|
||||
/// @return String representing the binary value.
|
||||
const char *dec_to_binary(unsigned long value, unsigned length);
|
||||
|
||||
/// Prints a KERN_DEFAULT.
|
||||
#define pr_default(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_DEFAULT __VA_ARGS__)
|
||||
/// Prints a KERN_EMERG.
|
||||
/// Prints a default message, which is always shown.
|
||||
#define pr_default(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEFAULT, __VA_ARGS__)
|
||||
|
||||
/// Prints an emergency message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_EMERG
|
||||
#define pr_emerg(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_EMERG __VA_ARGS__)
|
||||
#define pr_emerg(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_EMERG, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_emerg(...)
|
||||
#endif
|
||||
/// Prints a KERN_ALERT.
|
||||
|
||||
/// Prints an alert message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_ALERT
|
||||
#define pr_alert(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_ALERT __VA_ARGS__)
|
||||
#define pr_alert(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ALERT, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_alert(...)
|
||||
#endif
|
||||
/// Prints a KERN_CRIT.
|
||||
|
||||
/// Prints a critical message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_CRIT
|
||||
#define pr_crit(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_CRIT __VA_ARGS__)
|
||||
#define pr_crit(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_CRIT, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_crit(...)
|
||||
#endif
|
||||
/// Prints a KERN_ERR.
|
||||
|
||||
/// Prints an error message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_ERR
|
||||
#define pr_err(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_ERR __VA_ARGS__)
|
||||
#define pr_err(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ERR, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_err(...)
|
||||
#endif
|
||||
/// Prints a KERN_WARNING.
|
||||
|
||||
/// Prints a warning message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_WARNING
|
||||
#define pr_warning(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_WARNING __VA_ARGS__)
|
||||
#define pr_warning(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_WARNING, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_warning(...)
|
||||
#endif
|
||||
/// Prints a KERN_NOTICE.
|
||||
|
||||
/// Prints a notice message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_NOTICE
|
||||
#define pr_notice(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_NOTICE __VA_ARGS__)
|
||||
#define pr_notice(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_NOTICE, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_notice(...)
|
||||
#endif
|
||||
/// Prints a KERN_INFO.
|
||||
|
||||
/// Prints a info message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_INFO
|
||||
#define pr_info(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_INFO __VA_ARGS__)
|
||||
#define pr_info(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_INFO, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_info(...)
|
||||
#endif
|
||||
/// Prints a KERN_DEBUG.
|
||||
|
||||
/// Prints a debug message.
|
||||
#if __DEBUG_LEVEL__ >= LOGLEVEL_DEBUG
|
||||
#define pr_debug(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_DEBUG __VA_ARGS__)
|
||||
#define pr_debug(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEBUG, __VA_ARGS__)
|
||||
#else
|
||||
#define pr_debug(...)
|
||||
#endif
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
struct pt_regs;
|
||||
|
||||
/// @brief Prints the registers on debug output.
|
||||
/// @param frame Pointer to the register.
|
||||
void dbg_print_regs(struct pt_regs *frame);
|
||||
|
||||
#endif
|
||||
+13
-1
@@ -1,6 +1,6 @@
|
||||
/// @file mm_io.h
|
||||
/// @brief Memory Mapped IO functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -8,19 +8,31 @@
|
||||
#include "stdint.h"
|
||||
|
||||
/// @brief Reads a 8-bit value from the given address.
|
||||
/// @param addr the address we want to read from.
|
||||
/// @return the value we read.
|
||||
uint8_t in_memb(uint32_t addr);
|
||||
|
||||
/// @brief Reads a 16-bit value from the given address.
|
||||
/// @param addr the address we want to read from.
|
||||
/// @return the value we read.
|
||||
uint16_t in_mems(uint32_t addr);
|
||||
|
||||
/// @brief Reads a 32-bit value from the given address.
|
||||
/// @param addr the address we want to read from.
|
||||
/// @return the value we read.
|
||||
uint32_t in_meml(uint32_t addr);
|
||||
|
||||
/// @brief Writes a 8-bit value at the given address.
|
||||
/// @param addr the address we want to write to.
|
||||
/// @param value the value we want to write.
|
||||
void out_memb(uint32_t addr, uint8_t value);
|
||||
|
||||
/// @brief Writes a 16-bit value at the given address.
|
||||
/// @param addr the address we want to write to.
|
||||
/// @param value the value we want to write.
|
||||
void out_mems(uint32_t addr, uint16_t value);
|
||||
|
||||
/// @brief Writes a 32-bit value at the given address.
|
||||
/// @param addr the address we want to write to.
|
||||
/// @param value the value we want to write.
|
||||
void out_meml(uint32_t addr, uint32_t value);
|
||||
|
||||
+136
-28
@@ -1,42 +1,150 @@
|
||||
/// @file port_io.h
|
||||
/// @brief Byte I/O on ports prototypes.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stdint.h"
|
||||
/// @brief Reads a 8-bit value from the given port.
|
||||
/// @param port the port we want to read from.
|
||||
/// @return the value we read.
|
||||
static inline unsigned char inportb(unsigned short port)
|
||||
{
|
||||
unsigned char result;
|
||||
__asm__ __volatile__("inb %%dx, %%al"
|
||||
: "=a"(result)
|
||||
: "dN"(port)
|
||||
: "memory");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// @brief Used for reading from the I/O ports.
|
||||
/// @param port The input port.
|
||||
/// @return The read value.
|
||||
uint8_t inportb(uint16_t port);
|
||||
/// @brief Reads a 16-bit value from the given port.
|
||||
/// @param port the port we want to read from.
|
||||
/// @return the value we read.
|
||||
static inline unsigned short inports(unsigned short port)
|
||||
{
|
||||
unsigned short result;
|
||||
__asm__ __volatile__("inw %1, %0"
|
||||
: "=a"(result)
|
||||
: "dN"(port)
|
||||
: "memory");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// @brief Used for reading 2 bytes from the I/O ports.
|
||||
/// @param port The input port.
|
||||
/// @return The read value.
|
||||
uint16_t inports(uint16_t port);
|
||||
/// @brief Reads a 32-bit value from the given port.
|
||||
/// @param port the port we want to read from.
|
||||
/// @return the value we read.
|
||||
static inline unsigned int inportl(unsigned short port)
|
||||
{
|
||||
unsigned int result;
|
||||
__asm__ __volatile__("inl %%dx, %%eax"
|
||||
: "=a"(result)
|
||||
: "dN"(port)
|
||||
: "memory");
|
||||
return result;
|
||||
}
|
||||
|
||||
void inportsm(uint16_t port, uint8_t *data, unsigned long size);
|
||||
/// @brief Writes a 8-bit value at the given port.
|
||||
/// @param port the port we want to write to.
|
||||
/// @param value the value we want to write.
|
||||
static inline void outportb(unsigned short port, unsigned char value)
|
||||
{
|
||||
__asm__ __volatile__("outb %%al, %%dx"
|
||||
:
|
||||
: "a"(value), "dN"(port)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
/// @brief Used for reading 4 bytes from the I/O ports.
|
||||
/// @param port The input port.
|
||||
/// @return The read value.
|
||||
uint32_t inportl(uint16_t port);
|
||||
/// @brief Writes a 16-bit value at the given port.
|
||||
/// @param port the port we want to write to.
|
||||
/// @param value the value we want to write.
|
||||
static inline void outports(unsigned short port, unsigned short value)
|
||||
{
|
||||
__asm__ __volatile__("outw %1, %0"
|
||||
:
|
||||
: "dN"(port), "a"(value)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
/// @brief Use this to write to I/O ports to send bytes to devices.
|
||||
/// @param port The output port.
|
||||
/// @param data The data to write.
|
||||
void outportb(uint16_t port, uint8_t data);
|
||||
/// @brief Writes a 32-bit value at the given port.
|
||||
/// @param port the port we want to write to.
|
||||
/// @param value the value we want to write.
|
||||
static inline void outportl(unsigned short port, unsigned int value)
|
||||
{
|
||||
__asm__ __volatile__("outl %%eax, %%dx"
|
||||
:
|
||||
: "dN"(port), "a"(value)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
/// @brief Use this to write to I/O ports to send 2 bytes to devices.
|
||||
/// @param port The output port.
|
||||
/// @param data The data to write.
|
||||
void outports(uint16_t port, uint16_t data);
|
||||
/// @brief Reads multiple 8-bit values from the given port.
|
||||
/// @param port the port we want to read from.
|
||||
/// @param addr the location where we store the values we read.
|
||||
/// @param count the number of values we want to read.
|
||||
static inline void inportsb(unsigned short port, void *addr, unsigned long count)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cld ; rep ; insb "
|
||||
: "=D"(addr), "=c"(count)
|
||||
: "d"(port), "0"(addr), "1"(count));
|
||||
}
|
||||
|
||||
void outportsm(uint16_t port, uint8_t *data, uint16_t size);
|
||||
/// @brief Reads multiple 16-bit values from the given port.
|
||||
/// @param port the port we want to read from.
|
||||
/// @param addr the location where we store the values we read.
|
||||
/// @param count the number of values we want to read.
|
||||
static inline void inportsw(unsigned short port, void *addr, unsigned long count)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cld ; rep ; insw "
|
||||
: "=D"(addr), "=c"(count)
|
||||
: "d"(port), "0"(addr), "1"(count));
|
||||
}
|
||||
|
||||
/// @brief Use this to write to I/O ports to send 4 bytes to devices.
|
||||
/// @param port The output port.
|
||||
/// @param data The data to write.
|
||||
void outportl(uint16_t port, uint32_t data);
|
||||
/// @brief Reads multiple 32-bit values from the given port.
|
||||
/// @param port the port we want to read from.
|
||||
/// @param addr the location where we store the values we read.
|
||||
/// @param count the number of values we want to read.
|
||||
static inline void inportsl(unsigned short port, void *addr, unsigned long count)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cld ; rep ; insl "
|
||||
: "=D"(addr), "=c"(count)
|
||||
: "d"(port), "0"(addr), "1"(count));
|
||||
}
|
||||
|
||||
/// @brief Writes multiple 8-bit values to the given port.
|
||||
/// @param port the port we want to write to.
|
||||
/// @param addr the location where we get the values we need to write.
|
||||
/// @param count the number of values we want to write.
|
||||
static inline void outportsb(unsigned short port, void *addr, unsigned long count)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cld ; rep ; outsb "
|
||||
: "=S"(addr), "=c"(count)
|
||||
: "d"(port), "0"(addr), "1"(count));
|
||||
}
|
||||
|
||||
/// @brief Writes multiple 16-bit values to the given port.
|
||||
/// @param port the port we want to write to.
|
||||
/// @param addr the location where we get the values we need to write.
|
||||
/// @param count the number of values we want to write.
|
||||
static inline void outportsw(unsigned short port, void *addr, unsigned long count)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cld ; rep ; outsw "
|
||||
: "=S"(addr), "=c"(count)
|
||||
: "d"(port), "0"(addr), "1"(count));
|
||||
}
|
||||
|
||||
/// @brief Writes multiple 32-bit values to the given port.
|
||||
/// @param port the port we want to write to.
|
||||
/// @param addr the location where we get the values we need to write.
|
||||
/// @param count the number of values we want to write.
|
||||
static inline void outportsl(unsigned short port, void *addr, unsigned long count)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cld ; rep ; outsl "
|
||||
: "=S"(addr), "=c"(count)
|
||||
: "d"(port), "0"(addr), "1"(count));
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/// @file ipc.h
|
||||
/// @brief Inter-Process Communication (IPC) structures.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
/// @brief Permission details of an IPC object.
|
||||
struct ipc_perm {
|
||||
/// Key supplied to msgget(2).
|
||||
key_t __key;
|
||||
/// Effective UID of owner.
|
||||
uid_t uid;
|
||||
/// Effective GID of owner.
|
||||
gid_t gid;
|
||||
/// Effective UID of creator.
|
||||
uid_t cuid;
|
||||
/// Effective GID of creator.
|
||||
gid_t cgid;
|
||||
/// Permissions.
|
||||
unsigned short mode;
|
||||
/// Sequence number.
|
||||
unsigned short __seq;
|
||||
};
|
||||
+20
-31
@@ -1,40 +1,29 @@
|
||||
/// @file libgen.h
|
||||
/// @brief String routines.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
// TODO: doxygen comment.
|
||||
/// @brief
|
||||
/// @param out
|
||||
/// @param cur
|
||||
/// @param sep
|
||||
/// @param max
|
||||
/// @result
|
||||
int parse_path(char *out, char **cur, char sep, size_t max);
|
||||
/// @brief Extracts the parent directory of the given path and saves it inside
|
||||
/// the given buffer, e.g., from "/home/user/test.txt" it extracts "/home/user".
|
||||
/// If the path does not contain a '/', it will return ".".
|
||||
/// @param path the path we are parsing.
|
||||
/// @param buffer the buffer where we save the directory name.
|
||||
/// @param buflen the length of the buffer.
|
||||
/// @return 1 if succesfull, or 0 if the buffer cannot contain the path.
|
||||
int dirname(const char *path, char *buffer, size_t buflen);
|
||||
|
||||
// TODO: doxygen comment.
|
||||
/// @brief
|
||||
/// @param path
|
||||
/// @result
|
||||
char *dirname(const char *path);
|
||||
|
||||
// TODO: doxygen comment.
|
||||
/// @brief
|
||||
/// @param path
|
||||
/// @result
|
||||
char *basename(const char *path);
|
||||
/// @brief Extract the component after the final '/'.
|
||||
/// @param path the path from which we extract the final component.
|
||||
/// @return a pointer after the final '/', or path itself it none was found.
|
||||
const char *basename(const char *path);
|
||||
|
||||
/// @brief Return the canonicalized absolute pathname.
|
||||
/// @param path The path we are canonicalizing.
|
||||
/// @param resolved The canonicalized path.
|
||||
/// @return
|
||||
/// If there is no error, realpath() returns a pointer to the resolved.
|
||||
/// Otherwise, it returns NULL, the contents of the array resolved
|
||||
/// are undefined, and errno is set to indicate the error.
|
||||
/// @details
|
||||
/// If resolved is NULL, then realpath() uses malloc
|
||||
/// to allocate a buffer of up to PATH_MAX bytes to hold the
|
||||
/// resolved pathname, and returns a pointer to this buffer.
|
||||
char *realpath(const char *path, char *resolved);
|
||||
/// @param path the path we are canonicalizing.
|
||||
/// @param buffer where we will store the canonicalized path.
|
||||
/// @param buflen the size of the buffer.
|
||||
/// @return If there is no error, realpath() returns a pointer to the buffer.
|
||||
/// Otherwise, it returns NULL, the contents of the array buffer are undefined,
|
||||
/// and errno is set to indicate the error.
|
||||
char *realpath(const char *path, char *buffer, size_t buflen);
|
||||
|
||||
+4
-1
@@ -1,6 +1,6 @@
|
||||
/// @file limits.h
|
||||
/// @brief OS numeric limits.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -53,5 +53,8 @@
|
||||
/// Maximum number of characters in a path name.
|
||||
#define PATH_MAX 4096
|
||||
|
||||
/// Maximum length of arguments provided to exec function.
|
||||
#define ARG_MAX 256
|
||||
|
||||
/// Maximum pid number.
|
||||
#define PID_MAX_LIMIT 32768
|
||||
|
||||
+4
-1
@@ -1,6 +1,6 @@
|
||||
/// @file math.h
|
||||
/// @brief Mathematical constants and functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -17,6 +17,9 @@
|
||||
/// @brief The sign the the passed value.
|
||||
#define sign(x) ((x < 0) ? -1 : ((x > 0) ? 1 : 0))
|
||||
|
||||
/// @brief Returns a rounded up, away from zero, to the nearest multiple of b.
|
||||
#define round_up(number, base) (((number) + (base)-1) & ~((base)-1))
|
||||
|
||||
/// @brief e
|
||||
#define M_E 2.7182818284590452354
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file pwd.h
|
||||
/// @brief Contains the structure and functions for managing passwords.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/// @file readline.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
/// @brief Reads a line from the file.
|
||||
/// @param fd the file descriptor.
|
||||
/// @param buffer the buffer where we place the line.
|
||||
/// @param buflen the length of the buffer.
|
||||
/// @param readlen the amount we read, if negative, we did not encounter a newline.
|
||||
/// @return 0 if we are done reading, 1 if we encountered a newline, -1 if otherwise.
|
||||
int readline(int fd, char *buffer, size_t buflen, ssize_t *read_len);
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file ring_buffer.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/// @file sched.h
|
||||
/// @brief Structures and functions for managing the scheduler.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/types.h"
|
||||
@@ -40,4 +40,4 @@ int sched_getparam(pid_t pid, sched_param_t *param);
|
||||
/// @brief Placed at the end of an infinite while loop, stops the process until,
|
||||
/// its next period starts. The calling process must be a periodic one.
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
int waitperiod();
|
||||
int waitperiod(void);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file signal.h
|
||||
/// @brief Signals definition.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file stdarg.h
|
||||
/// @brief Contains the macros required to manage variable number of arguments.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file stdbool.h
|
||||
/// @brief Defines the boolean values.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+11
-1
@@ -1,6 +1,6 @@
|
||||
/// @file stddef.h
|
||||
/// @brief Define basic data types.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -68,3 +68,13 @@ typedef unsigned int pgprot_t;
|
||||
/// Returns the alignment, in bytes, of the specified type.
|
||||
#define alignof(type) offsetof( \
|
||||
struct { char c; type member; }, member)
|
||||
|
||||
/// Counts the number of elements of an array.
|
||||
#define count_of(x) ((sizeof(x) / sizeof((x)[0])) / ((size_t)(!(sizeof(x) % sizeof((x)[0])))))
|
||||
|
||||
#define swap(a, b) \
|
||||
do { \
|
||||
typeof(a) temp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = temp; \
|
||||
} while (0)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file stdint.h
|
||||
/// @brief Standard integer data-types.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+7
-3
@@ -1,6 +1,6 @@
|
||||
/// @file stdio.h
|
||||
/// @brief Standard I/0 functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -30,11 +30,11 @@ void putchar(int character);
|
||||
/// @brief Writes the string pointed by str to the standard output (stdout)
|
||||
/// and appends a newline character.
|
||||
/// @param str The string to send to stdout.
|
||||
void puts(char *str);
|
||||
void puts(const char *str);
|
||||
|
||||
/// @brief Returns the next character from the standard input (stdin).
|
||||
/// @return The character received from stdin.
|
||||
int getchar();
|
||||
int getchar(void);
|
||||
|
||||
/// @brief Reads characters from the standard input (stdin).
|
||||
/// @param str Where the characters are stored.
|
||||
@@ -124,3 +124,7 @@ int sscanf(const char *str, const char *fmt, ...);
|
||||
/// argument list successfully filled. EOF otherwise.
|
||||
int fscanf(int fd, const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
/// @brief Prints a system error message.
|
||||
/// @param s the message we prepend to the actual error message.
|
||||
void perror(const char *s);
|
||||
|
||||
+42
-13
@@ -1,12 +1,17 @@
|
||||
/// @file stdlib.h
|
||||
/// @brief Useful generic functions and macros.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __KERNEL__
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
#define EXIT_SUCCESS 0 ///< Successful execution of a program.
|
||||
#define EXIT_FAILURE 1 ///< Unsuccessful execution of a program.
|
||||
|
||||
/// @brief Returns the number of usable bytes in the block pointed to by ptr.
|
||||
/// @param ptr The pointer for which we want to retrieve the usable size.
|
||||
/// @return The number of usable bytes in the block of allocated memory
|
||||
@@ -38,19 +43,8 @@ void *realloc(void *ptr, size_t size);
|
||||
/// @param ptr The pointer to the allocated memory.
|
||||
void free(void *ptr);
|
||||
|
||||
/// The maximum value returned by the rand function.
|
||||
#define RAND_MAX ((1U << 31U) - 1U)
|
||||
|
||||
/// @brief Allows to set the seed of the random value generator.
|
||||
/// @param x The new seed.
|
||||
void srand(int x);
|
||||
|
||||
/// @brief Generates a random value.
|
||||
/// @return The random value.
|
||||
int rand();
|
||||
|
||||
/// @brief Cause an abnormal program termination with core-dump.
|
||||
void abort();
|
||||
void abort(void);
|
||||
|
||||
/// @brief Tries to adds the variable to the environment.
|
||||
/// @param name Name of the variable.
|
||||
@@ -68,3 +62,38 @@ int unsetenv(const char *name);
|
||||
/// @param name Name of the variable.
|
||||
/// @return A pointer to the value, or NULL if there is no match.
|
||||
char *getenv(const char *name);
|
||||
|
||||
#endif
|
||||
|
||||
/// The maximum value returned by the rand function.
|
||||
#define RAND_MAX ((1U << 31U) - 1U)
|
||||
|
||||
/// @brief Allows to set the seed of the random value generator.
|
||||
/// @param x The new seed.
|
||||
void srand(unsigned x);
|
||||
|
||||
/// @brief Generates a random unsigned integer between 0 and RAND_MAX.
|
||||
/// @return the random value.
|
||||
unsigned rand(void);
|
||||
|
||||
/// @brief Generates a random floating point number between 0 and 1.
|
||||
/// @return the random value.
|
||||
float randf(void);
|
||||
|
||||
/// @brief Generates a random integer between lb and ub.
|
||||
/// @param lb the lower-bound value.
|
||||
/// @param ub the upper-bound value.
|
||||
/// @return the random value.
|
||||
int randint(int lb, int ub);
|
||||
|
||||
/// @brief Generates a random unsigned between lb and ub.
|
||||
/// @param lb the lower-bound value.
|
||||
/// @param ub the upper-bound value.
|
||||
/// @return the random value.
|
||||
unsigned randuint(unsigned lb, unsigned ub);
|
||||
|
||||
/// @brief Generates a random float between lb and ub.
|
||||
/// @param lb the lower-bound value.
|
||||
/// @param ub the upper-bound value.
|
||||
/// @return the random value.
|
||||
float randfloat(float lb, float ub);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file strerror.h
|
||||
/// @brief Contains the function that transfornms an errno into a string.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+10
-1
@@ -1,6 +1,6 @@
|
||||
/// @file string.h
|
||||
/// @brief String routines.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -170,6 +170,15 @@ char *strtok(char *str, const char *delim);
|
||||
/// should be NULL, and saveptr should be unchanged since the previous call.
|
||||
char *strtok_r(char *str, const char *delim, char **saveptr);
|
||||
|
||||
/// @brief Parses the string using the separator, and at each call it saves the
|
||||
/// parsed token in buffer. The pointer `string` will be modified.
|
||||
/// @param string cursor used to parse the string, it will be modified.
|
||||
/// @param separators the list of separators we are using.
|
||||
/// @param buffer the buffer where we save the parsed token.
|
||||
/// @param buflen the length of the buffer.
|
||||
/// @return 1 if we still have things to parse, 0 if we finished parsing.
|
||||
int tokenize(const char *string, char *separators, size_t *offset, char *buffer, ssize_t buflen);
|
||||
|
||||
/// @brief Copies the values of num bytes from the location pointed by source
|
||||
/// to the memory block pointed by destination.
|
||||
/// @param dst Pointer to the destination array where the content is to be
|
||||
|
||||
+19
-13
@@ -1,34 +1,38 @@
|
||||
/// @file bitops.h
|
||||
/// @brief Bitmasks functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#define bit_set(V, B) ((V) | (1U << (B))) ///< Sets the given bit.
|
||||
#define bit_clear(V, B) ((V) & ~(1U << (B))) ///< Clears the given bit.
|
||||
#define bit_flip(V, B) ((V) ^ (1U << (B))) ///< Flips the given bit.
|
||||
#define bit_set_assign(V, B) ((V) |= (1U << (B))) ///< Sets the given bit, permanently.
|
||||
#define bit_clear_assign(V, B) ((V) &= ~(1U << (B))) ///< Clears the given bit, permanently.
|
||||
#define bit_flip_assign(V, B) ((V) ^= (1U << (B))) ///< Flips the given bit, permanently.
|
||||
#define bit_check(V, B) ((V) & (1U << (B))) ///< Checks if the given bit is 1.
|
||||
#define bit_set(V, B) ((V) | (1U << (B))) ///< Sets the given bit.
|
||||
#define bit_clear(V, B) ((V) & ~(1U << (B))) ///< Clears the given bit.
|
||||
#define bit_flip(V, B) ((V) ^ (1U << (B))) ///< Flips the given bit.
|
||||
#define bit_check(V, B) ((V) & (1U << (B))) ///< Checks if the given bit is 1.
|
||||
#define bit_toggle(V, B, C) ((C) ? bit_set(V, B) : bit_clear(V, B)) ///< Sets the given bit based on control bit C.
|
||||
#define bit_set_assign(V, B) ((V) |= (1U << (B))) ///< Sets the given bit, permanently.
|
||||
#define bit_clear_assign(V, B) ((V) &= ~(1U << (B))) ///< Clears the given bit, permanently.
|
||||
#define bit_flip_assign(V, B) ((V) ^= (1U << (B))) ///< Flips the given bit, permanently.
|
||||
#define bit_toggle_assign(V, B, C) ((C) ? bit_set_assign(V, B) : bit_clear_assign(V, B)) ///< Sets the given bit based on control bit C.
|
||||
|
||||
#define bitmask_set(V, M) ((V) | (M)) ///< Sets the bits identified by the mask.
|
||||
#define bitmask_clear(V, M) ((V) & ~(M)) ///< Clears the bits identified by the mask.
|
||||
#define bitmask_flip(V, M) ((V) ^ (M)) ///< Flips the bits identified by the mask.
|
||||
#define bitmask_check(V, M) ((V) & (M)) ///< Checks if the bits identified by the mask are all 1.
|
||||
#define bitmask_set_assign(V, M) ((V) |= (M)) ///< Sets the bits identified by the mask, permanently.
|
||||
#define bitmask_clear_assign(V, M) ((V) &= ~(M)) ///< Clears the bits identified by the mask, permanently.
|
||||
#define bitmask_flip_assign(V, M) ((V) ^= (M)) ///< Flips the bits identified by the mask, permanently.
|
||||
#define bitmask_check(V, M) ((V) & (M)) ///< Checks if the bits identified by the mask are all 1.
|
||||
|
||||
/// @brief Finds the first bit at zero, starting from the less significative bit.
|
||||
/// @param value the value we need to analyze.
|
||||
/// @return the position of the first zero bit.
|
||||
static inline int find_first_zero(unsigned long value)
|
||||
{
|
||||
for (int i = 0; i < 32; ++i)
|
||||
if (!bit_check(value, i))
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
if (!bit_check(value, i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,8 +41,10 @@ static inline int find_first_zero(unsigned long value)
|
||||
/// @return the position of the first non-zero bit.
|
||||
static inline int find_first_non_zero(unsigned long value)
|
||||
{
|
||||
for (int i = 0; i < 32; ++i)
|
||||
if (bit_check(value, i))
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
if (bit_check(value, i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file dirent.h
|
||||
/// @brief Functions used to manage directories.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/// @file errno.h
|
||||
/// @brief System call errors definition.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
extern int *__geterrno();
|
||||
extern int *__geterrno(void);
|
||||
|
||||
/// Provide easy access to the error number.
|
||||
#define errno (*__geterrno())
|
||||
@@ -20,7 +20,7 @@ extern int *__geterrno();
|
||||
#define ENOEXEC 8 ///< Exec format error.
|
||||
#define EBADF 9 ///< Bad file number.
|
||||
#define ECHILD 10 ///< No child processes.
|
||||
#define EAGAIN 11 ///< Try again.
|
||||
#define EAGAIN 11 ///< Resource temporarily unavailable.
|
||||
#define ENOMEM 12 ///< Out of memory.
|
||||
#define EACCES 13 ///< Permission denied.
|
||||
#define EFAULT 14 ///< Bad address.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file ioctl.h
|
||||
/// @brief Input/Output ConTroL (IOCTL) functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/// @file ipc.h
|
||||
/// @brief Inter-Process Communication (IPC) structures.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "stddef.h"
|
||||
|
||||
#define IPC_CREAT 01000 ///< Create key if key does not exist.
|
||||
#define IPC_EXCL 02000 ///< Fail if key exists.
|
||||
#define IPC_NOWAIT 04000 ///< Return error on wait.
|
||||
#define IPC_RMID 0 ///< Remove identifier.
|
||||
#define IPC_SET 1 ///< Set `ipc_perm' options.
|
||||
#define IPC_STAT 2 ///< Get `ipc_perm' options.
|
||||
#define IPC_INFO 3 ///< See ipcs.
|
||||
|
||||
#define IPC_PRIVATE ((key_t)0) ///< assures getting a new ipc_key.
|
||||
|
||||
/// @brief Permission details of an IPC object.
|
||||
struct ipc_perm {
|
||||
/// Key associated to the IPC.
|
||||
key_t key;
|
||||
/// Effective UID of owner.
|
||||
uid_t uid;
|
||||
/// Effective GID of owner.
|
||||
gid_t gid;
|
||||
/// Effective UID of creator.
|
||||
uid_t cuid;
|
||||
/// Effective GID of creator.
|
||||
gid_t cgid;
|
||||
/// Permissions.
|
||||
unsigned short mode;
|
||||
/// Sequence number.
|
||||
unsigned short __seq;
|
||||
};
|
||||
|
||||
/// @brief Returns a possible IPC key based upon the filepath and the id.
|
||||
/// @param path The file path.
|
||||
/// @param id the project id.
|
||||
/// @return the IPC key.
|
||||
key_t ftok(char *path, int id);
|
||||
@@ -0,0 +1,17 @@
|
||||
/// @file kernel_levels.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Integer equivalents of KERN_<LEVEL>
|
||||
#define LOGLEVEL_DEFAULT (-1) ///< default-level messages.
|
||||
#define LOGLEVEL_EMERG 0 ///< system is unusable.
|
||||
#define LOGLEVEL_ALERT 1 ///< action must be taken immediately.
|
||||
#define LOGLEVEL_CRIT 2 ///< critical conditions.
|
||||
#define LOGLEVEL_ERR 3 ///< error conditions.
|
||||
#define LOGLEVEL_WARNING 4 ///< warning conditions.
|
||||
#define LOGLEVEL_NOTICE 5 ///< normal but significant condition.
|
||||
#define LOGLEVEL_INFO 6 ///< informational.
|
||||
#define LOGLEVEL_DEBUG 7 ///< debug-level messages.
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file list_head.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -22,31 +22,37 @@ typedef struct list_head {
|
||||
#define list_entry(ptr, type, member) container_of(ptr, type, member)
|
||||
|
||||
/// @brief Iterates over a list.
|
||||
/// @param pos The &list_head to use as a loop cursor.
|
||||
/// @param head The head for your list.
|
||||
/// @param pos the name of the iterator used to visit the list.
|
||||
/// @param head the head for your list.
|
||||
#define list_for_each(pos, head) \
|
||||
for ((pos) = (head)->next; (pos) != (head); (pos) = (pos)->next)
|
||||
|
||||
/// @brief Iterates over a list backwards.
|
||||
/// @param pos The &list_head to use as a loop cursor.
|
||||
/// @param head The head for your list.
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for ((pos) = (head)->prev; (pos) != (head); (pos) = (pos)->prev)
|
||||
|
||||
/// @brief Iterates over a list safe against removal of list entry.
|
||||
/// @param pos The &list_head to use as a loop cursor.
|
||||
/// @param store Another &list_head to use as temporary storage.
|
||||
/// @param head The head for your list.
|
||||
/// @param pos the name of the iterator used to visit the list.
|
||||
/// @param store another list iterator to use as temporary storage.
|
||||
/// @param head the head for your list.
|
||||
#define list_for_each_safe(pos, store, head) \
|
||||
for ((pos) = (head)->next, (store) = (pos)->next; (pos) != (head); \
|
||||
(pos) = (store), (store) = (pos)->next)
|
||||
|
||||
/// @brief Iterates over a list.
|
||||
/// @param pos The &list_head to use as a loop cursor.
|
||||
/// @param head The head for your list.
|
||||
/// @brief Iterates over a list, but declares the iterator.
|
||||
/// @param pos the name of the iterator used to visit the list.
|
||||
/// @param head the head for your list.
|
||||
#define list_for_each_decl(pos, head) \
|
||||
for (list_head * (pos) = (head)->next; (pos) != (head); (pos) = (pos)->next)
|
||||
|
||||
/// @brief Iterates over a list backwards.
|
||||
/// @param pos the name of the iterator used to visit the list.
|
||||
/// @param head the head for your list.
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for ((pos) = (head)->prev; (pos) != (head); (pos) = (pos)->prev)
|
||||
|
||||
/// @brief Iterates over a list backwards, but declares the iterator.
|
||||
/// @param pos the name of the iterator used to visit the list.
|
||||
/// @param head the head for your list.
|
||||
#define list_for_each_prev_decl(pos, head) \
|
||||
for (list_head * (pos) = (head)->prev; (pos) != (head); (pos) = (pos)->prev)
|
||||
|
||||
/// @brief Initializes the list_head.
|
||||
/// @param head The head of your list.
|
||||
static inline void list_head_init(list_head *head)
|
||||
@@ -62,13 +68,15 @@ static inline int list_head_empty(const list_head *head)
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/// @brief Initializes the list_head.
|
||||
/// @param head The head for your list.
|
||||
/// @brief Computes the size of the list.
|
||||
/// @param head The head of the list.
|
||||
/// @return the size of the list.
|
||||
static inline unsigned list_head_size(const list_head *head)
|
||||
{
|
||||
unsigned size = 0;
|
||||
if (!list_head_empty(head))
|
||||
if (!list_head_empty(head)) {
|
||||
list_for_each_decl(it, head) size += 1;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -160,3 +168,32 @@ static inline void list_head_append(list_head *main, list_head *secondary)
|
||||
list_head_init(secondary);
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Replaces entry1 with entry2, entry1 will be removed from the list.
|
||||
/// @param entry1 the first entry to remove.
|
||||
/// @param entry2 the second entry which will take the place of the first entry.
|
||||
static inline void list_head_replace(list_head *entry1, list_head *entry2)
|
||||
{
|
||||
// First we need to remove the second entry.
|
||||
list_head_remove(entry2);
|
||||
// Then, we can place second entry where the first entry is.
|
||||
entry2->next = entry1->next;
|
||||
entry2->next->prev = entry2;
|
||||
entry2->prev = entry1->prev;
|
||||
entry2->prev->next = entry2;
|
||||
// Re-initialize the first entry.
|
||||
list_head_init(entry1);
|
||||
}
|
||||
|
||||
/// @brief Swaps entry1 and entry2 inside the list.
|
||||
/// @param entry1 the first entry.
|
||||
/// @param entry2 the second entry.
|
||||
static inline void list_head_swap(list_head *entry1, list_head *entry2)
|
||||
{
|
||||
list_head *pos = entry2->prev;
|
||||
list_head_replace(entry1, entry2);
|
||||
if (pos == entry1) {
|
||||
pos = entry2;
|
||||
}
|
||||
list_head_insert_after(entry1, pos);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/// @file list_head_algorithm.h
|
||||
/// @author Enrico Fraccaroli (enry.frak@gmail.com)
|
||||
/// @brief Some general algorithm that might come in handy while using list_head.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "list_head.h"
|
||||
|
||||
/// @brief list_head comparison function.
|
||||
typedef int (*list_head_compare)(const list_head *, const list_head *);
|
||||
|
||||
/// @brief -
|
||||
/// @param list
|
||||
/// @param compare
|
||||
static inline void list_head_sort(list_head *list, list_head_compare compare)
|
||||
{
|
||||
list_head *current = NULL, *index = NULL, *next = NULL;
|
||||
// Check whether list is empty
|
||||
if (!list_head_empty(list)) {
|
||||
// Keeps track if we need to restart the outer loop.
|
||||
int restart = 0;
|
||||
// Current will point to head
|
||||
for (current = list->next; current->next != list;) {
|
||||
// Save pointer to next.
|
||||
next = current->next;
|
||||
// Reset restart flag.
|
||||
restart = 0;
|
||||
// Index will point to node next to current
|
||||
for (index = current->next; index != list; index = index->next) {
|
||||
// If current's data is greater than index's data, swap the data of
|
||||
// current and index
|
||||
if (compare(current, index)) {
|
||||
list_head_swap(index, current);
|
||||
restart = 1;
|
||||
}
|
||||
}
|
||||
// Check if we need to restart.
|
||||
if (restart) {
|
||||
current = list->next;
|
||||
} else {
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/// @file mman.h
|
||||
/// @author Enrico Fraccaroli (enry.frak@gmail.com)
|
||||
/// @brief Functions for managing mappings in virtual address space.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
#define PROT_READ 0x1 ///< Page can be read.
|
||||
#define PROT_WRITE 0x2 ///< Page can be written.
|
||||
#define PROT_EXEC 0x4 ///< Page can be executed.
|
||||
|
||||
#define MAP_SHARED 0x01 ///< The memory is shared.
|
||||
#define MAP_PRIVATE 0x02 ///< The memory is private.
|
||||
|
||||
#ifndef __KERNEL__
|
||||
|
||||
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
|
||||
|
||||
int munmap(void *addr, size_t length);
|
||||
|
||||
#else
|
||||
|
||||
void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
|
||||
|
||||
int sys_munmap(void *addr, size_t length);
|
||||
|
||||
#endif
|
||||
@@ -1,31 +1,48 @@
|
||||
/// @file msg.h
|
||||
/// @brief Definition of structure for managing message queues.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "sys/ipc.h"
|
||||
#include "stddef.h"
|
||||
#include "sys/types.h"
|
||||
#include "time.h"
|
||||
#include "ipc.h"
|
||||
|
||||
/// Type for storing the number of messages in a message queue.
|
||||
typedef unsigned int msgqnum_t;
|
||||
/// The maximum size for a message text.
|
||||
#define MSGMAX 8192
|
||||
/// The default maximum size in bytes of a message queue.
|
||||
#define MSGMNB 16384
|
||||
|
||||
/// Type for storing the number of bytes in a message queue.
|
||||
typedef unsigned int msglen_t;
|
||||
/// Specify that we should not treat as an error if the message we are trying to
|
||||
/// return to the user, is too big. That message will be truncated to fit the
|
||||
/// user-defined reading buffer. If not specified, the message is kept in the
|
||||
/// queue, and an error is returned.
|
||||
#define MSG_NOERROR 010000
|
||||
|
||||
/// @brief Buffer to use with the message queue IPC.
|
||||
typedef struct msgbuf {
|
||||
struct msgbuf {
|
||||
/// Type of the message.
|
||||
long mtype;
|
||||
/// Text of the message.
|
||||
char mtext[1];
|
||||
} msgbuf_t;
|
||||
};
|
||||
|
||||
/// Keeps track of a stored message.
|
||||
struct msg {
|
||||
/// Pointer to the next message on queue.
|
||||
struct msg *msg_next;
|
||||
/// The type of message.
|
||||
long msg_type;
|
||||
/// Pointer to the beginning of the message.
|
||||
char *msg_ptr;
|
||||
/// The length of the message.
|
||||
size_t msg_size;
|
||||
};
|
||||
|
||||
/// @brief Message queue data structure.
|
||||
typedef struct msqid_ds {
|
||||
struct msqid_ds {
|
||||
/// Ownership and permissions.
|
||||
struct ipc_perm msg_perm;
|
||||
/// Time of last msgsnd(2).
|
||||
@@ -35,26 +52,30 @@ typedef struct msqid_ds {
|
||||
/// Time of creation or last modification by msgctl().
|
||||
time_t msg_ctime;
|
||||
/// Number of bytes in queue.
|
||||
unsigned long msg_cbytes;
|
||||
unsigned short msg_cbytes;
|
||||
/// Number of messages in queue.
|
||||
msgqnum_t msg_qnum;
|
||||
unsigned short msg_qnum;
|
||||
/// Maximum number of bytes in queue.
|
||||
msglen_t msg_qbytes;
|
||||
unsigned short msg_qbytes;
|
||||
/// PID of last msgsnd(2).
|
||||
pid_t msg_lspid;
|
||||
/// PID of last msgrcv(2).
|
||||
pid_t msg_lrpid;
|
||||
} msqid_ds_t;
|
||||
};
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
/// @brief Initializes the message queue system.
|
||||
/// @return 0 on success, 1 on failure.
|
||||
int msq_init(void);
|
||||
|
||||
/// @brief Get a System V message queue identifier.
|
||||
/// @param key can be used either to obtain the identifier of a previously
|
||||
/// created message queue, or to create a new set.
|
||||
/// @param msgflg controls the behaviour of the function.
|
||||
/// @return the message queue identifier, -1 on failure, and errno is set to
|
||||
/// indicate the error.
|
||||
long sys_msgget(key_t key, int msgflg);
|
||||
int sys_msgget(key_t key, int msgflg);
|
||||
|
||||
/// @brief Used to send messages.
|
||||
/// @param msqid the message queue identifier.
|
||||
@@ -62,7 +83,7 @@ long sys_msgget(key_t key, int msgflg);
|
||||
/// @param msgsz specifies the size in bytes of mtext.
|
||||
/// @param msgflg specifies the action to be taken in case of specific events.
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long sys_msgsnd(int msqid, msgbuf_t *msgp, size_t msgsz, int msgflg);
|
||||
int sys_msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
|
||||
|
||||
/// @brief Used to receive messages.
|
||||
/// @param msqid the message queue identifier.
|
||||
@@ -74,15 +95,16 @@ long sys_msgsnd(int msqid, msgbuf_t *msgp, size_t msgsz, int msgflg);
|
||||
/// - msgtyp < 0: the first message of the lowest type that is less than or
|
||||
/// equal to the absolute value of msgtyp is received.
|
||||
/// @param msgflg specifies the action to be taken in case of specific events.
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long sys_msgrcv(int msqid, msgbuf_t *msgp, size_t msgsz, long msgtyp, int msgflg);
|
||||
/// @return the number of bytes actually copied on success, -1 on failure and
|
||||
/// errno is set to indicate the error.
|
||||
ssize_t sys_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
|
||||
|
||||
/// @brief Message queue control operations.
|
||||
/// @param msqid the message queue identifier.
|
||||
/// @param cmd The command to perform.
|
||||
/// @param buf used with IPC_STAT and IPC_SET.
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long sys_msgctl(int msqid, int cmd, msqid_ds_t *buf);
|
||||
int sys_msgctl(int msqid, int cmd, struct msqid_ds *buf);
|
||||
|
||||
#else
|
||||
|
||||
@@ -92,7 +114,7 @@ long sys_msgctl(int msqid, int cmd, msqid_ds_t *buf);
|
||||
/// @param msgflg controls the behaviour of the function.
|
||||
/// @return the message queue identifier, -1 on failure, and errno is set to
|
||||
/// indicate the error.
|
||||
long msgget(key_t key, int msgflg);
|
||||
int msgget(key_t key, int msgflg);
|
||||
|
||||
/// @brief Used to send messages.
|
||||
/// @param msqid the message queue identifier.
|
||||
@@ -100,7 +122,7 @@ long msgget(key_t key, int msgflg);
|
||||
/// @param msgsz specifies the size in bytes of mtext.
|
||||
/// @param msgflg specifies the action to be taken in case of specific events.
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long msgsnd(int msqid, msgbuf_t *msgp, size_t msgsz, int msgflg);
|
||||
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
|
||||
|
||||
/// @brief Used to receive messages.
|
||||
/// @param msqid the message queue identifier.
|
||||
@@ -112,14 +134,15 @@ long msgsnd(int msqid, msgbuf_t *msgp, size_t msgsz, int msgflg);
|
||||
/// - msgtyp < 0: the first message of the lowest type that is less than or
|
||||
/// equal to the absolute value of msgtyp is received.
|
||||
/// @param msgflg specifies the action to be taken in case of specific events.
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long msgrcv(int msqid, msgbuf_t *msgp, size_t msgsz, long msgtyp, int msgflg);
|
||||
/// @return the number of bytes actually copied on success, -1 on failure and
|
||||
/// errno is set to indicate the error.
|
||||
ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
|
||||
|
||||
/// @brief Message queue control operations.
|
||||
/// @param msqid the message queue identifier.
|
||||
/// @param cmd The command to perform.
|
||||
/// @param buf used with IPC_STAT and IPC_SET.
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long msgctl(int msqid, int cmd, msqid_ds_t *buf);
|
||||
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file reboot.h
|
||||
/// @brief Defines the values required to issue a reboot.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,27 +1,87 @@
|
||||
/// @file sem.h
|
||||
/// @brief Definition of structure for managing semaphores.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "stddef.h"
|
||||
#include "sys/ipc.h"
|
||||
#include "time.h"
|
||||
#include "ipc.h"
|
||||
|
||||
#define SEM_UNDO 0x1000 ///< Undo the operation on exit.
|
||||
|
||||
/// @defgroup SemaphoreCommands semctl commands
|
||||
/// @brief List of commands for semctl function.
|
||||
/// @{
|
||||
|
||||
#define GETPID 11 ///< Get sempid.
|
||||
#define GETVAL 12 ///< Get semval.
|
||||
#define GETALL 13 ///< Get all semval's.
|
||||
#define GETNCNT 14 ///< Get semncnt.
|
||||
#define GETZCNT 15 ///< Get semzcnt.
|
||||
#define SETVAL 16 ///< Set semval.
|
||||
#define SETALL 17 ///< Set all semval's.
|
||||
#define SEM_STAT 18 ///< Return a semid_ds structure.
|
||||
#define SEM_INFO 19 ///< Return a seminfo structure.
|
||||
|
||||
/// }@
|
||||
|
||||
#define SEM_SET_MAX 256
|
||||
|
||||
/// @brief Optional argument for semctl() function
|
||||
union semun {
|
||||
/// @brief Value for SETVAL.
|
||||
int val;
|
||||
/// @brief Buffer for IPC_STAT & IPC_SET.
|
||||
struct semid_ds *buf;
|
||||
/// @brief Array for GETALL & SETALL.
|
||||
unsigned short *array;
|
||||
/// @brief Buffer for IPC_INFO.
|
||||
struct seminfo *__buf;
|
||||
};
|
||||
|
||||
/// @brief Single Semaphore.
|
||||
struct sem {
|
||||
/// @brief Process ID of the last operation.
|
||||
pid_t sem_pid;
|
||||
/// @brief Semaphore Value.
|
||||
unsigned short sem_val;
|
||||
/// @brief Number of processes waiting for the semaphore.
|
||||
unsigned short sem_ncnt;
|
||||
/// @brief Number of processes waiting for the value to become 0.
|
||||
unsigned short sem_zcnt;
|
||||
};
|
||||
|
||||
/// @brief Semaphore set
|
||||
struct semid_ds {
|
||||
/// @brief Ownership and permissions.
|
||||
struct ipc_perm sem_perm;
|
||||
/// @brief Last semop time.
|
||||
time_t sem_otime;
|
||||
/// @brief Last change time.
|
||||
time_t sem_ctime;
|
||||
/// @brief Number of semaphores in set.
|
||||
unsigned short sem_nsems;
|
||||
};
|
||||
|
||||
/// @brief Buffer to use with the semaphore IPC.
|
||||
struct sembuf {
|
||||
/// Semaphore index in array.
|
||||
/// @brief Semaphore index in array.
|
||||
unsigned short sem_num;
|
||||
/// Semaphore operation.
|
||||
/// @brief Semaphore operation.
|
||||
short sem_op;
|
||||
/// Operation flags.
|
||||
/// @brief Operation flags.
|
||||
short sem_flg;
|
||||
};
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
/// @brief Initializes the semaphore system.
|
||||
/// @return 0 on success, 1 on failure.
|
||||
int sem_init(void);
|
||||
|
||||
/// @brief Get a System V semaphore set identifier.
|
||||
/// @param key can be used either to obtain the identifier of a previously
|
||||
/// created semaphore set, or to create a new set.
|
||||
@@ -44,7 +104,7 @@ long sys_semop(int semid, struct sembuf *sops, unsigned nsops);
|
||||
/// @param cmd the command to perform.
|
||||
/// @param arg
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long sys_semctl(int semid, int semnum, int cmd, unsigned long arg);
|
||||
long sys_semctl(int semid, int semnum, int cmd, union semun *arg);
|
||||
|
||||
#else
|
||||
|
||||
@@ -70,6 +130,6 @@ long semop(int semid, struct sembuf *sops, unsigned nsops);
|
||||
/// @param cmd the command to perform.
|
||||
/// @param arg
|
||||
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
|
||||
long semctl(int semid, int semnum, int cmd, unsigned long arg);
|
||||
long semctl(int semid, int semnum, int cmd, union semun *arg);
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,14 @@
|
||||
/// @file shm.h
|
||||
/// @brief Definition of structure for managing shared memories.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "stddef.h"
|
||||
#include "sys/ipc.h"
|
||||
#include "time.h"
|
||||
#include "ipc.h"
|
||||
|
||||
/// Data type for storing the number of attaches.
|
||||
typedef unsigned long shmatt_t;
|
||||
@@ -19,27 +19,22 @@ struct shmid_ds {
|
||||
struct ipc_perm shm_perm;
|
||||
/// Size of segment in bytes.
|
||||
size_t shm_segsz;
|
||||
/// Time of last shmat().
|
||||
/// Time of last attach.
|
||||
time_t shm_atime;
|
||||
/// Time of last shmdt().
|
||||
/// Time of last detach.
|
||||
time_t shm_dtime;
|
||||
/// Time of last change by shmctl().
|
||||
/// Time of last change.
|
||||
time_t shm_ctime;
|
||||
/// Pid of creator.
|
||||
pid_t shm_cpid;
|
||||
/// Pid of last shmop.
|
||||
/// Pid of last operator.
|
||||
pid_t shm_lpid;
|
||||
/// Number of current attaches.
|
||||
shmatt_t shm_nattch;
|
||||
/// Pointer to the next shared memory data structure.
|
||||
struct shmid_ds *next;
|
||||
/// Where shm created is memorized, should be a file.
|
||||
void *shm_location;
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
#include "ipc.h"
|
||||
#include "debug.h"
|
||||
#include "time.h"
|
||||
#include "kheap.h"
|
||||
@@ -56,20 +51,6 @@ struct shmid_ds {
|
||||
#define SHM_W 0200
|
||||
//==============================================================================
|
||||
|
||||
//======== Flags for shmat =====================================================
|
||||
// Attach read-only else read-write.
|
||||
#define SHM_RDONLY 010000
|
||||
|
||||
// Round attach address to SHMLBA.
|
||||
#define SHM_RND 020000
|
||||
|
||||
// Take-over region on attach.
|
||||
#define SHM_REMAP 040000
|
||||
|
||||
// Execution access.
|
||||
#define SHM_EXEC 0100000
|
||||
//==============================================================================
|
||||
|
||||
//======== Commands for shmctl =================================================
|
||||
// Lock segment (root only).
|
||||
#define SHM_LOCK 11
|
||||
@@ -98,51 +79,27 @@ struct shmid_ds {
|
||||
// Don't check for reservations.
|
||||
#define SHM_NORESERVE 010000
|
||||
|
||||
/// @@brief Syscall Service Routine: Shared memory control operation.
|
||||
int syscall_shmctl(int *args);
|
||||
|
||||
/// @@brief Syscall Service Routine: Get shared memory segment.
|
||||
int syscall_shmget(int *args);
|
||||
|
||||
/// @@brief Syscall Service Routine: Attach shared memory segment.
|
||||
void *syscall_shmat(int *args);
|
||||
|
||||
/// @@brief Syscall Service Routine: Detach shared memory segment.
|
||||
int syscall_shmdt(int *args);
|
||||
|
||||
/// @@brief User Wrapper: Shared memory control operation.
|
||||
int shmctl(int shmid, int cmd, struct shmid_ds *buf);
|
||||
|
||||
/// @@brief User Wrapper: Get shared memory segment.
|
||||
int shmget(key_t key, size_t size, int flags);
|
||||
|
||||
/// @@brief User Wrapper: Attach shared memory segment.
|
||||
void *shmat(int shmid, void *shmaddr, int flag);
|
||||
|
||||
/// @@brief User Wrapper: Detach shared memory segment.
|
||||
int shmdt(void *shmaddr);
|
||||
|
||||
/// @@brief Find shmid_ds on list.
|
||||
struct shmid_ds *find_shm_fromid(int shmid);
|
||||
|
||||
/// @@brief Find shmid_ds on list.
|
||||
struct shmid_ds *find_shm_fromkey(key_t key);
|
||||
|
||||
/// @@brief shmid_ds on list.
|
||||
struct shmid_ds *find_shm_fromvaddr(void *shmvaddr);
|
||||
|
||||
#endif
|
||||
|
||||
#define SHM_RDONLY 010000 ///< Attach read-only else read-write.
|
||||
#define SHM_RND 020000 ///< Round attach address to SHMLBA.
|
||||
#define SHM_REMAP 040000 ///< Take-over region on attach.
|
||||
#define SHM_EXEC 0100000 ///< Execution access.
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
/// @brief Initializes the shared memory.
|
||||
/// @return 0 on success, 1 on failure.
|
||||
int shm_init(void);
|
||||
|
||||
/// @brief Get a System V shared memory identifier.
|
||||
/// @param key can be used either to obtain the identifier of a previously
|
||||
/// created shared memory, or to create a new one.
|
||||
/// @param size of the shared memory, rounded up to a multiple of PAGE_SIZE.
|
||||
/// @param flag controls the behaviour of the function.
|
||||
/// @param shmflg controls the behaviour of the function.
|
||||
/// @return the shared memory identifier, -1 on failure, and errno is set to
|
||||
/// indicate the error.
|
||||
long sys_shmget(key_t key, size_t size, int flag);
|
||||
long sys_shmget(key_t key, size_t size, int shmflg);
|
||||
|
||||
/// @brief Attaches the shared memory segment identified by shmid to the address
|
||||
/// space of the calling process.
|
||||
@@ -151,7 +108,7 @@ long sys_shmget(key_t key, size_t size, int flag);
|
||||
/// @param shmflg controls the behaviour of the function.
|
||||
/// @return returns the address of the attached shared memory segment; on error
|
||||
/// (void *) -1 is returned, and errno is set to indicate the error.
|
||||
void * sys_shmat(int shmid, const void *shmaddr, int shmflg);
|
||||
void *sys_shmat(int shmid, const void *shmaddr, int shmflg);
|
||||
|
||||
/// @brief Detaches the shared memory segment located at the address specified
|
||||
/// by shmaddr from the address space of the calling process
|
||||
@@ -174,10 +131,10 @@ long sys_shmctl(int shmid, int cmd, struct shmid_ds *buf);
|
||||
/// @param key can be used either to obtain the identifier of a previously
|
||||
/// created shared memory, or to create a new one.
|
||||
/// @param size of the shared memory, rounded up to a multiple of PAGE_SIZE.
|
||||
/// @param flag controls the behaviour of the function.
|
||||
/// @param shmflg controls the behaviour of the function.
|
||||
/// @return the shared memory identifier, -1 on failure, and errno is set to
|
||||
/// indicate the error.
|
||||
long shmget(key_t key, size_t size, int flag);
|
||||
long shmget(key_t key, size_t size, int shmflg);
|
||||
|
||||
/// @brief Attaches the shared memory segment identified by shmid to the address
|
||||
/// space of the calling process.
|
||||
@@ -186,7 +143,7 @@ long shmget(key_t key, size_t size, int flag);
|
||||
/// @param shmflg controls the behaviour of the function.
|
||||
/// @return returns the address of the attached shared memory segment; on error
|
||||
/// (void *) -1 is returned, and errno is set to indicate the error.
|
||||
void * shmat(int shmid, const void *shmaddr, int shmflg);
|
||||
void *shmat(int shmid, const void *shmaddr, int shmflg);
|
||||
|
||||
/// @brief Detaches the shared memory segment located at the address specified
|
||||
/// by shmaddr from the address space of the calling process
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file stat.h
|
||||
/// @brief Stat functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file types.h
|
||||
/// @brief Collection of Kernel datatype
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+24
-11
@@ -1,13 +1,13 @@
|
||||
/// @file unistd.h
|
||||
/// @brief Functions used to manage files.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "sys/dirent.h"
|
||||
#include "stddef.h"
|
||||
#include "sys/dirent.h"
|
||||
|
||||
#define STDIN_FILENO 0 ///< Standard input.
|
||||
#define STDOUT_FILENO 1 ///< Standard output.
|
||||
@@ -25,7 +25,7 @@ ssize_t read(int fd, void *buf, size_t nbytes);
|
||||
/// @param buf The buffer collecting data to written.
|
||||
/// @param nbytes The number of bytes to write.
|
||||
/// @return The number of written bytes.
|
||||
ssize_t write(int fd, void *buf, size_t nbytes);
|
||||
ssize_t write(int fd, const void *buf, size_t nbytes);
|
||||
|
||||
/// @brief Opens the file specified by pathname.
|
||||
/// @param pathname A pathname for a file.
|
||||
@@ -54,13 +54,26 @@ off_t lseek(int fd, off_t offset, int whence);
|
||||
/// @return
|
||||
int unlink(const char *path);
|
||||
|
||||
/// @brief Creates a symbolic link.
|
||||
/// @param linkname the name of the link.
|
||||
/// @param path the entity it is linking to.
|
||||
/// @return 0 on success, a negative number if fails and errno is set.
|
||||
int symlink(const char *linkname, const char *path);
|
||||
|
||||
/// @brief Read the symbolic link, if present.
|
||||
/// @param file the file for which we want to read the symbolic link information.
|
||||
/// @param buffer the buffer where we will store the symbolic link path.
|
||||
/// @param bufsize the size of the buffer.
|
||||
/// @return The number of read characters on success, -1 otherwise and errno is set to indicate the error.
|
||||
int readlink(const char *path, char *buffer, size_t bufsize);
|
||||
|
||||
/// @brief Wrapper for exit system call.
|
||||
/// @param status The exit status.
|
||||
extern void exit(int status);
|
||||
|
||||
/// @brief Returns the process ID (PID) of the calling process.
|
||||
/// @return pid_t process identifier.
|
||||
extern pid_t getpid();
|
||||
extern pid_t getpid(void);
|
||||
|
||||
///@brief Return session id of the given process.
|
||||
/// If pid == 0 return the SID of the calling process
|
||||
@@ -78,7 +91,7 @@ extern pid_t getsid(pid_t pid);
|
||||
/// is made the same as its process ID).
|
||||
///@return On success return SID of the session just created
|
||||
/// Otherwise return -1 with errno : EPERM
|
||||
extern pid_t setsid();
|
||||
extern pid_t setsid(void);
|
||||
|
||||
///@brief returns the Process Group ID (PGID) of the process specified by pid.
|
||||
/// If pid is zero, the process ID of the calling process is used.
|
||||
@@ -95,7 +108,7 @@ int setpgid(pid_t pid, pid_t pgid);
|
||||
|
||||
///@brief returns the group ID of the calling process.
|
||||
///@return GID of the current process
|
||||
extern pid_t getgid();
|
||||
extern pid_t getgid(void);
|
||||
|
||||
///@brief sets the effective group ID of the calling process.
|
||||
///@param pid process identifier to
|
||||
@@ -105,7 +118,7 @@ extern int setgid(pid_t pid);
|
||||
|
||||
///@brief Returns the User ID of the calling process.
|
||||
///@return User ID of the current process.
|
||||
extern uid_t getuid();
|
||||
extern uid_t getuid(void);
|
||||
|
||||
///@brief Sets the effective User ID of the calling process.
|
||||
///@param uid the new User ID.
|
||||
@@ -115,14 +128,14 @@ extern int setuid(uid_t uid);
|
||||
|
||||
/// @brief Returns the parent process ID (PPID) of the calling process.
|
||||
/// @return pid_t parent process identifier.
|
||||
extern pid_t getppid();
|
||||
extern pid_t getppid(void);
|
||||
|
||||
/// @brief Clone the calling process, but without copying the whole address space.
|
||||
/// The calling process is suspended until the new process exits or is
|
||||
/// replaced by a call to `execve'.
|
||||
/// @return Return -1 for errors, 0 to the new process, and the process ID of
|
||||
/// the new process to the old process.
|
||||
extern pid_t fork();
|
||||
extern pid_t fork(void);
|
||||
|
||||
/// @brief Replaces the current process image with a new process image (argument list).
|
||||
/// @param path The absolute path to the binary file to execute.
|
||||
@@ -238,7 +251,7 @@ int fchdir(int fd);
|
||||
/// @return On success, the number of bytes read is returned. On end of
|
||||
/// directory, 0 is returned. On error, -1 is returned, and errno is set
|
||||
/// appropriately.
|
||||
int getdents(int fd, dirent_t *dirp, unsigned int count);
|
||||
ssize_t getdents(int fd, dirent_t *dirp, unsigned int count);
|
||||
|
||||
/// @brief Send signal to calling thread after desired seconds.
|
||||
/// @param seconds the amount of seconds.
|
||||
@@ -246,4 +259,4 @@ int getdents(int fd, dirent_t *dirp, unsigned int count);
|
||||
/// shall return a non-zero value that is the number of seconds until the
|
||||
/// previous request would have generated a SIGALRM signal. Otherwise, alarm()
|
||||
/// shall return 0.
|
||||
int alarm(int seconds);
|
||||
unsigned alarm(int seconds);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file utsname.h
|
||||
/// @brief Functions used to provide information about the machine & OS.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file wait.h
|
||||
/// @brief Event management functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file syscall_types.h
|
||||
/// @brief System Call numbers.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -207,6 +207,17 @@
|
||||
return (type)(res); \
|
||||
} while (0)
|
||||
|
||||
// Few things about what follows:
|
||||
//
|
||||
// 1. The symbol "=", is a a constraint modifier, and it means that the operand
|
||||
// is write-only, meaning that the previous value is discarded and replaced
|
||||
// by output data.
|
||||
//
|
||||
// 2. Using "0" here specifies that the input is read from a variable which also
|
||||
// serves as an output, the 0-th output variable in this case.
|
||||
//
|
||||
//
|
||||
|
||||
/// @brief Heart of the code that calls a system call with 0 parameters.
|
||||
#define __inline_syscall0(res, name) \
|
||||
__asm__ __volatile__("int $0x80" \
|
||||
@@ -214,42 +225,39 @@
|
||||
: "0"(__NR_##name))
|
||||
|
||||
/// @brief Heart of the code that calls a system call with 1 parameter.
|
||||
#define __inline_syscall1(res, name, arg1) \
|
||||
__asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"((int)(arg1)) \
|
||||
#define __inline_syscall1(res, name, arg1) \
|
||||
__asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"(arg1) \
|
||||
: "memory");
|
||||
|
||||
/// @brief Heart of the code that calls a system call with 2 parameters.
|
||||
#define __inline_syscall2(res, name, arg1, arg2) \
|
||||
__asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)) \
|
||||
#define __inline_syscall2(res, name, arg1, arg2) \
|
||||
__asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"(arg1), "c"(arg2) \
|
||||
: "memory");
|
||||
|
||||
/// @brief Heart of the code that calls a system call with 3 parameters.
|
||||
#define __inline_syscall3(res, name, arg1, arg2, arg3) \
|
||||
__asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)), \
|
||||
"d"((int)(arg3)) \
|
||||
#define __inline_syscall3(res, name, arg1, arg2, arg3) \
|
||||
__asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3) \
|
||||
: "memory");
|
||||
|
||||
/// @brief Heart of the code that calls a system call with 4 parameters.
|
||||
#define __inline_syscall4(res, name, arg1, arg2, arg3, arg4) \
|
||||
__asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)), \
|
||||
"d"((int)(arg3)), "S"((int)(arg4)) \
|
||||
#define __inline_syscall4(res, name, arg1, arg2, arg3, arg4) \
|
||||
__asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "0"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3), "S"(arg4) \
|
||||
: "memory");
|
||||
|
||||
/// @brief Heart of the code that calls a system call with 5 parameters.
|
||||
#define __inline_syscall5(res, name, arg1, arg2, arg3, arg4, arg5) \
|
||||
__asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; movl %1,%%eax ; " \
|
||||
"int $0x80 ; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "i"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)), \
|
||||
"d"((int)(arg3)), "S"((int)(arg4)), "D"((int)(arg5)) \
|
||||
#define __inline_syscall5(res, name, arg1, arg2, arg3, arg4, arg5) \
|
||||
__asm__ __volatile__("push %%ebx; movl %2,%%ebx; movl %1,%%eax; " \
|
||||
"int $0x80; pop %%ebx" \
|
||||
: "=a"(res) \
|
||||
: "i"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3), "S"(arg4), "D"(arg5) \
|
||||
: "memory");
|
||||
|
||||
/// @brief System call with 0 parameters.
|
||||
@@ -305,3 +313,19 @@
|
||||
__inline_syscall5(__res, name, arg1, arg2, arg3, arg4, arg5); \
|
||||
__syscall_return(type, __res); \
|
||||
}
|
||||
|
||||
/// @brief System call with 5 parameters.
|
||||
#define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6) \
|
||||
type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \
|
||||
{ \
|
||||
long __res; \
|
||||
unsigned args[6] = { 0 }; \
|
||||
args[0] = (unsigned)arg1; \
|
||||
args[1] = (unsigned)arg2; \
|
||||
args[2] = (unsigned)arg3; \
|
||||
args[3] = (unsigned)arg4; \
|
||||
args[4] = (unsigned)arg5; \
|
||||
args[5] = (unsigned)arg6; \
|
||||
__inline_syscall1(__res, name, args); \
|
||||
__syscall_return(type, __res); \
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file termios.h
|
||||
/// @brief Defines the termios functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file time.h
|
||||
/// @brief Time-related functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
+2
-3
@@ -1,12 +1,12 @@
|
||||
/// @file abort.c
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "string.h"
|
||||
#include "signal.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
/// @brief Since there could be signal handlers listening for the abort, we need
|
||||
/// to keep track at which stage of the abort we are.
|
||||
@@ -28,7 +28,6 @@ void abort(void)
|
||||
|
||||
/* Send signal which possibly calls a user handler. */
|
||||
if (stage == 1) {
|
||||
|
||||
// We must allow recursive calls of abort
|
||||
int save_stage = stage;
|
||||
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
/// @file assert.c
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
void __assert_fail(const char *assertion, const char *file, const char *function, unsigned int line)
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// @file ctype.c
|
||||
/// @brief Functions related to character handling.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "ctype.h"
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/// @file debug.c
|
||||
/// @brief Debugging primitives.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <io/port_io.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/bitops.h>
|
||||
#include <math.h>
|
||||
|
||||
/// Serial port for QEMU.
|
||||
#define SERIAL_COM1 (0x03F8)
|
||||
|
||||
#define FG_RESET "\033[0m" ///< ANSI code for resetting.
|
||||
|
||||
void dbg_putchar(char c)
|
||||
{
|
||||
outportb(SERIAL_COM1, (uint8_t)c);
|
||||
}
|
||||
|
||||
void dbg_puts(const char *s)
|
||||
{
|
||||
while ((*s) != 0)
|
||||
dbg_putchar(*s++);
|
||||
}
|
||||
|
||||
static inline void __debug_print_header(const char *file, const char *fun, int line)
|
||||
{
|
||||
static char tmp_prefix[BUFSIZ], final_prefix[BUFSIZ];
|
||||
dbg_puts(FG_RESET);
|
||||
dbg_puts("[ LB |");
|
||||
sprintf(tmp_prefix, "%s:%d", file, line);
|
||||
sprintf(final_prefix, " %-20s ", tmp_prefix);
|
||||
dbg_puts(final_prefix);
|
||||
#if 0
|
||||
dbg_putchar('|');
|
||||
sprintf(final_prefix, " %-25s ]", fun);
|
||||
dbg_puts(final_prefix);
|
||||
#else
|
||||
dbg_putchar(']');
|
||||
#endif
|
||||
}
|
||||
|
||||
void dbg_printf(const char *file, const char *fun, int line, const char *format, ...)
|
||||
{
|
||||
// Define a buffer for the formatted string.
|
||||
static char formatted[BUFSIZ];
|
||||
static short new_line = 1;
|
||||
|
||||
// Stage 1: FORMAT
|
||||
if (strlen(format) >= BUFSIZ)
|
||||
return;
|
||||
|
||||
// Start variabile argument's list.
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
// Format the message.
|
||||
vsprintf(formatted, format, ap);
|
||||
// End the list of arguments.
|
||||
va_end(ap);
|
||||
|
||||
// Stage 2: SEND
|
||||
if (new_line) {
|
||||
__debug_print_header(file, fun, line);
|
||||
new_line = 0;
|
||||
}
|
||||
for (size_t it = 0; (formatted[it] != 0) && (it < BUFSIZ); ++it) {
|
||||
dbg_putchar(formatted[it]);
|
||||
if (formatted[it] != '\n') {
|
||||
continue;
|
||||
}
|
||||
if ((it + 1) >= BUFSIZ) {
|
||||
continue;
|
||||
}
|
||||
if (formatted[it + 1] == 0) {
|
||||
new_line = 1;
|
||||
} else {
|
||||
__debug_print_header(file, fun, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *to_human_size(unsigned long bytes)
|
||||
{
|
||||
static char output[200];
|
||||
const char *suffix[] = { "B", "KB", "MB", "GB", "TB" };
|
||||
char length = sizeof(suffix) / sizeof(suffix[0]);
|
||||
int i = 0;
|
||||
double dblBytes = bytes;
|
||||
if (bytes > 1024) {
|
||||
for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024)
|
||||
dblBytes = bytes / 1024.0;
|
||||
}
|
||||
sprintf(output, "%.03lf %2s", dblBytes, suffix[i]);
|
||||
return output;
|
||||
}
|
||||
|
||||
const char *dec_to_binary(unsigned long value, unsigned length)
|
||||
{
|
||||
static char buffer[33];
|
||||
for (int i = 0, j = 32 - min(max(0, length), 32); j < 32; ++i, ++j)
|
||||
buffer[i] = bit_check(value, 31 - j) ? '1' : '0';
|
||||
return buffer;
|
||||
}
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
/// @file fcvt.c
|
||||
/// @brief Define the functions required to turn double values into a string.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "fcvt.h"
|
||||
@@ -83,8 +83,9 @@ static void cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, unsig
|
||||
*p1 = '1';
|
||||
(*decpt)++;
|
||||
if (eflag == 0) {
|
||||
if (p > buf)
|
||||
if (p > buf) {
|
||||
*p = '0';
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
+51
-32
@@ -1,59 +1,72 @@
|
||||
/// @file grp.c
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "grp.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "sys/errno.h"
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "debug.h"
|
||||
#include "fcntl.h"
|
||||
#include "io/debug.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/unistd.h"
|
||||
|
||||
/// Holds the file descriptor while we are working with `/etc/group`.
|
||||
static int __fd = -1;
|
||||
|
||||
/// @brief It parses the line (as string) and saves its content inside the
|
||||
/// group_t structure.
|
||||
/// @param grp the struct where we store the information.
|
||||
/// @param buf the buffer from which we extract the information.
|
||||
/// @param buf the line from which we extract the information.
|
||||
static inline void __parse_line(group_t *grp, char *buf)
|
||||
{
|
||||
assert(grp && "Received null grp!");
|
||||
char *token;
|
||||
// Parse the group name.
|
||||
if ((token = strtok(buf, ":")) != NULL)
|
||||
token = strtok(buf, ":");
|
||||
if (token != NULL) {
|
||||
grp->gr_name = token;
|
||||
}
|
||||
// Parse the group passwd.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
token = strtok(NULL, ":");
|
||||
if (token != NULL) {
|
||||
grp->gr_passwd = token;
|
||||
}
|
||||
// Parse the group id.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
token = strtok(NULL, ":");
|
||||
if (token != NULL) {
|
||||
grp->gr_gid = atoi(token);
|
||||
|
||||
}
|
||||
size_t found_users = 0;
|
||||
while ((token = strtok(NULL, ",\n\0")) != NULL && found_users < MAX_MEMBERS_PER_GROUP) {
|
||||
grp->gr_mem[found_users] = token;
|
||||
found_users += 1;
|
||||
}
|
||||
|
||||
// Null terminate array
|
||||
grp->gr_mem[found_users] = "\0";
|
||||
}
|
||||
|
||||
static inline char *__search_entry(int fd, char *buf, int buflen, const char *name, gid_t gid)
|
||||
/// @brief Searches an entry in `/etc/group`.
|
||||
/// @param fd the file descriptor pointing to `/etc/group`.
|
||||
/// @param buf the buffer we are going to use to search the entry.
|
||||
/// @param buflen the length of the buffer.
|
||||
/// @param name the name we are looking for.
|
||||
/// @param gid the group id we must match.
|
||||
/// @return 1 on success, 0 on failure.
|
||||
static inline int __search_entry(int fd, char *buf, size_t buflen, const char *name, gid_t gid)
|
||||
{
|
||||
int ret;
|
||||
char c;
|
||||
int pos = 0;
|
||||
while ((ret = read(fd, &c, 1U))) {
|
||||
// Skip carriage return.
|
||||
if (c == '\r')
|
||||
if (c == '\r') {
|
||||
continue;
|
||||
}
|
||||
if (pos >= buflen) {
|
||||
errno = ERANGE;
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
// If we have found a newline or the EOF, parse the entry.
|
||||
if ((c == '\n') || (ret == EOF)) {
|
||||
@@ -61,8 +74,9 @@ static inline char *__search_entry(int fd, char *buf, int buflen, const char *na
|
||||
buf[pos] = 0;
|
||||
// Check the entry.
|
||||
if (name) {
|
||||
if (strncmp(buf, name, strlen(name)) == 0)
|
||||
return buf;
|
||||
if (strncmp(buf, name, strlen(name)) == 0) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
int gid_start = -1, col_count = 0;
|
||||
for (int i = 0; i < pos; ++i) {
|
||||
@@ -77,21 +91,23 @@ static inline char *__search_entry(int fd, char *buf, int buflen, const char *na
|
||||
// Parse the gid.
|
||||
int found_gid = atoi(&buf[gid_start]);
|
||||
// Check the gid.
|
||||
if (found_gid == gid)
|
||||
return buf;
|
||||
if (found_gid == gid) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reset the index.
|
||||
pos = 0;
|
||||
// If we have reached the EOF stop.
|
||||
if (ret == EOF)
|
||||
if (ret == EOF) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
buf[pos++] = c;
|
||||
}
|
||||
}
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
group_t *getgrgid(gid_t gid)
|
||||
@@ -100,23 +116,26 @@ group_t *getgrgid(gid_t gid)
|
||||
static char buffer[BUFSIZ];
|
||||
|
||||
group_t *result;
|
||||
if (!getgrgid_r(gid, &grp, buffer, BUFSIZ, &result))
|
||||
if (!getgrgid_r(gid, &grp, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &grp;
|
||||
}
|
||||
|
||||
group_t *getgrnam(const char *name)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static group_t grp;
|
||||
static char buffer[BUFSIZ];
|
||||
|
||||
group_t *result;
|
||||
if (!getgrnam_r(name, &grp, buffer, BUFSIZ, &result))
|
||||
if (!getgrnam_r(name, &grp, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &grp;
|
||||
}
|
||||
@@ -130,12 +149,11 @@ int getgrgid_r(gid_t gid, group_t *group, char *buf, size_t buflen, group_t **re
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *entry = __search_entry(fd, buf, buflen, NULL, gid);
|
||||
if (entry != NULL) {
|
||||
if (__search_entry(fd, buf, buflen, NULL, gid)) {
|
||||
// Close the file.
|
||||
close(fd);
|
||||
// Parse the line.
|
||||
__parse_line(group, entry);
|
||||
__parse_line(group, buf);
|
||||
// Return success.
|
||||
return 1;
|
||||
}
|
||||
@@ -155,12 +173,11 @@ int getgrnam_r(const char *name, group_t *group, char *buf, size_t buflen, group
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *entry = __search_entry(fd, buf, buflen, name, 0);
|
||||
if (entry != NULL) {
|
||||
if (__search_entry(fd, buf, buflen, name, 0)) {
|
||||
// Close the file.
|
||||
close(fd);
|
||||
// Parse the line.
|
||||
__parse_line(group, entry);
|
||||
__parse_line(group, buf);
|
||||
// Return success.
|
||||
return 1;
|
||||
}
|
||||
@@ -191,8 +208,9 @@ group_t *getgrent(void)
|
||||
static char buffer[BUFSIZ];
|
||||
while ((ret = read(__fd, &c, 1U))) {
|
||||
// Skip carriage return.
|
||||
if (c == '\r')
|
||||
if (c == '\r') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pos >= BUFSIZ) {
|
||||
errno = ERANGE;
|
||||
@@ -212,8 +230,9 @@ group_t *getgrent(void)
|
||||
}
|
||||
|
||||
// If we have reached the EOF stop.
|
||||
if (ret == EOF)
|
||||
if (ret == EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
buffer[pos++] = c;
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/// @file debug.c
|
||||
/// @brief Debugging primitives.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "io/debug.h"
|
||||
#include "io/ansi_colors.h"
|
||||
#include "io/port_io.h"
|
||||
#include "math.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/bitops.h"
|
||||
|
||||
/// Serial port for QEMU.
|
||||
#define SERIAL_COM1 (0x03F8)
|
||||
/// Determines the log level.
|
||||
static int max_log_level = LOGLEVEL_DEBUG;
|
||||
|
||||
void dbg_putchar(char c)
|
||||
{
|
||||
outportb(SERIAL_COM1, (unsigned char)c);
|
||||
}
|
||||
|
||||
void dbg_puts(const char *s)
|
||||
{
|
||||
while ((*s) != 0) {
|
||||
dbg_putchar(*s++);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void __debug_print_header(const char *file, const char *fun, int line, short log_level, char *header)
|
||||
{
|
||||
// "EMERG ", "ALERT ", "CRIT ", "ERR ", "WARNING", "NOTICE ", "INFO ", "DEBUG ", "DEFAULT",
|
||||
static const char *log_level_label[] = { " EM ", " AL ", " CR ", " ER ", " WR ", " NT ", " IN ", " DB ", " DF " };
|
||||
static const char *log_level_color[] = {
|
||||
FG_RED_BRIGHT, // "EMERG "
|
||||
FG_RED_BRIGHT, // "ALERT "
|
||||
FG_RED, // "CRIT "
|
||||
FG_RED, // "ERR "
|
||||
FG_YELLOW_BRIGHT, // "WARNING"
|
||||
FG_RESET, // "NOTICE "
|
||||
FG_CYAN, // "INFO "
|
||||
FG_YELLOW, // "DEBUG "
|
||||
FG_RESET // "DEFAULT"
|
||||
};
|
||||
static char tmp_prefix[BUFSIZ], final_prefix[BUFSIZ];
|
||||
// Check the log level.
|
||||
if ((log_level < LOGLEVEL_EMERG) || (log_level > LOGLEVEL_DEBUG)) {
|
||||
// Set it to default.
|
||||
log_level = 8;
|
||||
}
|
||||
// Set the color.
|
||||
dbg_puts(log_level_color[log_level]);
|
||||
dbg_putchar('[');
|
||||
// Set the label.
|
||||
dbg_puts(log_level_label[log_level]);
|
||||
dbg_putchar('|');
|
||||
// Print the file and line.
|
||||
sprintf(tmp_prefix, "%s:%d", file, line);
|
||||
// Print the message.
|
||||
sprintf(final_prefix, " %-20s ", tmp_prefix);
|
||||
// Print the actual message.
|
||||
dbg_puts(final_prefix);
|
||||
#if 0
|
||||
dbg_putchar('|');
|
||||
sprintf(final_prefix, " %-25s ]", fun);
|
||||
dbg_puts(final_prefix);
|
||||
#else
|
||||
dbg_putchar(']');
|
||||
#endif
|
||||
dbg_putchar(' ');
|
||||
if (header) {
|
||||
dbg_puts(header);
|
||||
dbg_putchar(' ');
|
||||
}
|
||||
}
|
||||
|
||||
void set_log_level(int level)
|
||||
{
|
||||
if ((level >= LOGLEVEL_EMERG) && (level <= LOGLEVEL_DEBUG)) {
|
||||
max_log_level = level;
|
||||
}
|
||||
}
|
||||
|
||||
int get_log_level(void)
|
||||
{
|
||||
return max_log_level;
|
||||
}
|
||||
|
||||
void dbg_printf(const char *file, const char *fun, int line, char *header, short log_level, const char *format, ...)
|
||||
{
|
||||
// Define a buffer for the formatted string.
|
||||
static char formatted[BUFSIZ];
|
||||
static short new_line = 1;
|
||||
|
||||
// Stage 1: FORMAT
|
||||
if (strlen(format) >= BUFSIZ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start variabile argument's list.
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
// Format the message.
|
||||
vsprintf(formatted, format, ap);
|
||||
// End the list of arguments.
|
||||
va_end(ap);
|
||||
|
||||
// Stage 2: SEND
|
||||
if (new_line) {
|
||||
__debug_print_header(file, fun, line, log_level, header);
|
||||
new_line = 0;
|
||||
}
|
||||
for (int it = 0; (formatted[it] != 0) && (it < BUFSIZ); ++it) {
|
||||
dbg_putchar(formatted[it]);
|
||||
if (formatted[it] != '\n') {
|
||||
continue;
|
||||
}
|
||||
if ((it + 1) >= BUFSIZ) {
|
||||
continue;
|
||||
}
|
||||
if (formatted[it + 1] == 0) {
|
||||
new_line = 1;
|
||||
} else {
|
||||
__debug_print_header(file, fun, line, log_level, header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *to_human_size(unsigned long bytes)
|
||||
{
|
||||
static char output[200];
|
||||
const char *suffix[] = { "B", "KB", "MB", "GB", "TB" };
|
||||
char length = sizeof(suffix) / sizeof(suffix[0]);
|
||||
int i = 0;
|
||||
double dblBytes = bytes;
|
||||
if (bytes > 1024) {
|
||||
for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024) {
|
||||
dblBytes = bytes / 1024.0;
|
||||
}
|
||||
}
|
||||
sprintf(output, "%.02lf %2s", dblBytes, suffix[i]);
|
||||
return output;
|
||||
}
|
||||
|
||||
const char *dec_to_binary(unsigned long value, unsigned length)
|
||||
{
|
||||
static char buffer[33];
|
||||
// Adjust the length.
|
||||
length = min(max(0, length), 32U);
|
||||
// Build the binary.
|
||||
for (unsigned i = 0, j = 32U - length; j < 32U; ++i, ++j) {
|
||||
buffer[i] = bit_check(value, 31 - j) ? '1' : '0';
|
||||
}
|
||||
// Close the string.
|
||||
buffer[length] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
void dbg_print_regs(pt_regs *frame)
|
||||
{
|
||||
pr_debug("Interrupt stack frame:\n");
|
||||
pr_debug("GS = 0x%-04x\n", frame->gs);
|
||||
pr_debug("FS = 0x%-04x\n", frame->fs);
|
||||
pr_debug("ES = 0x%-04x\n", frame->es);
|
||||
pr_debug("DS = 0x%-04x\n", frame->ds);
|
||||
pr_debug("EDI = 0x%-09x\n", frame->edi);
|
||||
pr_debug("ESI = 0x%-09x\n", frame->esi);
|
||||
pr_debug("EBP = 0x%-09x\n", frame->ebp);
|
||||
pr_debug("ESP = 0x%-09x\n", frame->esp);
|
||||
pr_debug("EBX = 0x%-09x\n", frame->ebx);
|
||||
pr_debug("EDX = 0x%-09x\n", frame->edx);
|
||||
pr_debug("ECX = 0x%-09x\n", frame->ecx);
|
||||
pr_debug("EAX = 0x%-09x\n", frame->eax);
|
||||
pr_debug("INT_NO = %-9d\n", frame->int_no);
|
||||
pr_debug("ERR_CD = %-9d\n", frame->err_code);
|
||||
pr_debug("EIP = 0x%-09x\n", frame->eip);
|
||||
pr_debug("CS = 0x%-04x\n", frame->cs);
|
||||
pr_debug("EFLAGS = 0x%-09x\n", frame->eflags);
|
||||
pr_debug("UESP = 0x%-09x\n", frame->useresp);
|
||||
pr_debug("SS = 0x%-04x\n", frame->ss);
|
||||
}
|
||||
|
||||
#endif
|
||||
+7
-7
@@ -1,36 +1,36 @@
|
||||
/// @file mm_io.c
|
||||
/// @brief Memory Mapped IO functions implementation.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "io/mm_io.h"
|
||||
|
||||
uint8_t in_memb(uint32_t addr)
|
||||
inline uint8_t in_memb(uint32_t addr)
|
||||
{
|
||||
return *((uint8_t *) (addr));
|
||||
}
|
||||
|
||||
uint16_t in_mems(uint32_t addr)
|
||||
inline uint16_t in_mems(uint32_t addr)
|
||||
{
|
||||
return *((uint16_t *) (addr));
|
||||
}
|
||||
|
||||
uint32_t in_meml(uint32_t addr)
|
||||
inline uint32_t in_meml(uint32_t addr)
|
||||
{
|
||||
return *((uint32_t *) (addr));
|
||||
}
|
||||
|
||||
void out_memb(uint32_t addr, uint8_t value)
|
||||
inline void out_memb(uint32_t addr, uint8_t value)
|
||||
{
|
||||
(*((uint8_t *) (addr))) = (value);
|
||||
}
|
||||
|
||||
void out_mems(uint32_t addr, uint16_t value)
|
||||
inline void out_mems(uint32_t addr, uint16_t value)
|
||||
{
|
||||
(*((uint16_t *) (addr))) = (value);
|
||||
}
|
||||
|
||||
void out_meml(uint32_t addr, uint32_t value)
|
||||
inline void out_meml(uint32_t addr, uint32_t value)
|
||||
{
|
||||
(*((uint32_t *) (addr))) = (value);
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/// @file port_io.c
|
||||
/// @brief Byte I/O on ports prototypes.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "io/port_io.h"
|
||||
|
||||
inline uint8_t inportb(uint16_t port)
|
||||
{
|
||||
unsigned char data = 0;
|
||||
__asm__ __volatile__("inb %%dx, %%al" : "=a"(data) : "d"(port));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
inline uint16_t inports(uint16_t port)
|
||||
{
|
||||
uint16_t rv;
|
||||
__asm__ __volatile__("inw %1, %0" : "=a"(rv) : "dN"(port));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void inportsm(uint16_t port, uint8_t *data, unsigned long size)
|
||||
{
|
||||
__asm__ __volatile__("rep insw"
|
||||
: "+D"(data), "+c"(size)
|
||||
: "d"(port)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
inline uint32_t inportl(uint16_t port)
|
||||
{
|
||||
uint32_t rv;
|
||||
__asm__ __volatile__("inl %%dx, %%eax" : "=a"(rv) : "dN"(port));
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline void outportb(uint16_t port, uint8_t data)
|
||||
{
|
||||
__asm__ __volatile__("outb %%al, %%dx" ::"a"(data), "d"(port));
|
||||
}
|
||||
|
||||
inline void outports(uint16_t port, uint16_t data)
|
||||
{
|
||||
__asm__ __volatile__("outw %1, %0" : : "dN"(port), "a"(data));
|
||||
}
|
||||
|
||||
void outportsm(uint16_t port, uint8_t *data, uint16_t size)
|
||||
{
|
||||
__asm__ __volatile__("rep outsw" : "+S"(data), "+c"(size) : "d"(port));
|
||||
}
|
||||
|
||||
inline void outportl(uint16_t port, uint32_t data)
|
||||
{
|
||||
__asm__ __volatile__("outl %%eax, %%dx" : : "dN"(port), "a"(data));
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/// @file ipc.c
|
||||
/// @brief Inter-Process Communication (IPC) system call implementation.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "stddef.h"
|
||||
#include "ipc/sem.h"
|
||||
#include "ipc/shm.h"
|
||||
#include "ipc/msg.h"
|
||||
|
||||
_syscall3(void *, shmat, int, shmid, const void *, shmaddr, int, shmflg)
|
||||
|
||||
_syscall3(long, shmget, key_t, key, size_t, size, int, flag)
|
||||
|
||||
_syscall1(long, shmdt, const void *, shmaddr)
|
||||
|
||||
_syscall3(long, shmctl, int, shmid, int, cmd, struct shmid_ds *, buf)
|
||||
|
||||
_syscall3(long, semget, key_t, key, int, nsems, int, semflg)
|
||||
|
||||
_syscall3(long, semop, int, semid, struct sembuf *, sops, unsigned, nsops)
|
||||
|
||||
_syscall4(long, semctl, int, semid, int, semnum, int, cmd, unsigned long, arg)
|
||||
|
||||
_syscall2(long, msgget, key_t, key, int, msgflg)
|
||||
|
||||
_syscall4(long, msgsnd, int, msqid, struct msgbuf *, msgp, size_t, msgsz, int, msgflg)
|
||||
|
||||
_syscall5(long, msgrcv, int, msqid, struct msgbuf *, msgp, size_t, msgsz, long, msgtyp, int, msgflg)
|
||||
|
||||
_syscall3(long, msgctl, int, msqid, int, cmd, struct msqid_ds *, buf)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/// @file libc_start.c
|
||||
/// @brief Contains the programs initialization procedure.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/unistd.h"
|
||||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "assert.h"
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
/// @brief Reference to the `environ` variable in `setenv.c`.
|
||||
extern char **environ;
|
||||
|
||||
+53
-69
@@ -1,85 +1,64 @@
|
||||
/// @file libgen.c
|
||||
/// @brief String routines.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "libgen.h"
|
||||
#include "io/debug.h"
|
||||
#include "limits.h"
|
||||
#include "string.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/unistd.h>
|
||||
#include "libgen.h"
|
||||
#include "string.h"
|
||||
#include "limits.h"
|
||||
|
||||
int parse_path(char *out, char **cur, char sep, size_t max)
|
||||
int dirname(const char *path, char *buffer, size_t buflen)
|
||||
{
|
||||
if (**cur == '\0') {
|
||||
if ((path == NULL) || (buffer == NULL) || (buflen == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out++ = **cur;
|
||||
++*cur;
|
||||
--max;
|
||||
|
||||
while ((max > 0) && (**cur != '\0') && (**cur != sep)) {
|
||||
*out++ = **cur;
|
||||
++*cur;
|
||||
--max;
|
||||
// Search for the last slash.
|
||||
const char *last_slash = NULL;
|
||||
for (const char *it = path; *it; it++) {
|
||||
if ((*it) == '/') {
|
||||
last_slash = it;
|
||||
}
|
||||
}
|
||||
// If we were able to find a slash, and the slash is not in the first
|
||||
// position, copy the substring.
|
||||
if (last_slash) {
|
||||
// Get the length of the substring, if the last slash is at the beginning,
|
||||
// add 1.
|
||||
size_t dirlen = last_slash - path + (last_slash == path);
|
||||
// Check if the path will fit inside the buffer.
|
||||
if (dirlen >= buflen) {
|
||||
return 0;
|
||||
}
|
||||
// Copy the substring.
|
||||
strncpy(buffer, path, dirlen);
|
||||
// Close the buffer.
|
||||
buffer[dirlen] = 0;
|
||||
} else {
|
||||
strcpy(buffer, ".");
|
||||
}
|
||||
|
||||
*out = '\0';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *dirname(const char *path)
|
||||
const char *basename(const char *path)
|
||||
{
|
||||
static char s[PATH_MAX];
|
||||
|
||||
static char dot[2] = ".";
|
||||
|
||||
// Check the input path.
|
||||
if (path == NULL) {
|
||||
return dot;
|
||||
// Search for the last slash.
|
||||
const char *last_slash = NULL;
|
||||
for (const char *it = path; *it; it++) {
|
||||
if ((*it) == '/') {
|
||||
last_slash = it;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the path to the support string.
|
||||
strcpy(s, path);
|
||||
|
||||
// Get the last occurrence of '/'.
|
||||
char *last_slash = strrchr(s, '/');
|
||||
|
||||
if (last_slash == s) {
|
||||
// If the slash is acutally the first character of the string, move the
|
||||
// pointer to the last slash after it.
|
||||
++last_slash;
|
||||
} else if ((last_slash != NULL) && (last_slash[1] == '\0')) {
|
||||
// If the slash is the last character, we need to search before it.
|
||||
last_slash = memchr(s, '/', last_slash - s);
|
||||
}
|
||||
|
||||
if (last_slash != NULL) {
|
||||
// If we have found it, close the string.
|
||||
last_slash[0] = '\0';
|
||||
} else {
|
||||
// Otherwise, return '.'.
|
||||
return dot;
|
||||
}
|
||||
|
||||
return s;
|
||||
return last_slash ? last_slash + 1 : path;
|
||||
}
|
||||
|
||||
char *basename(const char *path)
|
||||
{
|
||||
char *p = strrchr(path, '/');
|
||||
|
||||
return p ? p + 1 : (char *)path;
|
||||
}
|
||||
|
||||
char *realpath(const char *path, char *resolved)
|
||||
char *realpath(const char *path, char *buffer, size_t buflen)
|
||||
{
|
||||
assert(path && "Provided null path.");
|
||||
if (resolved == NULL)
|
||||
resolved = malloc(sizeof(char) * PATH_MAX);
|
||||
assert(buffer && "Provided null buffer.");
|
||||
char abspath[PATH_MAX];
|
||||
// Initialize the absolute path.
|
||||
memset(abspath, '\0', PATH_MAX);
|
||||
@@ -119,22 +98,27 @@ char *realpath(const char *path, char *resolved)
|
||||
// Go to previous directory if /../ is found
|
||||
else if (!strncmp("/../", abspath + absidx, 4)) {
|
||||
// Go to a valid path character (pathidx points to the next one)
|
||||
if (pathidx)
|
||||
if (pathidx) {
|
||||
pathidx--;
|
||||
while (pathidx && resolved[pathidx] != '/') {
|
||||
}
|
||||
while (pathidx && buffer[pathidx] != '/') {
|
||||
pathidx--;
|
||||
}
|
||||
absidx += 3;
|
||||
} else if (!strncmp("/./", abspath + absidx, 3)) {
|
||||
absidx += 2;
|
||||
} else {
|
||||
resolved[pathidx++] = abspath[absidx++];
|
||||
if ((pathidx + 1) >= buflen) {
|
||||
return NULL;
|
||||
}
|
||||
buffer[pathidx++] = abspath[absidx++];
|
||||
}
|
||||
}
|
||||
// Remove the last /
|
||||
if (pathidx > 1)
|
||||
resolved[pathidx - 1] = '\0';
|
||||
else
|
||||
resolved[1] = '\0';
|
||||
return resolved;
|
||||
if (pathidx > 1) {
|
||||
buffer[pathidx - 1] = '\0';
|
||||
} else {
|
||||
buffer[1] = '\0';
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
+11
-6
@@ -1,6 +1,6 @@
|
||||
/// @file math.c
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "math.h"
|
||||
@@ -18,26 +18,30 @@ double round(double x)
|
||||
double floor(double x)
|
||||
{
|
||||
if (x > -1.0 && x < 1.0) {
|
||||
if (x >= 0)
|
||||
if (x >= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
int i = (int)x;
|
||||
if (x < 0)
|
||||
if (x < 0) {
|
||||
return (double)(i - 1);
|
||||
}
|
||||
return (double)i;
|
||||
}
|
||||
|
||||
double ceil(double x)
|
||||
{
|
||||
if (x > -1.0 && x < 1.0) {
|
||||
if (x <= 0)
|
||||
if (x <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
int i = (int)x;
|
||||
if (x > 0)
|
||||
if (x > 0) {
|
||||
return (double)(i + 1);
|
||||
}
|
||||
return (double)i;
|
||||
}
|
||||
|
||||
@@ -145,8 +149,9 @@ double ln(double x)
|
||||
double logx(double x, double y)
|
||||
{
|
||||
// Base may not equal 1 or be negative.
|
||||
if (y == 1.f || y < 0.f || ln(y) == 0.f)
|
||||
if (y == 1.f || y < 0.f || ln(y) == 0.f) {
|
||||
return 0.f;
|
||||
}
|
||||
return ln(x) / ln(y);
|
||||
}
|
||||
|
||||
|
||||
+40
-56
@@ -1,84 +1,61 @@
|
||||
/// @file pwd.c
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "pwd.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "sys/errno.h"
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "fcntl.h"
|
||||
#include "debug.h"
|
||||
#include "io/debug.h"
|
||||
#include "readline.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sys/unistd.h"
|
||||
|
||||
/// @brief Parses the input buffer and fills pwd with its details.
|
||||
/// @param pwd the structure we need to fill.
|
||||
/// @param buf the buffer from which we extract the information.
|
||||
static inline void __parse_line(passwd_t *pwd, char *buf)
|
||||
{
|
||||
assert(pwd && "Received null pwd!");
|
||||
char *token, *ch;
|
||||
// Parse the username.
|
||||
if ((token = strtok(buf, ":")) != NULL)
|
||||
if ((token = strtok(buf, ":")) != NULL) {
|
||||
pwd->pw_name = token;
|
||||
}
|
||||
// Parse the password.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_passwd = token;
|
||||
}
|
||||
// Parse the user ID.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_uid = atoi(token);
|
||||
}
|
||||
// Parse the group ID.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_gid = atoi(token);
|
||||
}
|
||||
// Parse the user information.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_gecos = token;
|
||||
}
|
||||
// Parse the dir.
|
||||
if ((token = strtok(NULL, ":")) != NULL)
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_dir = token;
|
||||
}
|
||||
// Parse the shell.
|
||||
if ((token = strtok(NULL, ":")) != NULL) {
|
||||
pwd->pw_shell = token;
|
||||
// Find carriege return.
|
||||
if ((ch = strchr(pwd->pw_shell, '\r')))
|
||||
if ((ch = strchr(pwd->pw_shell, '\r'))) {
|
||||
*ch = 0;
|
||||
}
|
||||
// Find newline.
|
||||
if ((ch = strchr(pwd->pw_shell, '\n')))
|
||||
if ((ch = strchr(pwd->pw_shell, '\n'))) {
|
||||
*ch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Reads a line from the file.
|
||||
/// @param fd the file descriptor.
|
||||
/// @param buffer the buffer where we place the line.
|
||||
/// @param buflen the length of the buffer.
|
||||
/// @return the amount we read.
|
||||
ssize_t __readline(int fd, char *buffer, size_t buflen)
|
||||
{
|
||||
memset(buffer, 0, buflen);
|
||||
long num_read = read(fd, buffer, buflen);
|
||||
if (num_read == 0) {
|
||||
return 0;
|
||||
}
|
||||
char *newline = strchr(buffer, '\n');
|
||||
if (newline == NULL) {
|
||||
newline = strchr(buffer, EOF);
|
||||
if (newline == NULL) {
|
||||
newline = strchr(buffer, 0);
|
||||
if (newline == NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
long newline_len = (int)(newline - buffer);
|
||||
if (newline_len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
buffer[newline_len] = 0;
|
||||
long rollback = newline_len - num_read + 1;
|
||||
if (rollback > 1) {
|
||||
return 0;
|
||||
}
|
||||
lseek(fd, rollback, SEEK_CUR);
|
||||
return newline_len;
|
||||
}
|
||||
|
||||
/// @brief Searches for the given entry inside the buffer.
|
||||
@@ -90,7 +67,7 @@ ssize_t __readline(int fd, char *buffer, size_t buflen)
|
||||
/// @return the buffer itself if we have found the entry, NULL otherwise.
|
||||
static inline char *__search_entry(int fd, char *buffer, int buflen, const char *name, uid_t uid)
|
||||
{
|
||||
while (__readline(fd, buffer, buflen)) {
|
||||
while (readline(fd, buffer, buflen, NULL) != 0) {
|
||||
if (name != NULL) {
|
||||
char *name_end = strchr(buffer, ':');
|
||||
if (name_end) {
|
||||
@@ -103,17 +80,20 @@ static inline char *__search_entry(int fd, char *buffer, int buflen, const char
|
||||
} else {
|
||||
// Name
|
||||
char *ptr = strchr(buffer, ':');
|
||||
if (ptr == NULL)
|
||||
if (ptr == NULL) {
|
||||
continue;
|
||||
}
|
||||
// Password
|
||||
++ptr;
|
||||
char *uid_start = strchr(ptr, ':');
|
||||
if (uid_start == NULL)
|
||||
if (uid_start == NULL) {
|
||||
continue;
|
||||
}
|
||||
++uid_start;
|
||||
ptr = strchr(uid_start, ':');
|
||||
if (ptr == NULL)
|
||||
if (ptr == NULL) {
|
||||
continue;
|
||||
}
|
||||
*ptr = '\0';
|
||||
// Parse the uid.
|
||||
int found_uid = atoi(uid_start);
|
||||
@@ -129,13 +109,15 @@ static inline char *__search_entry(int fd, char *buffer, int buflen, const char
|
||||
|
||||
passwd_t *getpwnam(const char *name)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
static passwd_t pwd;
|
||||
static char buffer[BUFSIZ];
|
||||
passwd_t *result;
|
||||
if (!getpwnam_r(name, &pwd, buffer, BUFSIZ, &result))
|
||||
if (!getpwnam_r(name, &pwd, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
return &pwd;
|
||||
}
|
||||
|
||||
@@ -144,15 +126,17 @@ passwd_t *getpwuid(uid_t uid)
|
||||
static passwd_t pwd;
|
||||
static char buffer[BUFSIZ];
|
||||
passwd_t *result;
|
||||
if (!getpwuid_r(uid, &pwd, buffer, BUFSIZ, &result))
|
||||
if (!getpwuid_r(uid, &pwd, buffer, BUFSIZ, &result)) {
|
||||
return NULL;
|
||||
}
|
||||
return &pwd;
|
||||
}
|
||||
|
||||
int getpwnam_r(const char *name, passwd_t *pwd, char *buf, size_t buflen, passwd_t **result)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NULL) {
|
||||
return 0;
|
||||
}
|
||||
int fd = open("/etc/passwd", O_RDONLY, 0);
|
||||
if (fd == -1) {
|
||||
pr_debug("Cannot open `/etc/passwd`\n");
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/// @file readline.c
|
||||
/// @author Enrico Fraccaroli (enry.frak@gmail.com)
|
||||
/// @brief
|
||||
/// @version 0.1
|
||||
/// @date 2023-08-30
|
||||
///
|
||||
/// @copyright Copyright (c) 2023
|
||||
///
|
||||
|
||||
#include "readline.h"
|
||||
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys/unistd.h"
|
||||
|
||||
int readline(int fd, char *buffer, size_t buflen, ssize_t *read_len)
|
||||
{
|
||||
ssize_t length, rollback, num_read;
|
||||
memset(buffer, 0, buflen);
|
||||
unsigned char found_newline = 1;
|
||||
// Read from the file.
|
||||
num_read = read(fd, buffer, buflen);
|
||||
if (num_read == 0) {
|
||||
return 0;
|
||||
}
|
||||
// Search for termination character.
|
||||
char *newline = strchr(buffer, '\n');
|
||||
if (newline == NULL) {
|
||||
found_newline = 0;
|
||||
newline = strchr(buffer, EOF);
|
||||
if (newline == NULL) {
|
||||
newline = strchr(buffer, 0);
|
||||
if (newline == NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Compute the length of the string.
|
||||
length = (newline - buffer);
|
||||
if (length <= 0) {
|
||||
return 0;
|
||||
}
|
||||
// Close the string.
|
||||
buffer[length] = 0;
|
||||
// Compute how much we need to rollback.
|
||||
rollback = length - num_read + 1;
|
||||
if (rollback > 1) {
|
||||
return 0;
|
||||
}
|
||||
// Rollback the reading position in the file.
|
||||
lseek(fd, rollback, SEEK_CUR);
|
||||
// Set how much we were able to read from the file.
|
||||
if (read_len) {
|
||||
*read_len = length;
|
||||
}
|
||||
return (found_newline) ? 1 : -1;
|
||||
}
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
/// @file sched.c
|
||||
/// @brief Function for managing scheduler.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "system/syscall_types.h"
|
||||
#include "sys/errno.h"
|
||||
#include "sched.h"
|
||||
#include "sys/errno.h"
|
||||
|
||||
_syscall2(int, sched_setparam, pid_t, pid, const sched_param_t *, param)
|
||||
|
||||
|
||||
+16
-10
@@ -1,16 +1,18 @@
|
||||
/// @file setenv.c
|
||||
/// @brief Defines the functions used to manipulate the environmental variables.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include <assert.h>
|
||||
#include "sys/errno.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include <assert.h>
|
||||
|
||||
char **environ;
|
||||
|
||||
static char **__environ = NULL;
|
||||
/// @brief Global environ list.
|
||||
static char **__environ = NULL;
|
||||
/// @brief Size of the global environ list.
|
||||
static size_t __environ_size = 0;
|
||||
|
||||
/// @brief Finds the entry in the environ.
|
||||
@@ -21,15 +23,17 @@ static inline int __find_entry(const char *name, const size_t name_len)
|
||||
{
|
||||
if (environ) {
|
||||
int index = 0;
|
||||
for (char **ptr = environ; *ptr; ++ptr, ++index)
|
||||
if (!strncmp((*ptr), name, name_len) && (*ptr)[name_len] == '=')
|
||||
for (char **ptr = environ; *ptr; ++ptr, ++index) {
|
||||
if (!strncmp((*ptr), name, name_len) && (*ptr)[name_len] == '=') {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// @brief Makes a clone of the current environ.
|
||||
static void __clone_environ()
|
||||
static void __clone_environ(void)
|
||||
{
|
||||
if (environ) {
|
||||
// Count the number of variables.
|
||||
@@ -96,8 +100,9 @@ int setenv(const char *name, const char *value, int replace)
|
||||
environ = __environ = new_environ;
|
||||
}
|
||||
// Free the previous entry.
|
||||
if (environ[index])
|
||||
if (environ[index]) {
|
||||
free(environ[index]);
|
||||
}
|
||||
// Allocate the new entry.
|
||||
environ[index] = malloc(total_len);
|
||||
// Memcopy because we do not want the null terminating character.
|
||||
@@ -127,8 +132,9 @@ int unsetenv(const char *name)
|
||||
if (!strncmp(*ep, name, len) && (*ep)[len] == '=') {
|
||||
/* Found it. Remove this pointer by moving later ones back. */
|
||||
char **dp = ep;
|
||||
do dp[0] = dp[1];
|
||||
while (*dp++);
|
||||
do {
|
||||
dp[0] = dp[1];
|
||||
} while (*dp++);
|
||||
/* Continue the loop in case NAME appears again. */
|
||||
} else {
|
||||
++ep;
|
||||
|
||||
+73
-49
@@ -1,13 +1,14 @@
|
||||
/// @file stdio.c
|
||||
/// @brief Standard I/0 functions.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include <sys/errno.h>
|
||||
#include "stdio.h"
|
||||
#include "sys/errno.h"
|
||||
#include "ctype.h"
|
||||
#include "string.h"
|
||||
#include "stdbool.h"
|
||||
#include "stdio.h"
|
||||
#include "strerror.h"
|
||||
#include "string.h"
|
||||
#include "sys/unistd.h"
|
||||
|
||||
void putchar(int character)
|
||||
@@ -15,7 +16,7 @@ void putchar(int character)
|
||||
write(STDOUT_FILENO, &character, 1);
|
||||
}
|
||||
|
||||
void puts(char *str)
|
||||
void puts(const char *str)
|
||||
{
|
||||
write(STDOUT_FILENO, str, strlen(str));
|
||||
}
|
||||
@@ -23,17 +24,18 @@ void puts(char *str)
|
||||
int getchar(void)
|
||||
{
|
||||
char c;
|
||||
while (read(STDIN_FILENO, &c, 1) == 0)
|
||||
while (read(STDIN_FILENO, &c, 1) == 0) {
|
||||
continue;
|
||||
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
char *gets(char *str)
|
||||
{
|
||||
// Check the input string.
|
||||
if (str == NULL)
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// Buffer for reading input.
|
||||
char buffer[GETS_BUFFERSIZE];
|
||||
memset(buffer, '\0', GETS_BUFFERSIZE);
|
||||
@@ -60,7 +62,7 @@ char *gets(char *str)
|
||||
}
|
||||
} else {
|
||||
// The character is stored at address, and the pointer is incremented.
|
||||
*cptr++ = ch;
|
||||
*cptr++ = (char)ch;
|
||||
}
|
||||
}
|
||||
// Add the null-terminating character.
|
||||
@@ -74,13 +76,15 @@ char *gets(char *str)
|
||||
int atoi(const char *str)
|
||||
{
|
||||
// Check the input string.
|
||||
if (str == NULL)
|
||||
if (str == NULL) {
|
||||
return 0;
|
||||
}
|
||||
// Initialize sign, the result variable, and two indices.
|
||||
int sign = (str[0] == '-') ? -1 : +1, result = 0, i;
|
||||
// Find where the number ends.
|
||||
for (i = (sign == -1) ? 1 : 0; (str[i] != '\0') && isdigit(str[i]); ++i)
|
||||
for (i = (sign == -1) ? 1 : 0; (str[i] != '\0') && isdigit(str[i]); ++i) {
|
||||
result = (result * 10) + str[i] - '0';
|
||||
}
|
||||
return sign * result;
|
||||
}
|
||||
|
||||
@@ -90,48 +94,46 @@ long strtol(const char *str, char **endptr, int base)
|
||||
long acc, cutoff;
|
||||
int c;
|
||||
int neg, any, cutlim;
|
||||
/*
|
||||
* Skip white space and pick up leading +/- sign if any.
|
||||
* If base is 0, allow 0x for hex and 0 for octal, else
|
||||
* assume decimal; if base is already 16, allow 0x.
|
||||
*/
|
||||
// Skip white space and pick up leading +/- sign if any.
|
||||
// If base is 0, allow 0x for hex and 0 for octal, else
|
||||
// assume decimal; if base is already 16, allow 0x.
|
||||
s = str;
|
||||
do {
|
||||
c = (unsigned char)*s++;
|
||||
} while (isspace(c));
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
c = (int)*s++;
|
||||
} else {
|
||||
neg = 0;
|
||||
if (c == '+')
|
||||
c = *s++;
|
||||
if (c == '+') {
|
||||
c = (int)*s++;
|
||||
}
|
||||
}
|
||||
if ((base == 0 || base == 16) &&
|
||||
c == '0' && (*s == 'x' || *s == 'X')) {
|
||||
c = s[1];
|
||||
c = (int)s[1];
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
if (base == 0)
|
||||
if (base == 0) {
|
||||
base = c == '0' ? 8 : 10;
|
||||
/*
|
||||
* Compute the cutoff value between legal numbers and illegal
|
||||
* numbers. That is the largest legal value, divided by the
|
||||
* base. An input number that is greater than this value, if
|
||||
* followed by a legal input character, is too big. One that
|
||||
* is equal to this value may be valid or not; the limit
|
||||
* between valid and invalid numbers is then based on the last
|
||||
* digit. For instance, if the range for longs is
|
||||
* [-2147483648..2147483647] and the input base is 10,
|
||||
* cutoff will be set to 214748364 and cutlim to either
|
||||
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
|
||||
* a value > 214748364, or equal but the next digit is > 7 (or 8),
|
||||
* the number is too big, and we will return a range error.
|
||||
*
|
||||
* Set any if any `digits' consumed; make it negative to indicate
|
||||
* overflow.
|
||||
*/
|
||||
}
|
||||
// Compute the cutoff value between legal numbers and illegal
|
||||
// numbers. That is the largest legal value, divided by the
|
||||
// base. An input number that is greater than this value, if
|
||||
// followed by a legal input character, is too big. One that
|
||||
// is equal to this value may be valid or not; the limit
|
||||
// between valid and invalid numbers is then based on the last
|
||||
// digit. For instance, if the range for longs is
|
||||
// [-2147483648..2147483647] and the input base is 10,
|
||||
// cutoff will be set to 214748364 and cutlim to either
|
||||
// 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
|
||||
// a value > 214748364, or equal but the next digit is > 7 (or 8),
|
||||
// the number is too big, and we will return a range error.
|
||||
//
|
||||
// Set any if any `digits' consumed; make it negative to indicate
|
||||
// overflow.
|
||||
cutoff = neg ? LONG_MIN : LONG_MAX;
|
||||
cutlim = cutoff % base;
|
||||
cutoff /= base;
|
||||
@@ -143,16 +145,19 @@ long strtol(const char *str, char **endptr, int base)
|
||||
cutlim = -cutlim;
|
||||
}
|
||||
for (acc = 0, any = 0;; c = (unsigned char)*s++) {
|
||||
if (isdigit(c))
|
||||
if (isdigit(c)) {
|
||||
c -= '0';
|
||||
else if (isalpha(c))
|
||||
} else if (isalpha(c)) {
|
||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
if (c >= base)
|
||||
}
|
||||
if (c >= base) {
|
||||
break;
|
||||
if (any < 0)
|
||||
}
|
||||
if (any < 0) {
|
||||
continue;
|
||||
}
|
||||
if (neg) {
|
||||
if (acc < cutoff || (acc == cutoff && c > cutlim)) {
|
||||
any = -1;
|
||||
@@ -175,16 +180,18 @@ long strtol(const char *str, char **endptr, int base)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (endptr != 0)
|
||||
if (endptr != 0) {
|
||||
*endptr = (char *)(any ? s - 1 : str);
|
||||
}
|
||||
return (acc);
|
||||
}
|
||||
|
||||
int fgetc(int fd)
|
||||
{
|
||||
unsigned char c;
|
||||
if (read(fd, &c, 1) <= 0)
|
||||
if (read(fd, &c, 1) <= 0) {
|
||||
return EOF;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -195,14 +202,31 @@ char *fgets(char *buf, int n, int fd)
|
||||
|
||||
/* get max bytes or upto a newline */
|
||||
for (p = buf, n--; n > 0; n--) {
|
||||
if ((c = fgetc(fd)) == EOF)
|
||||
// Get the character.
|
||||
c = fgetc(fd);
|
||||
if (c == EOF) {
|
||||
break;
|
||||
*p++ = c;
|
||||
if (c == '\n')
|
||||
}
|
||||
*p++ = (char)c;
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*p = 0;
|
||||
if (p == buf || c == EOF)
|
||||
if (p == buf || c == EOF) {
|
||||
return NULL;
|
||||
}
|
||||
return (p);
|
||||
}
|
||||
|
||||
void perror(const char *s)
|
||||
{
|
||||
if (s) {
|
||||
puts(s);
|
||||
putchar(':');
|
||||
putchar(' ');
|
||||
}
|
||||
puts(strerror(errno));
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
+56
-32
@@ -1,39 +1,37 @@
|
||||
/// @file stdlib.c
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "system/syscall_types.h"
|
||||
#include "stddef.h"
|
||||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "assert.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
/// @brief Number which identifies a memory area allocated through a call to
|
||||
/// malloc(), calloc() or realloc().
|
||||
#define MALLOC_MAGIC_NUMBER 0x600DC0DE
|
||||
|
||||
/// @brief Checks if the pointer is a valid malloc entry.
|
||||
/// @param ptr the pointer we are checking.
|
||||
/// @return 1 of success, 0 on failure.
|
||||
static inline int __malloc_is_valid_ptr(void *ptr)
|
||||
{
|
||||
return (ptr && (((size_t *)ptr)[-1] == MALLOC_MAGIC_NUMBER));
|
||||
}
|
||||
|
||||
size_t malloc_usable_size(void *ptr)
|
||||
{
|
||||
if (__malloc_is_valid_ptr(ptr))
|
||||
return ((size_t *)ptr)[-2];
|
||||
return 0;
|
||||
}
|
||||
typedef struct {
|
||||
unsigned magic;
|
||||
size_t size;
|
||||
} malloc_header_t;
|
||||
|
||||
void *malloc(unsigned int size)
|
||||
{
|
||||
size_t *_res, _size = 2 * sizeof(size_t) + size;
|
||||
__inline_syscall1(_res, brk, _size);
|
||||
_res[0] = size;
|
||||
_res[1] = MALLOC_MAGIC_NUMBER;
|
||||
return &_res[2];
|
||||
assert(size && "Zero size requested.");
|
||||
size_t *ptr;
|
||||
// Compute the real size we need to allocate.
|
||||
size_t real_size = size + sizeof(malloc_header_t);
|
||||
// Allocate the memory.
|
||||
__inline_syscall1(ptr, brk, real_size);
|
||||
// Initialize the malloc header.
|
||||
malloc_header_t *malloc_header = (malloc_header_t *)ptr;
|
||||
malloc_header->magic = MALLOC_MAGIC_NUMBER;
|
||||
malloc_header->size = size;
|
||||
// Return the allocated memory.
|
||||
return (void *)((char *)ptr + sizeof(malloc_header_t));
|
||||
}
|
||||
|
||||
void *calloc(size_t num, size_t size)
|
||||
@@ -58,8 +56,12 @@ void *realloc(void *ptr, size_t size)
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
// Get the malloc header.
|
||||
malloc_header_t *malloc_header = (malloc_header_t *)((char *)ptr - sizeof(malloc_header_t));
|
||||
// Check the header.
|
||||
assert(malloc_header->magic == MALLOC_MAGIC_NUMBER && "This is not a valid pointer.");
|
||||
// Get the old size.
|
||||
size_t old_size = malloc_usable_size(ptr);
|
||||
size_t old_size = malloc_header->size;
|
||||
// Create the new pointer.
|
||||
void *newp = malloc(size);
|
||||
memset(newp, 0, size);
|
||||
@@ -70,24 +72,46 @@ void *realloc(void *ptr, size_t size)
|
||||
|
||||
void free(void *ptr)
|
||||
{
|
||||
// Get the malloc header.
|
||||
malloc_header_t *malloc_header = (malloc_header_t *)((char *)ptr - sizeof(malloc_header_t));
|
||||
// Check the header.
|
||||
assert(malloc_header->magic == MALLOC_MAGIC_NUMBER && "This is not a valid pointer.");
|
||||
// Get the real pointer.
|
||||
ptr = (char *)ptr - sizeof(malloc_header_t);
|
||||
// Call the free.
|
||||
int _res;
|
||||
if (__malloc_is_valid_ptr(ptr)) {
|
||||
size_t *_ptr = (size_t *)ptr - 2;
|
||||
__inline_syscall1(_res, brk, _ptr);
|
||||
} else {
|
||||
__inline_syscall1(_res, brk, ptr);
|
||||
}
|
||||
__inline_syscall1(_res, brk, ptr);
|
||||
}
|
||||
|
||||
/// Seed used to generate random numbers.
|
||||
static int rseed = 0;
|
||||
static unsigned rseed = 0;
|
||||
|
||||
void srand(int x)
|
||||
void srand(unsigned x)
|
||||
{
|
||||
rseed = x;
|
||||
}
|
||||
|
||||
int rand()
|
||||
unsigned rand(void)
|
||||
{
|
||||
return rseed = (rseed * 1103515245U + 12345U) & RAND_MAX;
|
||||
}
|
||||
|
||||
float randf(void)
|
||||
{
|
||||
return ((float)rand() / (float)(RAND_MAX));
|
||||
}
|
||||
|
||||
int randint(int lb, int ub)
|
||||
{
|
||||
return lb + ((int)rand() % (ub - lb + 1));
|
||||
}
|
||||
|
||||
unsigned randuint(unsigned lb, unsigned ub)
|
||||
{
|
||||
return lb + (rand() % (ub - lb + 1));
|
||||
}
|
||||
|
||||
float randfloat(float lb, float ub)
|
||||
{
|
||||
return lb + (randf() * (ub - lb));
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/// @file strerror.c
|
||||
/// @brief
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "strerror.h"
|
||||
@@ -76,7 +76,7 @@ char *strerror(int errnum)
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
case EAGAIN:
|
||||
strcpy(error, "No more processes");
|
||||
strcpy(error, "Resource temporarily unavailable");
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOMEM
|
||||
|
||||
+136
-100
@@ -1,33 +1,44 @@
|
||||
/// @file string.c
|
||||
/// @brief String routines.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include <fcntl.h>
|
||||
#include "string.h"
|
||||
#include "ctype.h"
|
||||
#include "fcntl.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include "mem/kheap.h"
|
||||
#endif
|
||||
|
||||
char *strncpy(char *destination, const char *source, size_t num)
|
||||
{
|
||||
char *start = destination;
|
||||
while (num && (*destination++ = *source++)) {
|
||||
num--;
|
||||
}
|
||||
// Check if we have a valid number.
|
||||
if (num) {
|
||||
while (--num) {
|
||||
*destination++ = '\0';
|
||||
// Copies the first num characters of source to destination.
|
||||
while (num && (*destination++ = *source++)) {
|
||||
num--;
|
||||
}
|
||||
// If the end of the source C string (which is signaled by a null-character)
|
||||
// is found before num characters have been copied, destination is padded
|
||||
// with zeros until a total of num characters have been written to it.
|
||||
if (num) {
|
||||
while (--num) {
|
||||
*destination++ = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return start;
|
||||
// Pointer to destination is returned.
|
||||
return destination;
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return 0;
|
||||
}
|
||||
while ((--n > 0) && (*s1) && (*s2) && (*s1 == *s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
@@ -66,8 +77,9 @@ char *strchr(const char *s, int ch)
|
||||
while (*s && *s != (char)ch) {
|
||||
s++;
|
||||
}
|
||||
if (*s == (char)ch)
|
||||
if (*s == (char)ch) {
|
||||
return (char *)s;
|
||||
}
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -155,8 +167,9 @@ size_t strcspn(const char *string, const char *control)
|
||||
size_t n;
|
||||
|
||||
// Clear out bit map.
|
||||
for (n = 0; n < 32; n++)
|
||||
for (n = 0; n < 32; n++) {
|
||||
map[n] = 0;
|
||||
}
|
||||
|
||||
// Set bits in control map.
|
||||
while (*ctrl) {
|
||||
@@ -184,8 +197,9 @@ char *strpbrk(const char *string, const char *control)
|
||||
int n;
|
||||
|
||||
// Clear out bit map.
|
||||
for (n = 0; n < 32; n++)
|
||||
for (n = 0; n < 32; n++) {
|
||||
map[n] = 0;
|
||||
}
|
||||
|
||||
// Set bits in control map.
|
||||
while (*ctrl) {
|
||||
@@ -204,6 +218,34 @@ char *strpbrk(const char *string, const char *control)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int tokenize(const char *string, char *separators, size_t *offset, char *buffer, ssize_t buflen)
|
||||
{
|
||||
// If we reached the end of the parsed string, stop.
|
||||
if (string[*offset] == 0) {
|
||||
return 0;
|
||||
}
|
||||
// Keep copying character until we either reach 1) the end of the buffer, 2) a
|
||||
// separator, or 3) the end of the string we are parsing.
|
||||
do {
|
||||
for (char *separator = separators; *separator != 0; ++separator) {
|
||||
if (string[*offset] == *separator) {
|
||||
// Skip the character.
|
||||
++(*offset);
|
||||
// Close the buffer.
|
||||
*buffer = '\0';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// Save the character.
|
||||
*buffer = string[*offset];
|
||||
// Advance the offset, decrese the available size in the buffer, and advance the buffer.
|
||||
++(*offset), --buflen, ++buffer;
|
||||
} while ((buflen > 0) && (string[*offset] != 0));
|
||||
// Close the buffer.
|
||||
*buffer = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *memmove(void *dst, const void *src, size_t n)
|
||||
{
|
||||
void *ret = dst;
|
||||
@@ -266,17 +308,30 @@ char *strupr(char *s)
|
||||
return s;
|
||||
}
|
||||
|
||||
char *strcat(char *dst, const char *src)
|
||||
{
|
||||
char *cp = dst;
|
||||
|
||||
while (*cp) {
|
||||
cp++;
|
||||
}
|
||||
|
||||
while ((*cp++ = *src++) != '\0') {}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
char *strncat(char *s1, const char *s2, size_t n)
|
||||
{
|
||||
char *start = s1;
|
||||
|
||||
while (*s1++) {}
|
||||
|
||||
s1--;
|
||||
|
||||
while (n--) {
|
||||
if (!(*s1++ = *s2++))
|
||||
if (!(*s1++ = *s2++)) {
|
||||
return start;
|
||||
}
|
||||
}
|
||||
|
||||
*s1 = '\0';
|
||||
@@ -284,15 +339,6 @@ char *strncat(char *s1, const char *s2, size_t n)
|
||||
return start;
|
||||
}
|
||||
|
||||
char *strnset(char *s, int c, size_t n)
|
||||
{
|
||||
while (n-- && *s) {
|
||||
*s++ = (char)c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
char *strrev(char *s)
|
||||
{
|
||||
char *start = s;
|
||||
@@ -364,11 +410,10 @@ char *strtok_r(char *str, const char *delim, char **saveptr)
|
||||
*saveptr = s;
|
||||
|
||||
// Determine if a token has been found.
|
||||
if (str == (char *)s) {
|
||||
if (str == s) {
|
||||
return NULL;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
// Intrinsic functions.
|
||||
@@ -386,119 +431,100 @@ char *strtok_r(char *str, const char *delim, char **saveptr)
|
||||
|
||||
void *memset(void *ptr, int value, size_t num)
|
||||
{
|
||||
// Truncate c to 8 bits.
|
||||
value = (value & 0xFF);
|
||||
|
||||
char *dst = (char *)ptr;
|
||||
|
||||
// Initialize the rest of the size.
|
||||
while (num--) {
|
||||
*dst++ = (char)value;
|
||||
}
|
||||
|
||||
// Turn the pointer into a char * pointer. Here, we use the volatile keyword
|
||||
// to prevent the compiler from optimizing away the operations involving the
|
||||
// pointer.
|
||||
unsigned char volatile *dst = (unsigned char volatile *)ptr;
|
||||
// Initialize the content of the memory.
|
||||
while (num--) *dst++ = (unsigned char)value;
|
||||
// Return the pointer.
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int memcmp(const void *ptr1, const void *ptr2, size_t n)
|
||||
int memcmp(const void *dst, const void *src, size_t n)
|
||||
{
|
||||
if (!n) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (--n && *(char *)ptr1 == *(char *)ptr2) {
|
||||
ptr1 = (char *)ptr1 + 1;
|
||||
ptr2 = (char *)ptr2 + 1;
|
||||
while (--n && *(char *)dst == *(char *)src) {
|
||||
dst = (char *)dst + 1;
|
||||
src = (char *)src + 1;
|
||||
}
|
||||
|
||||
return *((unsigned char *)ptr1) - *((unsigned char *)ptr2);
|
||||
return *((unsigned char *)dst) - *((unsigned char *)src);
|
||||
}
|
||||
|
||||
void *memcpy(void *ptr1, const void *ptr2, size_t num)
|
||||
void *memcpy(void *dst, const void *src, size_t num)
|
||||
{
|
||||
char *_dst = ptr1;
|
||||
const char *_src = ptr2;
|
||||
|
||||
while (num--) {
|
||||
*_dst++ = *_src++;
|
||||
}
|
||||
|
||||
return ptr1;
|
||||
// Turn the pointer into a char * pointer. Here, we use the volatile keyword
|
||||
// to prevent the compiler from optimizing away the operations involving the
|
||||
// pointer.
|
||||
unsigned char volatile *_dst = (unsigned char volatile *)dst;
|
||||
const unsigned char volatile *_src = (const unsigned char volatile *)src;
|
||||
// Initialize the content of the memory.
|
||||
while (num--) *_dst++ = *_src++;
|
||||
// Return the pointer.
|
||||
return (void *)dst;
|
||||
}
|
||||
|
||||
void *memccpy(void *ptr1, const void *ptr2, int c, size_t n)
|
||||
void *memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
while (n && (*((char *)(ptr1 = (char *)ptr1 + 1) - 1) =
|
||||
*((char *)(ptr2 = (char *)ptr2 + 1) - 1)) != (char)c) {
|
||||
while (n && (*((char *)(dst = (char *)dst + 1) - 1) =
|
||||
*((char *)(src = (char *)src + 1) - 1)) != (char)c) {
|
||||
n--;
|
||||
}
|
||||
|
||||
return n ? ptr1 : NULL;
|
||||
return n ? dst : NULL;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src)
|
||||
{
|
||||
char *save = dst;
|
||||
|
||||
while ((*dst++ = *src++) != '\0') {}
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
const char *eos;
|
||||
|
||||
for (eos = s; *eos != 0; ++eos) {}
|
||||
|
||||
long len = eos - s;
|
||||
|
||||
return (len < 0) ? 0 : (size_t)len;
|
||||
const char *it = s;
|
||||
while (*(++it) != 0) {}
|
||||
return ((it - s) < 0) ? 0 : (size_t)(it - s);
|
||||
}
|
||||
|
||||
size_t strnlen(const char *s, size_t count)
|
||||
{
|
||||
const char *sc;
|
||||
|
||||
for (sc = s; *sc != '\0' && count--; ++sc) {}
|
||||
|
||||
long len = sc - s;
|
||||
|
||||
return (len < 0) ? 0 : (size_t)len;
|
||||
const char *it = s;
|
||||
while ((*(++it) != 0) && --count) {}
|
||||
return ((it - s) < 0) ? 0 : (size_t)(it - s);
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int ret = 0;
|
||||
const char *s1t = s1, *s2t = s2;
|
||||
|
||||
for (; !(ret = *s1t - *s2t) && *s2t; ++s1t, ++s2t) {}
|
||||
|
||||
return (ret < 0) ? -1 : (ret > 0) ? 1 :
|
||||
0;
|
||||
}
|
||||
|
||||
char *strcat(char *dst, const char *src)
|
||||
{
|
||||
char *cp = dst;
|
||||
|
||||
while (*cp) {
|
||||
cp++;
|
||||
while (*s1 && *s2) {
|
||||
if (*s1 < *s2) break;
|
||||
if (*s1 > *s2) break;
|
||||
s1++, s2++;
|
||||
}
|
||||
|
||||
while ((*cp++ = *src++) != '\0') {}
|
||||
|
||||
return dst;
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
||||
char *strset(char *s, int c)
|
||||
{
|
||||
char *start = s;
|
||||
|
||||
while (*s) {
|
||||
*s++ = (char)c;
|
||||
char *it = s;
|
||||
while (*it) {
|
||||
*it++ = (char)c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
return start;
|
||||
char *strnset(char *s, int c, size_t n)
|
||||
{
|
||||
char *it = s;
|
||||
while (*it && n--) {
|
||||
*it++ = (char)c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
char *strtok(char *str, const char *delim)
|
||||
@@ -593,9 +619,14 @@ char *trim(char *str)
|
||||
char *strdup(const char *s)
|
||||
{
|
||||
size_t len = strlen(s) + 1;
|
||||
char *new = malloc(len);
|
||||
if (new == NULL)
|
||||
#ifdef __KERNEL__
|
||||
char *new = kmalloc(len);
|
||||
#else
|
||||
char *new = malloc(len);
|
||||
#endif
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new[len] = '\0';
|
||||
return (char *)memcpy(new, s, len);
|
||||
}
|
||||
@@ -603,9 +634,14 @@ char *strdup(const char *s)
|
||||
char *strndup(const char *s, size_t n)
|
||||
{
|
||||
size_t len = strnlen(s, n);
|
||||
char *new = malloc(len);
|
||||
if (new == NULL)
|
||||
#ifdef __KERNEL__
|
||||
char *new = kmalloc(len);
|
||||
#else
|
||||
char *new = malloc(len);
|
||||
#endif
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new[len] = '\0';
|
||||
return (char *)memcpy(new, s, len);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/// @file errno.c
|
||||
/// @brief Stores the error number.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/errno.h"
|
||||
|
||||
/// @brief Returns the error number for the current process.
|
||||
/// @return Pointer to the error number.
|
||||
int *__geterrno()
|
||||
int *__geterrno(void)
|
||||
{
|
||||
static int _errno = 0;
|
||||
return &_errno;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// @file ioctl.c
|
||||
/// @brief Input/Output ConTroL (IOCTL) functions implementation.
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "sys/ioctl.h"
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/// @file ipc.c
|
||||
/// @brief Inter-Process Communication (IPC) system call implementation.
|
||||
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#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/stat.h"
|
||||
#include "sys/unistd.h"
|
||||
#include "system/syscall_types.h"
|
||||
|
||||
_syscall3(void *, shmat, int, shmid, const void *, shmaddr, int, shmflg)
|
||||
|
||||
_syscall3(long, shmget, key_t, key, size_t, size, int, flag)
|
||||
|
||||
_syscall1(long, shmdt, const void *, shmaddr)
|
||||
|
||||
_syscall3(long, shmctl, int, shmid, int, cmd, struct shmid_ds *, buf)
|
||||
|
||||
_syscall3(long, semget, key_t, key, int, nsems, int, semflg)
|
||||
|
||||
_syscall4(long, semctl, int, semid, int, semnum, int, cmd, union semun *, arg)
|
||||
|
||||
_syscall2(int, msgget, key_t, key, int, msgflg)
|
||||
|
||||
_syscall3(int, msgctl, int, msqid, int, cmd, struct msqid_ds *, buf)
|
||||
|
||||
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
|
||||
{
|
||||
long __res;
|
||||
do {
|
||||
__inline_syscall4(__res, msgsnd, msqid, msgp, msgsz, msgflg);
|
||||
if (!(msgflg & IPC_NOWAIT) && (__res == -EAGAIN)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while (1);
|
||||
__syscall_return(int, __res);
|
||||
}
|
||||
|
||||
ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
|
||||
{
|
||||
long __res;
|
||||
do {
|
||||
__inline_syscall5(__res, msgrcv, msqid, msgp, msgsz, msgtyp, msgflg);
|
||||
if (!(msgflg & IPC_NOWAIT) && ((__res == -EAGAIN) || (__res == -ENOMSG))) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while (1);
|
||||
__syscall_return(int, __res);
|
||||
}
|
||||
|
||||
long semop(int semid, struct sembuf *sops, unsigned nsops)
|
||||
{
|
||||
struct sembuf *op;
|
||||
long __res;
|
||||
|
||||
// The pointer to the operation is NULL.
|
||||
if (!sops) {
|
||||
pr_err("The pointer to the operation is NULL.\n");
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// The value of nsops is negative.
|
||||
if (nsops <= 0) {
|
||||
pr_err("The value of nsops is negative.\n");
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// This should be performed for each sops.
|
||||
for (size_t i = 0; i < nsops; i++) {
|
||||
// Get the operation.
|
||||
op = &sops[i];
|
||||
// The process continues to try to perform the operation until it completes
|
||||
// or receives an error.
|
||||
while (1) {
|
||||
// Calling the kernel-side function.
|
||||
__inline_syscall3(__res, semop, semid, op, 1);
|
||||
|
||||
// If we get an error, the operation has been taken care of we stop
|
||||
// the loop. We also stop the loop if the operation is not allowed
|
||||
// and the IPC_NOWAIT flag is 1
|
||||
if ((__res != -EAGAIN) || (op->sem_flg & IPC_NOWAIT)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the operation couldn't be performed and we had the IPC_NOWAIT set
|
||||
// to 1 then we return.
|
||||
if ((__res == -EAGAIN) && (op->sem_flg & IPC_NOWAIT)) {
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Now, we can return the value.
|
||||
__syscall_return(long, __res);
|
||||
}
|
||||
|
||||
key_t ftok(char *path, int id)
|
||||
{
|
||||
// Create a struct containing the serial number and the device number of the
|
||||
// file we use to generate the key.
|
||||
struct stat_t st;
|
||||
if (stat(path, &st) < 0) {
|
||||
pr_err("Cannot stat the file `%s`...\n", path);
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
// Taking the upper 8 bits from the lower 8 bits of id, the second upper 8
|
||||
// bits from the lower 8 bits of the device number of the provided pathname,
|
||||
// and the lower 16 bits from the lower 16 bits of the inode number of the
|
||||
// provided pathname.
|
||||
return (st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 0xffu) << 24);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user