mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-16 01:05:15 +08:00
[components][lwp] split syscall implementation by subsystem
- move syscall implementations from lwp_syscall.c into syscall/ - group memory, file, socket, process, IPC and time syscalls - add a shared syscall dispatch table and internal header - register the new directory from the LWP build script - no functional change
This commit is contained in:
1 parent
b4c6828cf4
commit
68757abdcc
22 files changed
+12085
-11638
No files matched your search
@@ -57,6 +57,7 @@ if not GetDepend(['LWP_USING_RUNTIME']):
|
||||
|
||||
group = DefineGroup('lwProcess', src, depend = ['RT_USING_SMART'], CPPPATH = CPPPATH)
|
||||
|
||||
group = group + SConscript(os.path.join('syscall', 'SConscript'))
|
||||
group = group + SConscript(os.path.join('vdso', 'SConscript'))
|
||||
group = group + SConscript(os.path.join('utest', 'SConscript'))
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,11 @@
|
||||
# RT-Thread building script for component
|
||||
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp') + Glob('*.cxx') + Glob('*.cc')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('lwProcess', src, depend = ['RT_USING_SMART'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "syscall_internal.h"
|
||||
|
||||
/**
|
||||
* @brief Retrieves information about a file or directory.
|
||||
*
|
||||
* This system call obtains metadata about the specified file or directory and stores it in
|
||||
* the `buf` structure. The metadata includes attributes such as file size, permissions,
|
||||
* ownership, and timestamps.
|
||||
*
|
||||
* @param[in] file A pointer to the path of the file or directory to be queried.
|
||||
* The path should be a null-terminated string.
|
||||
* @param[out] buf A pointer to a `struct stat` structure where the file's metadata
|
||||
* will be stored. This structure must be allocated by the caller.
|
||||
*
|
||||
* @return sysret_t Returns a status code:
|
||||
* - `0`: The operation completed successfully, and the metadata
|
||||
* has been written to `buf`.
|
||||
* - Other error codes may indicate issues with the file path.
|
||||
*
|
||||
* @note The `file` path must be valid and accessible by the calling process. Ensure that
|
||||
* the `buf` pointer points to a properly allocated memory region.
|
||||
*
|
||||
* @warning Passing a `NULL` pointer for `file` or `buf` may result in undefined behavior.
|
||||
* Check all inputs before invoking this function to avoid potential issues.
|
||||
*/
|
||||
sysret_t sys_stat(const char *file, struct stat *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
size_t len;
|
||||
size_t copy_len;
|
||||
char *copy_path;
|
||||
struct stat statbuff = { 0 };
|
||||
|
||||
if (!lwp_user_accessable((void *)buf, sizeof(struct stat)))
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
len = lwp_user_strlen(file);
|
||||
if (len <= 0)
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
copy_path = (char *)rt_malloc(len + 1);
|
||||
if (!copy_path)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
copy_len = lwp_get_from_user(copy_path, (void *)file, len);
|
||||
if (copy_len == 0)
|
||||
{
|
||||
rt_free(copy_path);
|
||||
return -EFAULT;
|
||||
}
|
||||
copy_path[copy_len] = '\0';
|
||||
|
||||
ret = _SYS_WRAP(stat(copy_path, &statbuff));
|
||||
rt_free(copy_path);
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
lwp_put_to_user(buf, &statbuff, sizeof statbuff);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieves metadata about a file or symbolic link.
|
||||
*
|
||||
* This system call obtains metadata for the specified file or symbolic link and stores
|
||||
* it in the `buf` structure. Unlike `sys_stat`, if the specified path refers to a
|
||||
* symbolic link, this function retrieves information about the link itself, not the
|
||||
* target it points to.
|
||||
*
|
||||
* @param[in] file A pointer to the path of the file or symbolic link to be queried.
|
||||
* The path must be a null-terminated string.
|
||||
* @param[out] buf A pointer to a `struct stat` structure where the metadata will be
|
||||
* stored. This structure must be allocated by the caller.
|
||||
*
|
||||
* @return sysret_t Returns a status code:
|
||||
* - `0`: The operation completed successfully, and the metadata
|
||||
* has been written to `buf`.
|
||||
* - Other error codes may indicate issues with the file path.
|
||||
*
|
||||
* @note This function is particularly useful for handling symbolic links when you want
|
||||
* to get information about the link itself rather than the target file or directory.
|
||||
* The `file` path must be valid and accessible by the calling process.
|
||||
*
|
||||
* @warning Passing a `NULL` pointer for `file` or `buf` may result in undefined behavior.
|
||||
* Always check inputs for validity before invoking this function.
|
||||
*/
|
||||
sysret_t sys_lstat(const char *file, struct stat *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
size_t len;
|
||||
size_t copy_len;
|
||||
char *copy_path;
|
||||
struct stat statbuff = { 0 };
|
||||
|
||||
if (!lwp_user_accessable((void *)buf, sizeof(struct stat)))
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
len = lwp_user_strlen(file);
|
||||
if (len <= 0)
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
copy_path = (char *)rt_malloc(len + 1);
|
||||
if (!copy_path)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
copy_len = lwp_get_from_user(copy_path, (void *)file, len);
|
||||
if (copy_len == 0)
|
||||
{
|
||||
rt_free(copy_path);
|
||||
return -EFAULT;
|
||||
}
|
||||
copy_path[copy_len] = '\0';
|
||||
#ifdef RT_USING_DFS_V2
|
||||
ret = _SYS_WRAP(dfs_file_lstat(copy_path, &statbuff));
|
||||
#else
|
||||
ret = _SYS_WRAP(stat(copy_path, &statbuff));
|
||||
#endif
|
||||
rt_free(copy_path);
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
lwp_put_to_user(buf, &statbuff, sizeof statbuff);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef __LWP_SYSCALL_INTERNAL_H__
|
||||
#define __LWP_SYSCALL_INTERNAL_H__
|
||||
|
||||
#define __RT_IPC_SOURCE__
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include <board.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define DBG_TAG "lwp.syscall"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#include "syscall_generic.h"
|
||||
#include "libc_musl.h"
|
||||
#include "lwp_internal.h"
|
||||
#include "lwp_ipc_internal.h"
|
||||
#include "mqueue.h"
|
||||
|
||||
#ifdef ARCH_MM_MMU
|
||||
#include <mm_aspace.h>
|
||||
#include <lwp_user_mm.h>
|
||||
#include <lwp_arch.h>
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <eventfd.h>
|
||||
#include <poll.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/select.h>
|
||||
#include <dfs_file.h>
|
||||
#ifdef RT_USING_DFS_V2
|
||||
#include <dfs_dentry.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef RT_USING_MUSLLIBC
|
||||
#include <sys/signalfd.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_SAL
|
||||
#include <netdev_ipaddr.h>
|
||||
#include <netdev.h>
|
||||
#include <sal_netdb.h>
|
||||
#include <sal_socket.h>
|
||||
#include <sys/socket.h>
|
||||
#include "lwp_sys_socket.h"
|
||||
#endif
|
||||
|
||||
#include <sched.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
#ifndef GRND_NONBLOCK
|
||||
#define GRND_NONBLOCK 0x0001
|
||||
#endif
|
||||
#ifndef GRND_RANDOM
|
||||
#define GRND_RANDOM 0x0002
|
||||
#endif
|
||||
|
||||
#ifndef RT_USING_POSIX_TIMER
|
||||
#error "No definition RT_USING_POSIX_TIMER"
|
||||
#endif
|
||||
#ifndef RT_USING_POSIX_CLOCK
|
||||
#error "No definition RT_USING_POSIX_CLOCK"
|
||||
#endif
|
||||
|
||||
void lwp_cleanup(struct rt_thread *tid);
|
||||
void _crt_thread_entry(void *parameter);
|
||||
|
||||
#ifdef ARCH_MM_MMU
|
||||
void *kmem_get(size_t size);
|
||||
void kmem_put(void *kptr);
|
||||
#define ALLOC_KERNEL_STACK_SIZE 5120
|
||||
#else
|
||||
#define ALLOC_KERNEL_STACK_SIZE 1536
|
||||
#define ALLOC_KERNEL_STACK_SIZE_MIN 1024
|
||||
#define ALLOC_KERNEL_STACK_SIZE_MAX 4096
|
||||
void set_user_context(void *stack);
|
||||
#endif
|
||||
|
||||
sysret_t sys_notimpl(void);
|
||||
|
||||
#ifdef RT_USING_SAL
|
||||
void convert_sockopt(int *level, int *optname);
|
||||
#endif
|
||||
|
||||
#if defined(RT_USING_LWIP) || defined(SAL_USING_UNET) || defined(RT_USING_SAL)
|
||||
struct musl_sockaddr;
|
||||
void sockaddr_tolwip(const struct musl_sockaddr *std, struct sockaddr *lwip);
|
||||
void sockaddr_tomusl(const struct sockaddr *lwip, struct musl_sockaddr *std);
|
||||
#endif
|
||||
|
||||
#endif /* __LWP_SYSCALL_INTERNAL_H__ */
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user