Skip to content
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

Add configRESET_TLS_BLOCK macro, adjust formatting. #652

Closed
wants to merge 3 commits into from

Conversation

paulbartell
Copy link
Contributor

Description

Add configRESET_TLS_BLOCK macro to allow using newlibc functions from Interrupt / Exception handlers.

Repro Steps

Attempt to call printf from a fault handler / interrupt.
Note that if the last task to run had not yet initialized stdio, the call may fail due to attempts to allocate heap memory.

Fix

Add a configRESET_TLS_BLOCK macro which may be called to reset the thread local storage to a particular context for use in interrupt handlers. For newlibc, this sets _impure_ptr = _global_impure_ptr.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@paulbartell paulbartell requested a review from a team as a code owner March 30, 2023 19:31
@codecov
Copy link

codecov bot commented Mar 30, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (686b6e6) 94.46% compared to head (f3afb95) 94.46%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #652   +/-   ##
=======================================
  Coverage   94.46%   94.46%           
=======================================
  Files           6        6           
  Lines        2422     2422           
  Branches      594      594           
=======================================
  Hits         2288     2288           
  Misses         85       85           
  Partials       49       49           
Flag Coverage Δ
unittests 94.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

This was linked to issues Apr 1, 2023
Closed
Closed
@paulbartell paulbartell force-pushed the add-tls-include-guards branch from e131bde to f3afb95 Compare April 25, 2023 18:32
@Mancent Mancent linked an issue May 21, 2023 that may be closed by this pull request
@jefftenney
Copy link
Contributor

If an ISR uses configRESET_TLS_BLOCK(), would there be an easy way for it to restore the TLS pointer (eg, _impure_ptr) before returning from the interrupt? That would be important if the ISR returns to the interrupted task without an OS context switch.

The ISR could do the save/restore "by hand" like this:

__interrupt__ void myISR( void )
{
    struct _reent *reSave = _impure_ptr;
    configRESET_TLS_BLOCK();   // _impure_ptr = _global_impure_ptr;

    // Body of ISR

    _impure_ptr = reSave;
}

But then that begs the question why the macro configRESET_TLS_BLOCK() exists at all since the ISR writer has to know how everything works behind the scenes anyway, including that it works only for newlib. And even if we can justify the existence of configRESET_TLS_BLOCK(), it would still be insufficient for nested interrupts, which cannot all share the one global reent struct at _global_impure_ptr. Wondering if it would be better to leave this whole concept (TLS support in interrupt handlers) up to the developer.

@paulbartell paulbartell closed this Jan 5, 2024
@paulbartell paulbartell deleted the add-tls-include-guards branch January 5, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

> - [ ] ``` H G
4 participants