Commit Graph

231 Commits

Author SHA1 Message Date
ligd 415fe60695 signal: use work_cancel_sync() to fix used after free
bug:

user thread:                             hpwork:
timer_create() with SIGEV_THREAD
timer_settime()
    irq -> work_queue()                  add nxsig_notification_worker to Q
timer_delete()
    nxsig_cancel_notification()
                                         call nxsig_notification_worker()
    work_cancel()
    timer_free()
                                         nxsig_notification_worker() used after free

root cause:
work_cancel() can't cancel work completely, the worker may alreay be running.

resolve:
use work_cancel_sync() API to cancel the work completely

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 15:52:48 +08:00
xuxin19 d93d377257 cmake:complete missing changes during cmake reforming for sched
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-08 21:20:16 +03:00
chao an 664927c86e mm/alloc: remove all unnecessary cast for alloc
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 14:34:20 +08:00
xinhaiteng dbefe37a3a sigqueue: add signal type judgment logic
To determine whether a signal is real-time signal or standard signal, the POSIX standard https://www.man7.org/linux/man-pages/man7/signal.7.html defines a real-time signal between SIGRTMIN  and SIGRTMAX , which can store multiple copies, otherwise only one can be retained.

Signed-off-by: xinhaiteng <xinhaiteng@xiaomi.com>
2023-08-21 15:35:45 +08:00
yinshengkai 8fa4f2d61d add the startup process tracepoint
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-19 21:50:08 +08:00
Petro Karashchenko d113722eb2 style: fix indentation issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
zhangyuan21 671c5dc3d8 sched/pthread: Don't do cancel when it is already in the exit process
When the task is already in the exit process,
do not execute pthread cancel and return ESRCH.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-03 03:12:36 -07:00
guanyi 55a727b1ce ltp: sigprocmask fix
1. change signal/sig_procmask.c and pthread/pthread_sigmask.c together
2. clear signals unconditionally

Signed-off-by: guanyi <guanyi@xiaomi.com>
2023-07-31 22:29:31 -07:00
guoshichao 0092b3e30f sched/signal/sig_nanosleep: fix the clock_nanosleep posix case
1. make the clock_nanosleep can pass
ltp/open_posix_testsuite/clock_nanosleep 13-1, 10-1, 9-1 cases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-23 22:02:03 -07:00
fangxinyong 7462b199bb signal: SIGCONT can be caught
pass ltp sigaction case 19-5.c, 23-5,c and 28-5.c.
When SIGCONT is dispatched, resume all members of the task group.
So there is nothing do in default action.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-07-12 21:27:06 +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
fangxinyong dc7f8f136c signal: correct to const pointer for sigorset and sigandset
the two GNU functions, should use const input pointer parameter.

https://refspecs.linuxfoundation.org/LSB_1.3.0/gLSB/gLSB/baselib-sigorset.html
https://refspecs.linuxfoundation.org/LSB_1.3.0/gLSB/gLSB/baselib-sigandset.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-07-05 16:26:18 +08:00
Petro Karashchenko 1b801a5bbc style: remove extra spaces and align parameters
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-06-11 12:55:29 +08:00
chao an fb9b41221d semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00
Petro Karashchenko 764f8ef9be sched/signal: fix typo in comments
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Gregory Nutt 8cca30b44c Signal must be masked when it is delivered to a signal handler
Signal must be masked when it is delivered to a signal handler per:

https://pubs.opengroup.org/onlinepubs/007904875/functions/sigaction.html:

When a signal is caught by a signal-catching function installed by sigaction(), a new signal mask is calculated and installed for the duration of the signal-catching function (or until a call to either sigprocmask() or sigsuspend() is made). This mask is formed by taking the union of the current signal mask and the value of the sa_mask for the signal being delivered [XSI] [Option Start] unless SA_NODEFER or SA_RESETHAND is set, [Option End] and then including the signal being delivered. If and when the user's signal handler returns normally, the original signal mask is restored.

Any action queued for that signal while the signal is masked should be deferred. It should go into the group pending signal list and should not be processed until until the signal is unmasked (which should occur when the signal handler returns).
2023-05-18 01:19:12 +08:00
anjiahao 1e22163b57 sig_timewait:remove useless assert
use sclock_t repalce int64 and int32

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-04 18:04:45 +03:00
anjiahao 78bff8e9c5 sig_timewait:changes the macro for waitticks
use SYSTEM_TIME64 inside of LONG LONG better

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-04-30 00:41:06 +08:00
Petro Karashchenko a8f4a89221 signal: add SIGSYS
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-03-28 11:24:35 -06:00
Gregory Nutt 717bb04cb7 Increase the number of real time signals. Two is not enough.
Refer to issue #8867 for details and rational.

Convert sigset_t to an array type so that more than 32 signals can be supported.

Why not use a uin64_t?
- Using a uin32_t is more flexible if we decide to increase the number of signals beyound 64.
- 64-bit accesses are not atomic, at least not on 32-bit ARMv7-M and similar
- Keeping the base type as uint32_t does not introduce additional overhead due to padding to achieve 64-bit alignment of uin64_t
- Some architectures still supported by NuttX do not support uin64_t
  types,

Increased the number of signals to 64. This matches Linux. This will support all xsignals defined by Linux and also 32 real time signals (also like Linux).

This is is a work in progress; a draft PR that you are encouraged to comment on.
2023-03-27 16:59:04 +03:00
Ville Juven 776e2d774f signal/sig_dispatch: Add signal action, if task is in system call
The _unmasked_ signal action was never added if the task is in system call
and waiting for (a different) signal.

This fixes deliver especially for default signal actions / unmaskable
signals, like SIGTERM.
2023-03-14 11:16:52 +09:00
Ville Juven 47ce89f757 Revert "signal/sig_dispatch: Signal action was not performed if TCB_FLAG_SYSCALL is set"
This reverts commit 0e44666828.
2023-03-08 10:13:26 +01:00
Ville Juven 3f529b4882 Revert "signal/sig_dispatch: Fix case where signal action is sent twice"
This reverts commit be0cb4cbe3.
2023-03-08 10:13:26 +01:00
chenrun1 e6227e1943 include/signal.h:Expanding SIGNAL to be consistent with Linux 2023-02-24 04:07:10 +08:00
Ville Juven be0cb4cbe3 signal/sig_dispatch: Fix case where signal action is sent twice
As far as I can interpret how signal delivery should work when the signal
is blocked, it should still be sent to the pending queue even if the signal
is masked. When the sigmask changes it will be delivered.

The original implementation did not add the pending signal action, if
stcb->task_state == TSTATE_WAIT_SIG is true.

An attempt to patch this was made in #8563 but it is insufficient as it
creates an issue when the task is not waiting for a signal, but is in
syscall, in this case the signal is incorrectly queued twice.
2023-02-22 01:29:06 +08:00
Ville Juven df1d7dd480 libc/exit: Purge calls to userspace API exit() from kernel
Remove calls to the userspace API exit() from the kernel. The problem
with doing such calls is that the exit functions are called with kernel
mode privileges which is a big security no-no.
2023-02-17 23:07:17 +08:00
Ville Juven 0e44666828 signal/sig_dispatch: Signal action was not performed if TCB_FLAG_SYSCALL is set
For some reason the signal action was never performed if the receiveing
task was within a system call, the pending queue inser was simply missing.

This fixes the issue.
2023-02-17 22:54:55 +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
dongjiuzhu1 9244b5a737 signal: Support sigaction:sa_user, siginfo_t:si_user with user info
When the signal sent by the sender is blocked in the target task,
if the target task has an action registered with sa_flags SA_KENELHAND,
it will directly respond to the action in the context of the sender.
When the action is executed, it will have the parameters set by the
target task with sigaction:sa_user.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-12-28 23:05:58 +08:00
dongjiuzhu1 3927d878e4 signal/nxsig_pengingset: move nxsig_pendingset to common header
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-12-28 23:05:58 +08:00
Petro Karashchenko 5b4e12774c sched: remove unnecessary type cast
fix code style issues

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-12-15 09:44:32 +08:00
zhangyuan21 d8051ba979 nuttx/sched: merge up_block_task and up_unblock_task 2022-11-22 22:59:08 +08:00
zhangyuan21 08f7152d9f nuttx/sched: remove nxsched_remove_readytorun from up_block_task
It takes about 10 cycles to obtain the task list according to the task
status. In most cases, we know the task status, so we can directly
add the task from the specified task list to reduce time consuming.
2022-11-22 15:29:00 +09:00
zhangyuan21 e54b602208 nuttx/sched: remove nxsched_remove_blocked from up_unblock_task
It takes about 10 cycles to obtain the task list according to the task
status. In most cases, we know the task status, so we can directly
delete the task from the specified task list to reduce time consuming.
2022-11-22 15:29:00 +09:00
zhangyuan21 f27065cb9e sched/mqueue: make mqueue and mqueue sysv can disable separately 2022-11-16 20:03:40 +08:00
Petro Karashchenko 1a06ea4356 sched/signal: fix error handling in sigtimedwait()
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-11-13 09:11:54 +08:00
Petro Karashchenko 12646cc142 sched/signal: fix typo in comment
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-11-13 09:11:54 +08:00
ligd d4ba93067e sched: remove sched_continue, merge code
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-11-04 08:51:02 +01:00
zhangyuan21 18266c1012 nuttx/sched: use pid to check idle task
Pid is more appropriate than the flink pointer to determine idle task,
when we want to use other data structure to optimize the task list.
2022-10-31 17:53:08 +09:00
chao an 205c8934a3 sched/msgq: add support of System V message queue
https://man.openbsd.org/msgget.2

Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-22 12:58:11 +08:00
Xiang Xiao 40ef5bc6db libc: Move queue.h from include to include/nuttx
to avoid the conflict with libuv's queue.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-26 08:04:58 +02:00
ligd 3b04450808 sched: fix corner case wd_cancel assert crash
There one ways can caused this:
mq_timedreceive
   TIMER IRQ do wd_timer -> wd_func1 mq_send
                         -> wd_func2 nxmq_rcvtimeout -> crash

Resolve:
Stop the watchdog when mq_send

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-07 10:50:28 +08:00
Xiang Xiao 1b04bfae20 sched: Remove the unnecessary weak_function
because not all compiler support the weak attribute, and
many features are either always used or guarded by config.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-30 09:42:24 +02:00
Jiuzhu Dong 37ef22b106 sigact: get free sigact from freelist always successful
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-04-01 13:38:29 +08:00
ligd 0c1f63625a signal: Don't do schedule_sigaction when there is no action
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-03-30 10:53:14 +09:00
Huang Qi c0a0de97ce Revert "libc: Call pthread_exit in user-space by up_pthread_exit"
This reverts commit f4a0b7aedd.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-02-09 21:21:43 +08:00
Huang Qi 6814b1416f Revert "pthread: Avoid recursive pthread_exit call"
This reverts commit a2941532bd.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-02-09 21:21:43 +08:00
Xiang Xiao ef1abbbea0 Fix signal/sig_default.c:195:21: error: unused variable 'rtcb'
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-07 12:04:03 +08:00
Zeng Zhaoxiu fb43fd73ed signal: signal handler may cause task's state error
For example, task is blocked by nxsem_wait(sem1), use nxsem_wait(sem2)
in signal handler, and take sem2 successfully, after exit from signal
handler to task, nxsem_wait(sem1) returns OK, but the correct result
should be -EINTR.

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
2022-01-05 21:36:44 +09:00
Masayuki Ishikawa 83edd2fbba sched: signal: Introduce a private spinlock in sig_action.c
Summary:
- This commit introduces a private spinlock in sig_action.c

Impact:
- None

Testing:
- Tested with spresense:wifi_smp and spresense:wifi

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-12-09 00:13:31 -06:00