1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 14:03:55 +01:00

1087 Commits

Author SHA1 Message Date
chrysn
79071b10f2 core/doc: Thread names are expected to be long-lived 2025-05-19 15:55:05 +02:00
Marian Buschsieweke
0b01fa0025
core/compiler_hints: Add NONSTRING attribute
This adds the `NONSTRING` attribute that is defined as either
`__attribute__((nonstring))` or as empty, depending on whether the
toolchain understands the `nonstring` attribute.

This allows declaring char arrays as not being a zero-terminated
c-string without cluttering the code with preprocessor conditinational
to ensure backward compatibility with compilers that do not support
`-Wunterminated-string-initialization` yet.
2025-04-27 22:49:22 +02:00
Marian Buschsieweke
914429c5f5
core/lib/include/compiler_hints.h: fix style
This adds indent to make reading preprocessor conditionals easier, as
is recommended by our coding convention.
2025-04-27 22:49:22 +02:00
Marian Buschsieweke
0069a6bf9a
build system: enable support for static analysis
Modules can now add the following snipped to their `Makefile`:

    MODULE_SUPPORTS_STATIC_ANALYSIS := 1

When the application is then build with `make STATIC_ANALYSIS=1`, all
modules that opted in to static analysis get build with static analysis.
2025-04-18 09:36:31 +02:00
Marian Buschsieweke
16c24a43e9
Merge pull request #21414 from maribu/core/thread/thread_msg_has_queue
core/thread: fix thread_has_msg_queue()
2025-04-17 20:41:30 +00:00
Marian Buschsieweke
87ff0d550d
core/thread_get_unchecked(): fix doc
This fixes the API doc for thread_get_unchecked()
2025-04-17 18:49:49 +02:00
Marian Buschsieweke
2a65b9cfa5
core/thread: fix thread_has_msg_queue()
This fixes compilation with `-fanalyzer`. We use `assume()` to signal
GCC that `thread` must not be null in `NDEBUG` mode, and `assert()` it
in with enabled assertions.

This also drops the `volatile` qualifier from the function argument and
changes the return value to `bool`.
2025-04-17 18:47:39 +02:00
Marian Buschsieweke
d36465d532
core/msg: handle error in msg_queue_capacity()
Rather than using an `assert()` on `thread_get()`, check for the thread
to exist and return a capacity of `0` if it does not.

This fixes compilation with `-fanalyzer` with `NDEBUG` defined, is more
consistent with other core APIs, and makes the API usable for threads
with a dynamic life cycle.

Co-authored-by: crasbe <crasbe@gmail.com>
2025-04-17 07:55:13 +02:00
Marian Buschsieweke
55f9d1c930
Merge pull request #21405 from JerelJr/fix-core-headers
core: replace header guards with #pragma once
2025-04-16 05:30:21 +00:00
JerelJr
04dafd5618 core: replace header guards with #pragma once
core/lib/include/ringbuffer.h: removed trailing newline

core/lib/include/irq.h: restored header guard for irq.h to resolve build errors

core/lib/include/irq.h: added trailing newline to irq.h
2025-04-15 14:55:38 -04:00
Marian Buschsieweke
a605d05eca
Merge pull request #21400 from maribu/core/msg-avail
core/msg: fix `msg_avail_thread()` and `msg_avail()`
2025-04-15 13:20:26 +00:00
Marian Buschsieweke
caa5561667
core/msg: fix msg_avail_thread() and msg_avail()
This now ensures race-free access to the CIB tracking the number
of messages queued in the ringbuffer for a given thread.

In addition, `msg_avail_thread()` now checks if the provided pid refers
to a thread that is currently existing.

Co-authored-by: Mikolai Gütschow <mikolai.guetschow@tu-dresden.de>
2025-04-15 15:07:11 +02:00
Marian Buschsieweke
dcd3ee74ae
core/cib: Add a prominent warning about thread safety
Users of CIB may easily be mislead to believing that it is generally
thread safe, or at least thread safe as long as there is a single
consumer and producer. Neither is the case, which now is clearly
communicated in the API doc.

