kernel+libc: Add uname()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-04-24 20:34:44 +02:00
parent a99a0e5a54
commit 9eab0886b6
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 64 additions and 1 deletions

View File

@ -37,6 +37,7 @@ set(SOURCES
src/sys/stat.cpp
src/sys/chdir.cpp
src/sys/link.cpp
src/sys/uname.cpp
src/fs/VFS.cpp
src/fs/tmpfs/FileSystem.cpp
src/fs/devices/DeviceRegistry.cpp

25
kernel/src/sys/uname.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "arch/CPU.h"
#include "memory/MemoryManager.h"
#include "sys/Syscall.h"
#include <bits/struct_utsname.h>
#include <luna/CString.h>
Result<u64> sys_uname(Registers*, SyscallArgs args)
{
utsname* buf = (utsname*)args[0];
utsname result;
strncpy(result.sysname, "moon", _UTSNAME_LENGTH);
strncpy(result.nodename, "lunar", _UTSNAME_LENGTH);
// FIXME: Hardcode these at build time instead of in code.
strncpy(result.release, "0.1", _UTSNAME_LENGTH);
strncpy(result.version, "alpha", _UTSNAME_LENGTH);
strncpy(result.machine, CPU::platform_string(), _UTSNAME_LENGTH);
if (!MemoryManager::copy_to_user_typed(buf, &result)) return err(EFAULT);
return 0;
}

View File

@ -0,0 +1,17 @@
/* bits/struct_utsname.h: The utsname structure. */
#ifndef _BITS_STRUCT_UTSNAME_H
#define _BITS_STRUCT_UTSNAME_H
#define _UTSNAME_LENGTH 256
struct utsname
{
char sysname[_UTSNAME_LENGTH];
char nodename[_UTSNAME_LENGTH];
char release[_UTSNAME_LENGTH];
char version[_UTSNAME_LENGTH];
char machine[_UTSNAME_LENGTH];
};
#endif

View File

@ -0,0 +1,20 @@
/* sys/utsname.h: Kernel name and information. */
#ifndef _SYS_UTSNAME_H
#define _SYS_UTSNAME_H
#include <bits/struct_utsname.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* Get kernel name and information. */
int uname(struct utsname* buf);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -4,7 +4,7 @@
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(openat) _e(close) _e(read) _e(getpid) _e(write) \
_e(lseek) _e(mkdir) _e(execve) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl) _e(getdents) _e(getuid) \
_e(geteuid) _e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(chmod) _e(chown) \
_e(ioctl) _e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat)
_e(ioctl) _e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) _e(uname)
enum Syscalls
{