feat(kernel/syscalls): implement uname syscall

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
EnderIce2 2025-03-10 22:38:52 +00:00
parent fc43512c75
commit 9f393754f6
No known key found for this signature in database
GPG Key ID: 2EE20AF089811A5A
6 changed files with 132 additions and 2 deletions

View File

@ -624,6 +624,14 @@ typedef struct FramebufferScreenInfo
*/
#define FBIOGET_SCREEN_INFO 0xf0
struct kutsname
{
char sysname[65];
char release[65];
char version[65];
char machine[65];
};
/**
* @brief List of syscalls
*
@ -1601,6 +1609,22 @@ typedef enum
* - #EACCES if permission is denied
*/
SYS_RENAME,
/**
* @brief Get unix name information
*
* @code
* int uname(struct kutsname *buf);
* @endcode
*
* @details Retrieves information about the operating system.
*
* @param buf Pointer to `kutsname` structure to store information
*
* @return
* - #EOK on success
* - #EFAULT if `buf` is outside accessible address space
*/
SYS_UNAME,
/**
* @brief Max number of syscalls
@ -1782,4 +1806,7 @@ typedef enum
/** @copydoc SYS_RENAME */
#define call_rename(oldpath, newpath) syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath)
/** @copydoc SYS_UNAME */
#define call_uname(buf) syscall1(SYS_UNAME, (scarg)buf)
#endif // !__FENNIX_API_SYSCALLS_LIST_H__

View File

@ -9,6 +9,6 @@
#define __kernel__ 1
#define KERNEL_NAME "Fennix"
#define KERNEL_ARCH "amd64"
#define KERNEL_VERSION "1.0"
#define KERNEL_VERSION "1.0.0"
#define GIT_COMMIT "0000000000000000000000000000000000000000"
#define GIT_COMMIT_SHORT "0000000"

View File

@ -624,6 +624,14 @@ typedef struct FramebufferScreenInfo
*/
#define FBIOGET_SCREEN_INFO 0xf0
struct kutsname
{
char sysname[65];
char release[65];
char version[65];
char machine[65];
};
/**
* @brief List of syscalls
*
@ -1601,6 +1609,22 @@ typedef enum
* - #EACCES if permission is denied
*/
SYS_RENAME,
/**
* @brief Get unix name information
*
* @code
* int uname(struct kutsname *buf);
* @endcode
*
* @details Retrieves information about the operating system.
*
* @param buf Pointer to `kutsname` structure to store information
*
* @return
* - #EOK on success
* - #EFAULT if `buf` is outside accessible address space
*/
SYS_UNAME,
/**
* @brief Max number of syscalls
@ -1782,4 +1806,7 @@ typedef enum
/** @copydoc SYS_RENAME */
#define call_rename(oldpath, newpath) syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath)
/** @copydoc SYS_UNAME */
#define call_uname(buf) syscall1(SYS_UNAME, (scarg)buf)
#endif // !__FENNIX_API_SYSCALLS_LIST_H__

View File

@ -212,6 +212,54 @@ static int sys_rmdir(SysFrm *Frame, const char *path) { return -ENOSYS; }
static int sys_unlink(SysFrm *Frame, const char *pathname) { return -ENOSYS; }
static int sys_rename(SysFrm *Frame, const char *oldpath, const char *newpath) { return -ENOSYS; }
static int sys_uname(SysFrm *Frame, struct kutsname *buf)
{
PCB *pcb = thisProcess;
Memory::VirtualMemoryArea *vma = pcb->vma;
struct kutsname *pBuf = vma->UserCheckAndGetAddress(buf, sizeof(struct kutsname));
if (pBuf == nullptr)
return -EFAULT;
strncpy(pBuf->sysname, KERNEL_NAME, sizeof(pBuf->sysname));
char release[sizeof(pBuf->release)];
sprintf(release, "%s", KERNEL_VERSION);
strncpy(pBuf->release, release, sizeof(pBuf->release));
char version[sizeof(pBuf->version)];
bool isDebug = false;
#ifdef DEBUG
isDebug = true;
#endif
sprintf(version, "FNX-v%s-%s %s %s %s %s",
KERNEL_VERSION, GIT_COMMIT_SHORT,
isDebug ? "DEBUG" : "RELEASE",
__DATE__, __TIME__, __VERSION__);
strncpy(pBuf->version, version, sizeof(pBuf->version));
#if defined(__amd64__)
const char *osarch = "x86_64";
#elif defined(__i386__)
const char *osarch = "i386";
#elif defined(__aarch64__)
const char *osarch = "aarch64";
#elif defined(__arm__)
const char *osarch = "arm";
#else
const char *osarch = "unknown";
#endif
strncpy(pBuf->machine, osarch, sizeof(pBuf->machine));
debug("%s %s %s %s", pBuf->sysname, pBuf->release,
pBuf->version, pBuf->machine);
return 0;
}
static SyscallData scTbl[SYS_MAX] = {};
__constructor void __init_native_syscalls(void)
{
@ -281,6 +329,7 @@ __constructor void __init_native_syscalls(void)
scTbl[SYS_RMDIR] = {"SYS_RMDIR", (void *)sys_rmdir};
scTbl[SYS_UNLINK] = {"SYS_UNLINK", (void *)sys_unlink};
scTbl[SYS_RENAME] = {"SYS_RENAME", (void *)sys_rename};
scTbl[SYS_UNAME] = {"SYS_UNAME", (void *)sys_uname};
}
uintptr_t HandleNativeSyscalls(SysFrm *Frame)

View File

@ -624,6 +624,14 @@ typedef struct FramebufferScreenInfo
*/
#define FBIOGET_SCREEN_INFO 0xf0
struct kutsname
{
char sysname[65];
char release[65];
char version[65];
char machine[65];
};
/**
* @brief List of syscalls
*
@ -1601,6 +1609,22 @@ typedef enum
* - #EACCES if permission is denied
*/
SYS_RENAME,
/**
* @brief Get unix name information
*
* @code
* int uname(struct kutsname *buf);
* @endcode
*
* @details Retrieves information about the operating system.
*
* @param buf Pointer to `kutsname` structure to store information
*
* @return
* - #EOK on success
* - #EFAULT if `buf` is outside accessible address space
*/
SYS_UNAME,
/**
* @brief Max number of syscalls
@ -1782,4 +1806,7 @@ typedef enum
/** @copydoc SYS_RENAME */
#define call_rename(oldpath, newpath) syscall2(SYS_RENAME, (scarg)oldpath, (scarg)newpath)
/** @copydoc SYS_UNAME */
#define call_uname(buf) syscall1(SYS_UNAME, (scarg)buf)
#endif // !__FENNIX_API_SYSCALLS_LIST_H__

View File

@ -17,7 +17,7 @@ OSARCH = amd64
BOARD_TYPE := raspi4
# Kernel version.
KERNEL_VERSION = dev
KERNEL_VERSION = 0.0.1
# Which bootloader to use.
# Available bootloaders: