Changeset 8798372 in rtems


Ignore:
Timestamp:
Sep 10, 2019, 5:53:31 PM (6 weeks ago)
Author:
Joel Sherrill <joel@…>
Branches:
master
Children:
de6348a
Parents:
33ed412
git-author:
Joel Sherrill <joel@…> (09/10/19 17:53:31)
git-committer:
Joel Sherrill <joel@…> (09/24/19 21:27:57)
Message:

Correct initial POSIX signals mask

+ Modify POSIX thread create extension to ensure expected

initial signal mask is provided to system threads, initial
tasks and threads, and inheritied by tasks and threads.

+ Adds psxsignal07 to verify functionality when using a POSIX

Initialization thread and POSIX threads.

+ Adds psxsignal08 to verify functionality when using a Classic API

Initialization task and Classic API tasks.

Closes #3794.

Files:
8 added
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/src/pthreadcreate.c

    r33ed412 r8798372  
    8787  Priority_Control                    core_low_prio;
    8888  POSIX_API_Control                  *api;
    89   const POSIX_API_Control            *executing_api;
    9089#endif
    9190
     
    261260   */
    262261  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    263   executing_api = executing->API_Extensions[ THREAD_API_POSIX ];
    264 
    265   api->signals_unblocked = executing_api->signals_unblocked;
    266262
    267263  _Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );
     
    377373
    378374static bool _POSIX_Threads_Create_extension(
    379   Thread_Control *executing RTEMS_UNUSED,
     375  Thread_Control *executing,
    380376  Thread_Control *created
    381377)
     
    390386  _Priority_Node_set_inactive( &api->Sporadic.Low_priority );
    391387
     388#if defined(RTEMS_POSIX_API)
     389  /*
     390   * There are some subtle rules which need to be followed for
     391   * the value of the created thread's signal mask. Because signals
     392   * are part of C99 and enhanced by POSIX, both Classic API tasks
     393   * and POSIX threads have to have them enabled.
     394   *
     395   * + Internal system threads should have no signals enabled. They
     396   *   have no business executing user signal handlers -- especially IDLE.
     397   * + The initial signal mask for other threads needs to follow the
     398   *   implication of a pure C99 environment which only has the methods
     399   *   raise() and signal(). This implies that all signals are unmasked
     400   *   until the thread explicitly uses a POSIX methods to block some.
     401   *   This applies to both Classic tasks and POSIX threads created
     402   *   as initalization tasks/threads (e.g. before the system is up).
     403   * + After the initial threads are created, the signal mask should
     404   *   be inherited from the creator.
     405   *
     406   * NOTE: The default signal mask does not matter for any application
     407   *       that does not use POSIX signals.
     408   */
     409  if ( _Objects_Get_API(created->Object.id) == OBJECTS_INTERNAL_API ) {
     410      /*
     411       * Ensure internal (especially IDLE) is handled first.
     412       *
     413       * Block signals for all internal threads -- especially IDLE.
     414       */
     415      api->signals_unblocked = 0;
     416  } else if ( _Objects_Get_API(executing->Object.id) == OBJECTS_INTERNAL_API ) {
     417      /*
     418       * Threads being created while an internal thread is executing
     419       * should only happen for the initialization threads/tasks.
     420       *
     421       * Default state (signals unblocked) for all Initialization tasks
     422       * and POSIX threads. We should not inherit from IDLE which is
     423       * what appears to be executing during initialization.
     424       */
     425      api->signals_unblocked = SIGNAL_ALL_MASK;
     426  } else {
     427    const POSIX_API_Control            *executing_api;
     428    /*
     429     * RTEMS is running so follow the POSIX rules to inherit the signal mask.
     430     */
     431    executing_api = executing->API_Extensions[ THREAD_API_POSIX ];
     432    api->signals_unblocked = executing_api->signals_unblocked;
     433  }
     434#endif
    392435  return true;
    393436}
  • testsuites/psxtests/Makefile.am

    r33ed412 r8798372  
    878878psxsignal06_SOURCES = psxsignal06/init.c
    879879psxsignal06_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxsignal06) \
     880        $(support_includes) -I$(top_srcdir)/include
     881endif
     882endif
     883
     884if HAS_POSIX
     885if TEST_psxsignal07
     886psx_tests += psxsignal07
     887psx_screens += psxsignal07/psxsignal07.scn
     888psx_docs += psxsignal07/psxsignal07.doc
     889psxsignal07_SOURCES = psxsignal07/main.c psxsignal07/rtems_config.c
     890psxsignal07_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxsignal07) \
     891        $(support_includes) -I$(top_srcdir)/include
     892endif
     893endif
     894
     895if HAS_POSIX
     896if TEST_psxsignal08
     897psx_tests += psxsignal08
     898psx_screens += psxsignal08/psxsignal08.scn
     899psx_docs += psxsignal08/psxsignal08.doc
     900psxsignal08_SOURCES = psxsignal08/main.c psxsignal08/rtems_config.c
     901psxsignal08_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxsignal08) \
    880902        $(support_includes) -I$(top_srcdir)/include
    881903endif
  • testsuites/psxtests/configure.ac

    r33ed412 r8798372  
    136136RTEMS_TEST_CHECK([psxsignal05])
    137137RTEMS_TEST_CHECK([psxsignal06])
     138RTEMS_TEST_CHECK([psxsignal07])
     139RTEMS_TEST_CHECK([psxsignal08])
    138140RTEMS_TEST_CHECK([psxspin01])
    139141RTEMS_TEST_CHECK([psxstack01])
  • testsuites/psxtests/psxsignal01/init.c

    r33ed412 r8798372  
    3737volatile int Signal_count;
    3838
     39static void block_all_signals(void)
     40{
     41  int               sc;
     42  sigset_t          mask;
     43
     44  sc = sigfillset( &mask );
     45  rtems_test_assert( !sc );
     46
     47  sc = pthread_sigmask( SIG_BLOCK, &mask, NULL );
     48  rtems_test_assert( !sc );
     49}
     50
    3951void Handler_1(
    4052  int signo
     
    109121  TEST_BEGIN();
    110122
     123  block_all_signals();
     124
    111125  /* set the time of day, and print our buffer in multiple ways */
    112126
  • testsuites/psxtests/psxsignal02/init.c

    r33ed412 r8798372  
    2828volatile bool      Signal_occurred;
    2929volatile pthread_t Signal_thread;
     30
     31static void block_all_signals(void)
     32{
     33  int               sc;
     34  sigset_t          mask;
     35
     36  sc = sigfillset( &mask );
     37  rtems_test_assert( !sc );
     38
     39  sc = pthread_sigmask( SIG_BLOCK, &mask, NULL );
     40  rtems_test_assert( !sc );
     41}
    3042
    3143void Signal_handler(
     
    141153  Signal_occurred = false;
    142154
     155  block_all_signals();
     156
    143157  act.sa_handler = Signal_handler;
    144158  act.sa_flags   = 0;
  • testsuites/psxtests/psxsignal03/init.c

    r33ed412 r8798372  
    6464volatile bool      Signal_occurred;
    6565volatile pthread_t Signal_thread;
     66
     67static void block_all_signals(void)
     68{
     69  int               sc;
     70  sigset_t          mask;
     71
     72  sc = sigfillset( &mask );
     73  rtems_test_assert( !sc );
     74
     75  sc = pthread_sigmask( SIG_BLOCK, &mask, NULL );
     76  rtems_test_assert( !sc );
     77}
    6678
    6779void Signal_handler(
     
    167179  puts( "Init - Variation is: " TEST_STRING );
    168180
     181  block_all_signals();
     182
    169183  Signal_occurred = false;
    170184
Note: See TracChangeset for help on using the changeset viewer.