A structure, system_config, which is dynamically defined by the definitions/sysconf.yaml config, is now mapped into every user address space. The kernel fills this with information about itself and the running machine. User programs access this through the new j6_sysconf fake syscall in libj6. See: Github bug #242 See: [frobozz blog post](https://jsix.dev/posts/frobozz/) Tags:
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#include <string.h>
|
|
|
|
#include "assert.h"
|
|
#include "cpu.h"
|
|
#include "frame_allocator.h"
|
|
#include "memory.h"
|
|
#include "sysconf.h"
|
|
|
|
struct kheader
|
|
{
|
|
uint64_t magic;
|
|
uint16_t header_len;
|
|
uint16_t header_version;
|
|
|
|
uint16_t version_major;
|
|
uint16_t version_minor;
|
|
uint16_t version_patch;
|
|
uint16_t _reserved;
|
|
uint32_t version_gitsha;
|
|
|
|
uint64_t flags;
|
|
};
|
|
|
|
extern kheader _kernel_header;
|
|
|
|
system_config *g_sysconf = nullptr;
|
|
uintptr_t g_sysconf_phys = 0;
|
|
|
|
constexpr size_t sysconf_pages = mem::bytes_to_pages(sizeof(system_config));
|
|
|
|
void
|
|
sysconf_create()
|
|
{
|
|
auto &fa = frame_allocator::get();
|
|
|
|
size_t count = fa.allocate(sysconf_pages, &g_sysconf_phys);
|
|
|
|
kassert(count == sysconf_pages,
|
|
"Could not get enough contiguous pages for sysconf");
|
|
|
|
g_sysconf = mem::to_virtual<system_config>(g_sysconf_phys);
|
|
memset(g_sysconf, 0, sysconf_pages * mem::frame_size);
|
|
|
|
g_sysconf->kernel_version_major = _kernel_header.version_major;
|
|
g_sysconf->kernel_version_minor = _kernel_header.version_minor;
|
|
g_sysconf->kernel_version_patch = _kernel_header.version_patch;
|
|
g_sysconf->kernel_version_gitsha = _kernel_header.version_gitsha;
|
|
|
|
g_sysconf->sys_page_size = mem::frame_size;
|
|
g_sysconf->sys_large_page_size = 0;
|
|
g_sysconf->sys_huge_page_size = 0;
|
|
g_sysconf->sys_num_cpus = g_num_cpus;
|
|
}
|