feat(components): add uname support

This commit is contained in:
xqyjlj 2023-03-27 17:09:37 +08:00 committed by guo
parent c3b08d4288
commit 157dc0959c
5 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-03-27 xqyjlj add uname
*/
#ifndef __SYS_UTSNAME_H__
#define __SYS_UTSNAME_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef RT_USING_MUSLLIBC
/* this is required for musl <sys/utsname.h> */
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
#include_next <sys/utsname.h>
/* limiting influence of _POSIX_SOURCE */
#undef _POSIX_SOURCE
#else /* def _POSIX_SOURCE */
#include_next <sys/utsname.h>
#endif
#else
struct utsname
{
char sysname[65];
char nodename[65];
char release[65];
char version[65];
char machine[65];
char domainname[65];
};
int uname(struct utsname *);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -34,6 +34,7 @@
#endif
#include <fcntl.h>
#include <sys/utsname.h>
#ifdef RT_USING_DFS
#include <poll.h>
@ -4566,6 +4567,37 @@ rt_weak sysret_t sys_cacheflush(void *addr, int size, int cache)
return -EFAULT;
}
sysret_t sys_uname(struct utsname *uts)
{
struct utsname utsbuff = {0};
int ret = 0;
char *machine;
if (!lwp_user_accessable((void *)uts, sizeof(struct utsname)))
{
return -EFAULT;
}
rt_strncpy(utsbuff.sysname, "RT-Thread", sizeof(utsbuff.sysname));
utsbuff.nodename[0] = '\0';
ret = rt_snprintf(utsbuff.release, sizeof(utsbuff.release), "%u.%u.%u",
RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH);
if (ret < 0) {
return -EIO;
}
ret = rt_snprintf(utsbuff.version, sizeof(utsbuff.version), "RT-Thread %u.%u.%u %s %s",
RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH, __DATE__, __TIME__);
if (ret < 0) {
return -EIO;
}
machine = rt_hw_cpu_arch();
rt_strncpy(utsbuff.machine, machine, sizeof(utsbuff.machine));
utsbuff.domainname[0] = '\0';
lwp_put_to_user(uts, &utsbuff, sizeof utsbuff);
return 0;
}
const static struct rt_syscall_def func_table[] =
{
SYSCALL_SIGN(sys_exit), /* 01 */
@ -4776,6 +4808,7 @@ const static struct rt_syscall_def func_table[] =
SYSCALL_SIGN(sys_mq_getsetattr),
SYSCALL_SIGN(sys_mq_close),
SYSCALL_SIGN(sys_stat), //TODO should be replaced by sys_lstat if symbolic link are implemented
SYSCALL_SIGN(sys_uname), /* 170 */
};
const void *lwp_get_sys_api(rt_uint32_t number)

View File

@ -86,6 +86,8 @@ void rt_hw_cpu_dcache_ops(int ops, void* addr, int size);
void rt_hw_cpu_reset(void);
void rt_hw_cpu_shutdown(void);
const char *rt_hw_cpu_arch(void);
rt_uint8_t *rt_hw_stack_init(void *entry,
void *parameter,
rt_uint8_t *stack_addr,

View File

@ -348,6 +348,11 @@ rt_weak void rt_hw_secondary_cpu_idle_exec(void)
*/
/*@{*/
const char *rt_hw_cpu_arch(void)
{
return "aarch64";
}
/** shutdown CPU */
rt_weak void rt_hw_cpu_shutdown()
{

View File

@ -62,6 +62,11 @@ rt_weak void rt_hw_us_delay(rt_uint32_t us)
"Please consider implementing rt_hw_us_delay() in another file.\n"));
}
rt_weak const char *rt_hw_cpu_arch(void)
{
return "unknown";
}
static const char* rt_errno_strs[] =
{
"OK",