diff --git a/components/libc/compilers/common/include/sys/utsname.h b/components/libc/compilers/common/include/sys/utsname.h new file mode 100644 index 0000000000..5089f24b89 --- /dev/null +++ b/components/libc/compilers/common/include/sys/utsname.h @@ -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 */ +#ifndef _POSIX_SOURCE +#define _POSIX_SOURCE +#include_next +/* limiting influence of _POSIX_SOURCE */ +#undef _POSIX_SOURCE + +#else /* def _POSIX_SOURCE */ +#include_next +#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 diff --git a/components/lwp/lwp_syscall.c b/components/lwp/lwp_syscall.c index 7c0a83c39e..9b31b9ea58 100644 --- a/components/lwp/lwp_syscall.c +++ b/components/lwp/lwp_syscall.c @@ -34,6 +34,7 @@ #endif #include +#include #ifdef RT_USING_DFS #include @@ -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) diff --git a/include/rthw.h b/include/rthw.h index 8bbc3794e6..247b4b3d2d 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -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, diff --git a/libcpu/aarch64/common/cpu.c b/libcpu/aarch64/common/cpu.c index e8d55fd644..f5f96a5d90 100644 --- a/libcpu/aarch64/common/cpu.c +++ b/libcpu/aarch64/common/cpu.c @@ -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() { diff --git a/src/kservice.c b/src/kservice.c index e522a649cf..1c1d8da848 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -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",