-
Notifications
You must be signed in to change notification settings - Fork 8k
doc: services: logging: add limitation when using logging thread name #96640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
doc: services: logging: add limitation when using logging thread name #96640
Conversation
Add a note about a limitation when using deferred logging + thread name together with dynamically allocated struct k_thread. This limitation has been raised in issue zephyrproject-rtos#95077. Signed-off-by: Loic Domaigne <[email protected]>
2fba872
to
30b5cd6
Compare
|
Hi @dcpleung, @nordic-krch : |
:c:func:`malloc` for instance. In this case, if the thread logs some messages and then gets | ||
stopped and its ``struct k_thread`` is freed, the log system will still try to access that | ||
structure when handling the message later. This creates a use-after-free scenario. | ||
To avoid this, a solution consists of calling :c:func:`log_flush` before freeing the structure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid this, a solution consists of calling :c:func:`log_flush` before freeing the structure. | |
To avoid this, a solution consists in calling :c:func:`log_flush` before freeing the structure. |
struct k_thread *thread = malloc(sizeof(*thread)); /* struct allocated dynamically */ | ||
k_thread_create(thread, ...); | ||
k_thread_name_set(thread, "foobar2025"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k_thread_name_set(thread, "foobar2025"); | |
k_thread_name_set(thread, "foobar2025"); |
Nit but you probably shouldn't use a year here since this will have the code snippet "age" for no reason. "foo bar" should be just fine :)
k_thread_create(thread, ...); | ||
k_thread_name_set(thread, "foobar2025"); | ||
// Thread calls LOG_*(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be C style too
|
||
.. code-block:: c | ||
struct k_thread *thread = malloc(sizeof(*thread)); /* struct allocated dynamically */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be k_malloc (resp. k_free), not everyone necessarily have malloc/free available
Add a note about a limitation when using deferred logging + thread name together with dynamically allocated struct k_thread. This limitation has been raised in issue #95077.