Compare commits

...

3 Commits

Author SHA1 Message Date
04322d9ff7
kernel: Add a customizable configuration file system
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-18 20:18:19 +02:00
b7bdec9ece
kernel: Add a bunch more config definitions and hide debug messages behind them 2023-06-18 20:18:00 +02:00
ec34937f14
tests: Add tests for libluna/CPath.h 2023-06-18 20:15:18 +02:00
14 changed files with 211 additions and 11 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ initrd/bin/**
initrd/tests/**
base/
.fakeroot
kernel/config.cmake

View File

@ -103,6 +103,10 @@ if(MOON_DEBUG)
include(debug.cmake)
endif()
if(EXISTS config.cmake)
include(config.cmake)
endif()
target_link_options(moon PRIVATE -lgcc -Wl,--build-id=none -z max-page-size=0x1000 -mcmodel=kernel)
set_target_properties(moon PROPERTIES CXX_STANDARD 20)

View File

@ -0,0 +1,12 @@
# Copy this file and rename it to 'config.cmake' before making your own changes.
# config.cmake: Configuration file for the kernel.
# Edit/add values to customize kernel compilation flags/defines.
# This file is automatically ignored by git.
# To use an example configuration line, just remove the hashtag '#' at the beginning.
# Example: Adding a compiler definition. This will define PCI_DEBUG in the kernel source.
# target_compile_definitions(moon PRIVATE PCI_DEBUG)
# Example: Adding a compiler flag. This will optimize the kernel aggressively (warning: untested, use at your own discretion).
# target_compile_options(moon PRIVATE -O3)

View File

@ -3,4 +3,9 @@ target_compile_definitions(moon PRIVATE DEBUG_MODE)
target_compile_definitions(moon PRIVATE ELF_DEBUG)
target_compile_definitions(moon PRIVATE MMU_DEBUG)
target_compile_definitions(moon PRIVATE MMAP_DEBUG)
target_compile_definitions(moon PRIVATE EXEC_DEBUG)
target_compile_definitions(moon PRIVATE OPEN_DEBUG)
target_compile_definitions(moon PRIVATE REAP_DEBUG)
target_compile_definitions(moon PRIVATE PCI_DEBUG)
target_compile_definitions(moon PRIVATE DEVICE_REGISTRY_DEBUG)
target_compile_options(moon PRIVATE -fsanitize=undefined)

View File

@ -96,12 +96,16 @@ namespace PCI
// Single-function PCI bus
if ((header_type & 0x80) == 0)
{
#ifdef PCI_DEBUG
kdbgln("PCI bus is single-function");
#endif
scan_bus(0, { callback, match });
}
else
{
#ifdef PCI_DEBUG
kdbgln("PCI bus is multiple-function");
#endif
for (u32 function = 0; function < 8; function++)
{
if (read16({ 0, 0, function }, Field::VendorID) != PCI::INVALID_ID)

View File

@ -16,8 +16,8 @@ namespace GPT
if (memcmp(header.signature, GPT_SIGNATURE, GPT_SIGNATURE_LENGTH)) return false;
kdbgln("gpt: Found GUID partition table on device %s, revision %#.8x, with space for %d partition entries!",
device->device_path().chars(), header.revision, header.num_partitions);
kinfoln("gpt: Found GUID partition table on device %s, revision %#.8x, with space for %d partition entries!",
device->device_path().chars(), header.revision, header.num_partitions);
if (header.revision != GPT_REVISION)
{
@ -55,7 +55,7 @@ namespace GPT
if (!memcmp(entry.type_guid, null_guid, 16)) continue;
kdbgln("gpt: Partition entry #%u is active: start=%lu, end=%lu", i, entry.start_lba, entry.end_lba);
kinfoln("gpt: Partition entry #%u is active: start=%lu, end=%lu", i, entry.start_lba, entry.end_lba);
TRY(MBR::PartitionDevice::create(device, entry.start_lba, entry.end_lba - entry.start_lba,
partition_index++));

View File

@ -232,7 +232,7 @@ namespace VFS
auto parent_path = TRY(parser.dirname());
auto child = TRY(parser.basename());
kdbgln("vfs: Mounting filesystem on target %s", path);
kinfoln("vfs: Mounting filesystem on target %s", path);
auto parent_inode = TRY(resolve_path(parent_path.chars(), auth, working_directory));
@ -255,7 +255,7 @@ namespace VFS
if (child.view() == "/") return err(EBUSY);
kdbgln("vfs: Unmounting filesystem on target %s", path);
kinfoln("vfs: Unmounting filesystem on target %s", path);
auto parent_inode = TRY(resolve_path(parent_path.chars(), auth, working_directory));

View File

@ -51,7 +51,9 @@ namespace DeviceRegistry
const char* name = device->device_path().chars();
#ifdef DEVICE_REGISTRY_DEBUG
kdbgln("DeviceRegistry: registered new device type %u:%u at path /%s in devfs", major, minor, name);
#endif
auto desc = DeviceDescriptor { .device = device, .major = major, .minor = minor, .name = name, .mode = mode };

View File

@ -66,7 +66,9 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
if (!VFS::can_execute(inode, current->auth)) return err(EACCES);
kinfoln("exec: attempting to replace current image with %s", path.chars());
#ifdef EXEC_DEBUG
kdbgln("exec: attempting to replace current image with %s", path.chars());
#endif
auto guard = make_scope_guard([current] { MMU::switch_page_directory(current->directory); });
@ -80,7 +82,9 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
// From now on, nothing should fail.
kinfoln("exec: image load ok, will now replace existing process image");
#ifdef EXEC_DEBUG
kdbgln("exec: image load ok, will now replace existing process image");
#endif
guard.deactivate();
@ -110,6 +114,8 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
memcpy(regs, &current->regs, sizeof(*regs));
kinfoln("exec: thread %lu was replaced with %s", current->id, path.chars());
return 0;
}
@ -151,7 +157,9 @@ Result<u64> sys_fork(Registers* regs, SyscallArgs)
Scheduler::add_thread(thread);
kinfoln("fork: thread %lu forked into child %lu", current->id, thread->id);
#ifdef FORK_DEBUG
kdbgln("fork: thread %lu forked into child %lu", current->id, thread->id);
#endif
return thread->id;
}

View File

@ -74,7 +74,9 @@ Result<u64> sys_openat(Registers*, SyscallArgs args)
int fd = TRY(current->allocate_fd(0));
kinfoln("openat: opening file %s from dirfd %d, flags %d, mode %#o = fd %d", path.chars(), dirfd, flags, mode, fd);
#ifdef OPEN_DEBUG
kdbgln("openat: opening file %s from dirfd %d, flags %d, mode %#o = fd %d", path.chars(), dirfd, flags, mode, fd);
#endif
inode->add_handle();

View File

@ -73,7 +73,9 @@ namespace ELFLoader
return err(ENOEXEC);
}
kinfoln("ELF: Loading ELF with entry=%#.16lx", elf_header.e_entry);
#ifdef ELF_DEBUG
kdbgln("ELF: Loading ELF with entry=%#.16lx", elf_header.e_entry);
#endif
usize i;
Elf64_Phdr program_header;

View File

@ -171,7 +171,9 @@ namespace Scheduler
{
CPU::disable_interrupts();
kinfoln("reap: reaping thread with id %zu", thread->id);
#ifdef REAP_DEBUG
kdbgln("reap: reaping thread with id %zu", thread->id);
#endif
if (thread->is_kernel)
{

View File

@ -18,6 +18,7 @@ luna_test(libluna/TestBase64.cpp TestBase64)
luna_test(libluna/TestUtf8.cpp TestUtf8)
luna_test(libluna/TestFormat.cpp TestFormat)
luna_test(libluna/TestHashTable.cpp TestHashTable)
luna_test(libluna/TestCPath.cpp TestCPath)
luna_app(run-tests.cpp run-tests)
endif()

157
tests/libluna/TestCPath.cpp Normal file
View File

@ -0,0 +1,157 @@
#include <luna/CPath.h>
#include <string.h>
#include <test.h>
// Test cases taken from the basename(3) manpage on my Arch Linux system (which are taken from SUSv2).
TestResult test_dirname_usr_lib()
{
char path[] = "/usr/lib";
char* dir = dirname(path);
validate(!strcmp(dir, "/usr"));
test_success;
}
TestResult test_basename_usr_lib()
{
char path[] = "/usr/lib";
char* name = basename(path);
validate(!strcmp(name, "lib"));
test_success;
}
TestResult test_dirname_absolute_usr()
{
char path[] = "/usr/";
char* dir = dirname(path);
validate(!strcmp(dir, "/"));
test_success;
}
TestResult test_basename_absolute_usr()
{
char path[] = "/usr/";
char* name = basename(path);
validate(!strcmp(name, "usr"));
test_success;
}
TestResult test_dirname_relative_usr()
{
char path[] = "usr";
char* dir = dirname(path);
validate(!strcmp(dir, "."));
test_success;
}
TestResult test_basename_relative_usr()
{
char path[] = "usr";
char* name = basename(path);
validate(!strcmp(name, "usr"));
test_success;
}
TestResult test_dirname_root()
{
char path[] = "/";
char* dir = dirname(path);
validate(!strcmp(dir, "/"));
test_success;
}
TestResult test_basename_root()
{
char path[] = "/";
char* name = basename(path);
validate(!strcmp(name, "/"));
test_success;
}
TestResult test_dirname_self()
{
char path[] = ".";
char* dir = dirname(path);
validate(!strcmp(dir, "."));
test_success;
}
TestResult test_basename_self()
{
char path[] = ".";
char* name = basename(path);
validate(!strcmp(name, "."));
test_success;
}
TestResult test_dirname_parent()
{
char path[] = "..";
char* dir = dirname(path);
validate(!strcmp(dir, "."));
test_success;
}
TestResult test_basename_parent()
{
char path[] = "..";
char* name = basename(path);
validate(!strcmp(name, ".."));
test_success;
}
Result<void> test_main()
{
test_prelude;
run_test(test_basename_usr_lib);
run_test(test_basename_absolute_usr);
run_test(test_basename_relative_usr);
run_test(test_basename_root);
run_test(test_basename_self);
run_test(test_basename_parent);
run_test(test_dirname_usr_lib);
run_test(test_dirname_absolute_usr);
run_test(test_dirname_relative_usr);
run_test(test_dirname_root);
run_test(test_dirname_self);
run_test(test_dirname_parent);
return {};
}