From dc98bcf0cad8dac6535b0bde31873851df77af00 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 3 Sep 2023 17:23:12 +0200 Subject: [PATCH] Add options to kernelinfo(2). --- kernel/kernel.cpp | 4 ++++ kernel/kernelinfo.cpp | 7 ++++++- kernel/kernelinfo.h | 29 +++++++++++++++++++++++++++++ utils/kernelinfo.1 | 7 ++++++- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 kernel/kernelinfo.h diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 3a95c948..8eaa7d98 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -80,6 +80,7 @@ #include "kb/default-kblayout.h" #include "kb/kblayout.h" #include "kb/ps2.h" +#include "kernelinfo.h" #include "logterminal.h" #include "mouse/ps2.h" #include "multiboot.h" @@ -228,6 +229,9 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo_p) FreeKernelAddress(&alloc); } + if ( !(kernel_options = strdup(cmdline ? cmdline : "")) ) + Panic("Failed to allocate kernel command line"); + int argmax = 1; argv = new char*[argmax + 1]; if ( !argv ) diff --git a/kernel/kernelinfo.cpp b/kernel/kernelinfo.cpp index db964cbc..66bc547e 100644 --- a/kernel/kernelinfo.cpp +++ b/kernel/kernelinfo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, 2022 Jonas 'Sortie' Termansen. + * Copyright (c) 2012, 2015, 2022, 2023 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,17 +24,22 @@ #include #include +#include "kernelinfo.h" + #ifndef VERSIONSTR #define VERSIONSTR "unknown" #endif namespace Sortix { +char* kernel_options; + static const char* KernelInfo(const char* req) { if ( strcmp(req, "name") == 0 ) { return BRAND_KERNEL_NAME; } if ( strcmp(req, "version") == 0 ) { return VERSIONSTR; } if ( strcmp(req, "tagline") == 0 ) { return BRAND_RELEASE_TAGLINE; } + if ( strcmp(req, "options") == 0 ) { return kernel_options; } if ( strcmp(req, "builddate") == 0 ) { return __DATE__; } if ( strcmp(req, "buildtime") == 0 ) { return __TIME__; } #if defined(__i386__) || defined(__x86_64__) diff --git a/kernel/kernelinfo.h b/kernel/kernelinfo.h new file mode 100644 index 00000000..1b49e77a --- /dev/null +++ b/kernel/kernelinfo.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Jonas 'Sortie' Termansen. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * kernelinfo.h + * Lets user-space query information about the kernel. + */ + +#ifndef KERNELINFO_H +#define KERNELINFO_H + +namespace Sortix { + +extern char* kernel_options; + +} // namespace Sortix + +#endif diff --git a/utils/kernelinfo.1 b/utils/kernelinfo.1 index 79c84518..f1fba49a 100644 --- a/utils/kernelinfo.1 +++ b/utils/kernelinfo.1 @@ -21,6 +21,10 @@ The name of the current kernel. The version of the current kernel. .It Sy tagline The tagline (slogan) of the release. +.It Sy options +The +.Xr kernel 7 +options. .It Sy builddate The date on which the current kernel was built. .It Sy buildtime @@ -33,4 +37,5 @@ The firmware of the system (e.g. "bios" or "uefi") will exit 0 on success and non-zero otherwise. .Sh SEE ALSO .Xr uname 1 , -.Xr kernelinfo 2 +.Xr kernelinfo 2 , +.Xr kernel 7