Commit Graph

243 Commits

Author SHA1 Message Date
YAMAMOTO Takashi 761ee81956 move readv/writev to the kernel
currently, nuttx implements readv/writev on the top of read/write.
while it might work for the simplest cases, it's broken by design.
for example, it's impossible to make it work correctly for files
which need to preserve data boundaries without allocating a single
contiguous buffer. (udp socket, some character devices, etc)

this change is a start of the migration to a better design.
that is, implement read/write on the top of readv/writev.

to avoid a single huge change, following things will NOT be done in
this commit:

* fix actual bugs caused by the original readv-based-on-read design.
  (cf. https://github.com/apache/nuttx/pull/12674)

* adapt filesystems/drivers to actually benefit from the new interface.
  (except a few trivial examples)

* eventually retire the old interface.

* retire read/write syscalls. implement them in libc instead.

* pread/pwrite/preadv/pwritev (except the introduction of struct uio,
  which is a preparation to back these variations with the new
  interface.)
2024-10-30 17:07:54 +08:00
Xiang Xiao 32784b0898 libc: Refine the arc4random_buf implementation
fill the buffer with getrandom instead random pool
and move the implementation to from crypto to libc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-26 18:04:21 -03:00
makejian e8a890ef42 nuttx/syscall: export nxsem_getprioceiling and nxsem_setprioceiling via syscall
Signed-off-by: makejian <makejian@xiaomi.com>
2024-10-12 09:50:54 +08:00
fangxinyong 76508d42a9 sched: export sched_getcpu API in AMP mode
Some app with same code runs on different cores in AMP mode,
need known physical core id on which the function is called.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-10-09 15:21:25 +08:00
chenrun1 d04205aa3d fs/mmap/msync:support msync.
Summary:
  1.Added msync callback in struct mm_map_entry_s
  2.Added msync API in fs_msync.c
  3.Added static msync_rammap for rammap.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-19 01:43:50 +08:00
pangzhen1 8bb62e532c nuttx/syscall: delete getrandom in syscall.csv
delete getrandom in syscall.csv, because it has been moved to libc.

Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
2024-08-27 21:44:33 +08:00
guohao15 86e00896d3 fs:notify add support for inotify
support API: open close read write unlink mkdir rename fchstat rmdir symlink

Signed-off-by: guohao15 <guohao15@xiaomi.com>
2024-08-22 01:50:37 +08:00
zhanghongyu ee4c25f34e sem_open: return error code, sem returned by parameter
pointer comparison is unsigned, when returning -errno will be converted
to a large positive number, can not enter the error handling branch,
therefore, the error code is returned directly and the sem is returned
through the parameters.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-06-06 02:40:50 +08:00
Huang Qi 97ec55db46 syscall.csv: Correct macro guard of setsockopt
setsockopt only available if both NET and  NET_SOCKOPTS enabled.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-05-29 20:37:12 +08:00
Ville Juven 5f36a43609 sched/semaphore: Move named semaphores to user space 2023-11-27 04:52:54 -08:00
Ville Juven c9bdadd541 sched/semaphore: Move cancel point and errno handling to libc / user-space
This moves all the public POSIX semaphore functions into libc and with
this most of the user-space logic is also moved; namely cancel point and
errno handling.

This also removes the need for the _SEM_XX macros used to differentiate
which API is used per user-/kernel mode. Such macros are henceforth
unnecessary.
2023-11-27 04:52:54 -08:00
Ville Juven 0dedbcd4ae task/pthread_cancelpt: Move cancel point handling to libc, data to TLS
This moves task / thread cancel point logic from the NuttX kernel into
libc, while the data needed by the cancel point logic is moved to TLS.

The change is an enabler to move user-space APIs to libc as well, for
a coherent user/kernel separation.
2023-11-15 08:52:04 -08:00
Xiang Xiao b1c8c84e81 stdio: Merge fs_fdopen into fdopen to simplify the code logi
since fs_fdopen could avoid call the kernel specific function now

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
Xiang Xiao 47faeeb360 tls: Move task_tls_alloc and task_tls_destruct to libc
so task_tls_destruct can be called from usrspace, which is required by:
https://github.com/apache/nuttx/pull/10288

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-28 11:02:18 +03:00
fangxinyong 896f34fde9 sched: implement effective uid and gid interfaces
Implement 'effective' setuid, getuid, setgid, and getgid interfaces.
These will be inheritance by all child task groups. These definitons
are explicitly specified here:
https://pubs.opengroup.org/onlinepubs/000095399/functions/geteuid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/getegid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/seteuid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/setegid.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-09 17:07:58 +08:00
guoshichao 3524f4b9ce libs/libc/fork: add lib_fork implementation
1. add lib_fork api in libs/libc, we need a fork() api to implement the
fork relative method, such as pthread_atfork
2. rename the assembly fork entry function name to up_fork(), and rename
the up_fork() to arch specific name, such as
sim_fork()/arm_fork()/mips_fork() etc.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-26 10:41:52 +02:00
guoshichao c33d1c9c97 sched/task/fork: add fork implementation
1. as we can use fork to implement vfork, so we rename the vfork to
fork, and use the fork method as the base to implement vfork method
2. create the vfork function as a libc function based on fork
function

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-12 02:27:37 +08:00
Petro Karashchenko b8d3e32bdf sched/clock: move clock_getcpuclockid() and clock_getres() to libc
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-07 17:39:39 -03:00
Gregory Nutt 8868c58720 Fix Deadloop in VFS if CONFIG_CANCELLATION_POINTS is enabled
If cancellation points are enabled, then the following logic is activated in sem_wait().  This causes ECANCELED to be returned every time that sem_wait is called.

    int sem_wait(FAR sem_t *sem)
    {
      ...

      /* sem_wait() is a cancellation point */

      if (enter_cancellation_point())
        {
    #ifdef CONFIG_CANCELLATION_POINTS
          /* If there is a pending cancellation, then do not perform
           * the wait.  Exit now with ECANCELED.
           */

          errcode = ECANCELED;
          goto errout_with_cancelpt;
    #endif
        }
      ...

Normally this works fine.  sem_wait() is the OS API called by the application and will cancel the thread just before it returns to the application.  Since it is cancellation point, it should never be called from within the OS.

There there is is one perverse cases where sem_wait() may be nested within another cancellation point.  If open() is called, it will attempt to lock a VFS data structure and will eventually call nxmutex_lock().  nxmutex_lock() waits on a semaphore:

   int nxmutex_lock(FAR mutex_t *mutex)
   {
     ...

     for (; ; )
       {
         /* Take the semaphore (perhaps waiting) */

         ret = _SEM_WAIT(&mutex->sem);
         if (ret >= 0)
           {
             mutex->holder = _SCHED_GETTID();
             break;
           }

         ret = _SEM_ERRVAL(ret);
         if (ret != -EINTR && ret != -ECANCELED)
           {
             break;
           }
       }
   ...
}

In the FLAT build, _SEM_WAIT expands to sem_wait().  That causes the error in the logic:  It should always expand to nxsem_wait().  That is because sem_wait() is cancellation point and should never be called from with the OS or the C library internally.

The failure occurs because the cancellation point logic in sem_wait() returns -ECANCELED (via _SEM_ERRVAL) because sem_wait() is nested; it needs to return the -ECANCELED error to the outermost cancellation point which is open() in this case.  Returning -ECANCELED then causes an infinite loop to occur in nxmutex_lock().

The correct behavior in this case is to call nxsem_wait() instead of sem_wait().  nxsem_wait() is identical to sem_wait() except that it is not a cancelation point.  It will return -ECANCELED if the thread is canceled, but only once.  So no infinite loop results.

In addition, an nxsem_wait() system call was added to support the call from nxmutex_lock().

This resolves Issue #9695
2023-07-06 14:20:29 -03:00
guoshichao bc084a8505 sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation
1. the implementation can pass the full
ltp/open_posix_testsuite/clock_getcpuclockid testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-05 00:32:11 +08:00
zhangyuan21 884be2bdb9 assert: Distinguish between assert and exception
CURRENT_REGS may change during assert handling, so pass
in the 'regs' parameter at the entry point of _assert.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-05-03 14:49:32 +08:00
hujun5 d189a86a35 system: pthread_barrierwait should be moved to kernel space
The current implementation requires the use of enter_critical_section, so the source code needs to be moved to kernel space

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-04-25 15:34:40 +08:00
chao an 3c58f5db2b syscall/libc: add more syscall/libc symbols into csv file
Signed-off-by: chao an <anchao@xiaomi.com>
2023-03-31 21:56:50 +09:00
Xiang Xiao a3a1883787 fs: Don't guard rename with CONFIG_DISABLE_MOUNTPOINT
since the pseudo root fs support rename too

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-14 11:24:37 +08:00
Xiang Xiao 4009cb1970 fs: Don't guard ftruncate with CONFIG_DISABLE_MOUNTPOINT
since ftruncate depends on file_operations not mountpt_operations

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-14 11:24:37 +08:00
Xiang Xiao a05f9aaa85 fs: Don't guard fsync with CONFIG_DISABLE_MOUNTPOINT
since the driver can also support fsync by implementing BIOC_FLUSH

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-14 11:24:37 +08:00
dongjiuzhu1 63e6f80fb0 sync: add sync api
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-02-07 12:15:05 +02:00
Stuart Ianna a2a542562f fs: Implment link as a normal function instead macro
so "using ::link;" can pass the compiling. This change also
simplify the implementation of the hard link in the future.
2023-02-04 18:31:23 -03:00
Zhe Weng 8819eeaf15 net: Implement shutdown() interface and tcp shutdown
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 11:15:01 +08:00
Xiang Xiao 819fbd22cc sched: Implement tkill/tgkill
https://linux.die.net/man/2/tgkill

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-26 08:11:56 +02:00
Xiang Xiao 43e7b13697 assert: Log the assertion expression in case of fail
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-24 15:00:19 -03:00
Jukka Laitinen b09581f736 Add shm_open and shm_unlink to syscalls
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-18 11:01:20 +08:00
Xiang Xiao 695f42f8d2 net: Move accept to libc after https://github.com/apache/nuttx/pull/8083
since accept can simply forward to kernel accept4 function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-13 11:23:42 +02:00
zhanghongyu 48c9d10336 net_socket: add accept4 function
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-11 23:28:08 +08:00
Jukka Laitinen 0a885da434 syscall: Always add munmap into syscalls
Munmap interface is always enabled just like mmap is

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-11 03:11:11 +08:00
Ville Juven 172b209f2d sched/assert: Re-implement assert() into user space
_assert is a kernel procedure, entered via system call to make the core
dump in privileged mode.

Running exit() from this context is not OK as it runs the registered
exit functions and flushes streams, which must not be done
from privileged mode as it is a security hole.

Thus, implement assert() into user space (again) and remove the exit()
call from the kernel procedure.
2022-12-22 21:07:47 +08:00
Ville Juven 2ed51d026c fs/streams: Move the file streams from the group structure into TLS
This is preparation for flushing streams from user space, like it should
be done.

- Move tg_streamlist (group, kernel space) ->
       ta_streamlist (TLS, user space)
- Access stream list via tg_info in kernel
- Access stream list via TLS in user space
- Remove / rename nxsched_get_streams -> lib_getstreams
- Remove system call for nxsched_get_streams
2022-12-22 20:16:11 +08:00
田昕 2719869ab2 Move _assert to kernel space.
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2022-12-06 18:33:21 +08:00
Michael Jung b401db5ca4 prctl syscall is present unconditionally
I had a link problem regarding prctl while CONFIG_TASK_NAME_SIZE was
defined 0 and building in protected mode.  Turns out in monolithic
build prctl is present no matter what CONFIG_TASK_NAME_SIZE, but in
protected mode build its only present if CONFIG_TASK_NAME_SIZE > 0.
So, bring protected mode build in sync with the monolithic one.

Signed-off-by: Michael Jung <michael.jung@secore.ly>
2022-11-09 01:21:16 +08:00
Xiang Xiao 19bded4738 fs: Remove the unused nx_pipe to prefer file_pipe for kernel
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-27 23:14:25 +02:00
Xiang Xiao ee82f7b5ca Fix error: proxies/PROXY_socketpair.c:9:55: error: argument 4 of type 'int *' declared as a pointer [-Werror=array-parameter=]
9 | int socketpair(int parm1, int parm2, int parm3, int * parm4)
      |                                                 ~~~~~~^~~~~
In file included from proxies/PROXY_socketpair.c:4:
/github/workspace/sources/nuttx/include/sys/socket.h:373:56: note: previously declared as an array 'int[2]'
  373 | int socketpair(int domain, int type, int protocol, int sv[2]);
      |

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-23 12:08:30 +08:00
yangxuan8282 c77743c463 syscall: fix task_testcancel header file 2022-08-24 16:47:19 +08:00
Jiuzhu Dong aeec797511 syscall: remove directory syscall
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-08-10 13:33:08 +08:00
Masayuki Ishikawa d96c87f666 syscall: Add socketpair to syscall.csv
Summary:
- This commit adds socketpair to syscall.csv

Impact:
- None

Testing:
- Tested with adb (not merged net)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-07-15 13:31:58 +08:00
Masayuki Ishikawa a384b05aa4 syscall: Fix task_tls_alloc in syscall.csv
Summary:
- This commit fixes comiple error for task_tls_alloc

Impact:
- None

Testing:
- Tested with sabre-6quad:netknsh (not merged yet)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-07-11 09:32:52 -03:00
Ville Juven ba4277bb13 syscall: Remove exit() call gate
exit() is a userspace function, no need for call gate
2022-06-20 14:14:28 +03:00
Ville Juven a54c3d13f9 sched: Remove SCHED_ATEXIT / SCHED_ONEXIT
Remove the kernel side implementations altogether. These will be
replaced by user land implementations.
2022-05-25 15:28:43 +08:00
Ville Juven 5bcd1dbb64 sched: Remove task_restart in case of CONFIG_BUILD_KERNEL
Same treatment as task_delete, this is not usable in kernel build
either.
2022-05-12 22:08:19 +08:00
Ville Juven b1d92159fa sched: Remove task_delete in case of CONFIG_BUILD_KERNEL
Deleting a task from another task's context will not do, so shut
this gate down for BUILD_KERNEL. In this case if a task wants another
task to terminate, it must ask the other task to politely kill itself.

Note: kthreads still need this, also, the kernel can delete a task
without asking.
2022-05-12 03:27:25 +08:00
Ville Juven cf90e3f66b syscall: Fix prototype of exec() to syscall.csv 2022-04-22 14:34:42 +03:00