Co-authored-by: mguetschow <mikolai.guetschow@tu-dresden.de>
2025-04-14 14:29:56 +02:00
Marian Buschsieweke
1ff982a664
tree wide: various doc fixes
This fixes a batch of incorrect Doxygen comments that building with
LLVM/clang and `-Wdocumentation` uncovered.
2025-04-04 11:44:53 +02:00
Marian Buschsieweke
ca781c2f12
Merge pull request #21242 from mguetschow/native-alias
boards: introduce board alias and make native default to host target
2025-04-02 09:14:12 +00:00
benpicco
85dc9be1c9
Merge pull request #20872 from benpicco/stdio_null-frontend
core: add stdio.h to replace stdout functions with stdio_null
2025-04-01 15:30:08 +00:00
Benjamin Valentin
35005c3e85 core: add stdio.h to replace stdout functions with stdio_null 2025-04-01 14:29:28 +02:00
Mikolai Gütschow
69c15e1754
boards: make BOARD=native an alias for BOARD=native32 2025-04-01 12:39:06 +02:00
Karl Fessel
1446aeab24 core/mutex: separate documentation 2025-04-01 11:30:15 +02:00
Marian Buschsieweke
785faa77f7
Merge pull request #21253 from DeJusten/2025-02.thread
core/thread: error in thread.c corrected
2025-03-14 12:26:57 +00:00
DeJusten
2eeb0f7f96
core/thread: document thread_add_to_list()
Adding the task to the linked list is graphically commented
2025-03-14 13:11:09 +01:00
DeJusten
a4ec8e1ebb
core/thread: fix thread_state_to_string()
In thread_state_to_string() it is not checked whether state is within
the valid range, so that in the event of an error an invalid memory
address is returned, which in turn leads to further invalid memory
accesses when the string is output. thread_state_to_string() is used
in particular by ps(). In the case of a corrupt thread context, which
often occurred in my case due to the stack size being too small,
thread_state_to_string() is called with an invalid status.
2025-03-14 13:11:09 +01:00
DeJusten
48f8e618ca
core/thread: fix incorrect thread status after wake up
In thread_wakeup() the status of the function to be woken up is
incorrectly set to TASK_RUNNING. Instead the task should be set
to STATUS_PENDING here, as only sched_run() is allowed to set a
task to TASK_RUNNING.
2025-03-14 11:04:16 +01:00
DeJusten
3cbde6a2ee
core/thread: thread_create(): improve error handling
Return `-EINVAL` when stack is too small in addition to warn when
`ENABLE_DEBUG` is set.
2025-03-14 11:03:58 +01:00
Marian Buschsieweke
ef2d6f8724
core/debug: extend doc about DEBUG() / LOG_DEBUG()
This adds a few lines to explain the difference between the two and
hints when to use which.

Co-authored-by: crasbe <crasbe@gmail.com>
2025-03-06 21:08:46 +01:00
Fabian Hüßler
f7045405c0 core/cib: add const to cib_peek() 2025-01-12 21:09:36 +01:00
Mikolai Gütschow
850a827c24
core/msg: re-enable IRQs before printing for highlevel_stdio
copy message queue information to stack before
2024-11-28 12:49:11 +01:00
benpicco
77c4a24bcf
Merge pull request #20938 from derMihai/mir/fix_runqueue_pop
core/sched.c: fix _runqueue_pop() removing wrong thread
2024-11-14 12:05:45 +00:00
Mihai Renea
ba71ba72a3 core/sched.c: fix _runqueue_pop() removing wrong thread 2024-11-14 11:05:40 +01:00
benpicco
d65dec6ab5
Merge pull request #20960 from maribu/build_system/xfa/fix-alignment
build_system/xfa: change API to fix alignment
2024-11-07 16:16:28 +00:00
Marian Buschsieweke
2b6f65a08a
build_system/xfa: change API to fix alignment
This changes the API of xfa from

    XFA(array_name, prio) type element_name = INITIALIZER;

to

    XFA(type, array_name, prio) element_name = INITIALIZER;

