Commit Graph

321 Commits

Author SHA1 Message Date
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
raiden00pl 5b87fdfb9d Documentation: remove all migrated READMEs 2023-10-29 21:03:54 -03: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
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +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
Xiang Xiao 55b5561fdb sched/task: Implement execle and execve
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-22 10:40:31 +03:00
Ville Juven d6ef4849a9 syscall: Add call gate for get_environ_ptr
Now that the environment strings are stored as an array of strings,
they can be passed from the application via char **environ, which
is really defined as a function call to get_environ_ptr().

This works as is for flat build, but protected mode and kernel mode
require a call gate, which is added here.
2022-04-21 18:38:37 +08:00
Xiang Xiao 9f7ecbd5b7 syscall: Fix Makefile:69: target 'syscall_names.o' given more than once in the same rule
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-04 08:44:50 +02:00
chao.an ea42981cc6 syscall/names: export the syscall name in STUB module
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-03-14 21:37:53 +02:00
Xiang Xiao 4deaa6d29d syscal: Remove .context form .gitignore
since it is already added in the top level of .gitignore

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-02 10:42:05 +01:00
Xiang Xiao 44bd3212d4 arch: Remove SYS_RESERVED from Kconfg
let's arch define the correct value instead

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-27 22:54:13 +08:00
Huang Qi e516c6247e sched: Implement task local storage
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-02-23 22:05:02 +08:00