this allows forcing natural alignment of the type, fixing failing tests
on `native64`.
2024-11-07 16:30:01 +01:00
Benjamin Valentin
46ecf82e24 core/mutex: add mutex_init_locked() 2024-11-06 12:53:17 +01:00
mguetschow
a54ba26285
Merge pull request #20893 from benpicco/THREAD_CREATE_STACKTEST-cleanup
treewide: clean up remnants of THREAD_CREATE_STACKTEST
2024-10-08 09:55:52 +00:00
Benjamin Valentin
97128eef48 treewide: clean up remnants of THREAD_CREATE_STACKTEST 2024-10-07 17:31:31 +02:00
Marian Buschsieweke
1d99f4f758
core/mutex: use thread_yield_higher() in mutex_unlock()
Using `sched_switch()` in `mutex_unlock()` can result in crashes when
`mutex_unlock()` is called from IRQ context. This however is a common
pattern in RIOT to wake up a thread from IRQ. The reason for the crash
is that `sched_switch()` assumes `thread_get_active()` to always return
a non-`NULL` value. But when thread-less idle is used, no thread may be
active after the last runnable thread exited. Using
`thread_yield_higher()` instead solves the issue, as
`thread_yield_higher()` is safe to call from IRQ context without an
active thread.

This fixes https://github.com/RIOT-OS/RIOT/issues/20812
2024-10-05 22:02:28 +02:00
benpicco
41204c8b81
Merge pull request #20450 from benpicco/THREAD_CREATE_STACKTEST-delete
core/thread: always use THREAD_CREATE_STACKTEST when DEVELHELP is enabled
2024-07-29 11:52:06 +00:00
Benjamin Valentin
0fbc10fb45 core/thread: introduce THREAD_CREATE_NO_STACKTEST 2024-07-29 11:45:58 +02:00
Benjamin Valentin
312a550f1a treewide: remove THREAD_CREATE_STACKTEST from thread creation 2024-07-29 11:45:58 +02:00
Benjamin Valentin
b1d3825c27 core/thread: always use THREAD_CREATE_STACKTEST with DEVELHELP 2024-07-29 11:45:58 +02:00
Benjamin Valentin
3237ed911e core/panic: don't use LOG_ functions in panic handler 2024-07-17 16:18:19 +02:00
Marian Buschsieweke
70f5747712
core/native_shed: Fix compilation with musl
On musl, `spu_set_t` is provided by system headers, so only provide
that with glibc.
2024-06-05 21:57:43 +02:00
Marian Buschsieweke
11e273c4db
core/thread: "fix" valgrind erros in thread_measure_stack_free()
The dark magic used used in thread_measure_stack_free() is frowned upon
by valgrind. E.g. valgrind may deduce (by monitoring the stack pointer)
that a specific value was at some point allocated on the stack, but has
gone out of scope. When that value is now read again to estimate stack
usage, it does look a lot like someone passed a pointer to a stack
allocated value, and that pointer is referenced after that value has
gone out of scope.

This is "fixed" by temporarily disabling valgrind error reporting while
iterating over the stack.
2024-06-05 14:31:58 +02:00
Benjamin Valentin
02fe256a06 core/thread: don't try to align end of stack 2024-06-04 16:57:05 +02:00
Marian Buschsieweke
e93b5e4b98
core/thread: fix thread_measure_stack_free()
`thread_measure_stack_free()` previously assumed that reading past the
stack is safe. When the stack was indeed part of a thread, the
`thread_t` structure is put after the stack, increasing the odds of
this assumption to hold. However, `thread_measure_stack_free()` could
also be used on the ISR stack, which may be allocated at the end of
SRAM.

A second parameter had to be added to indicate the stack size, so that
reading past the stack can now be prevented.

This also makes valgrind happy on `native`/`native64`.
2024-05-31 19:54:10 +02:00
Mikolai Gütschow
d5d5e9f602
core/lib/assert: consistify output and cleanup documentation 2024-05-27 17:12:49 +02:00
Marian Buschsieweke
2e9ce4d6b4
Merge pull request #20633 from dylad/pr/cpu/cortexm33/add_splim_support
cpu/cortexm: add stack limit support for Cortex-M33
2024-05-06 17:05:20 +00:00
Dylan Laduranty
683d4a249d cpu/cortexm: add stack limit support for CM33
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
2024-05-06 17:14:49 +02:00
benpicco
6c154958a3
Merge pull request #20627 from benpicco/assert-zombi
core/assert: halt running thread instead of panic
2024-04-29 09:16:46 +00:00
Benjamin Valentin
731ada03e5 core/assert: halt running thread instead of panic 2024-04-28 01:43:18 +02:00
Benjamin Valentin
9e0a32e011 core/panic: make reboot on panic configurable 2024-04-26 15:44:49 +02:00