jingfei195887 opened a new pull request, #22443:
URL: https://github.com/apache/nuttx/pull/22443

   ## Summary
   
   When a driver blocks during poll setup, ppoll can deliver a newly unblocked
   signal before entering its semaphore wait. The signal handler runs, but
   ppoll then waits until timeout instead of returning EINTR.
   
   Move the shared polling implementation into nx_poll and install ppoll's
   temporary signal mask after driver setup. Keep the mask change, pending
   signal check and semaphore wait in one critical section. Restore the mask
   through the existing wait-mask helper, including its deferred signal
   dispatch handling in protected and kernel builds.
   
   ## Impact
   
   - Functionality: YES, close the signal-consumption window during ppoll setup.
   - Internal API: YES, add nx_poll with an optional signal mask and negative
     errno returns. It remains a cancellation point. Public poll/ppoll
     signatures, driver callbacks and pollfd layout do not change.
   - Existing stack/heap poll arrays, file references and cancellation cleanup
     remain in place. Ordinary poll passes no mask. ppoll with a NULL mask
     passes the current mask to retain the pending-signal check.
   - Argument/allocation errors are checked before installing a temporary mask.
     Their precedence over a simultaneously pending signal can therefore differ
     from the previous ppoll implementation.
   - Configuration, build process, hardware, drivers and user migration: NO
     changes. The internal declaration documents the new helper.
   - No dependency on another open PR.
   
   ## Testing
   
   I confirm that changes are verified on the local setup and work as intended.
   
   Host: Linux x86_64, GCC 13.1.0. Serial builds with two CPUs.
   Base `3a1dbb62655edbd4fc556cb33df4325abc21ddc7`; head 
`914008cd268f5f22b58cfeeee1fb01bf6afb867c`.
   
   - Identical `sim:nsh` configuration and standalone test: **254 checks,
     20 failures before; 254 checks, zero failures after**.
   - The main thread blocks SIGUSR1 and ppoll temporarily unblocks it. A test
     driver uses semaphore handshakes to hold poll setup until a sender has
     delivered SIGUSR1. On the baseline, each handler runs once but ppoll
     returns timeout. With this change, each call returns EINTR. There is no
     fixed sleep used to create this window. Ten iterations each cover the
     stack array (one descriptor) and heap array (six descriptors).
   - Controls cover signals at setup completion with infinite waits, a pending
     signal with no descriptors, zero/positive/infinite timeouts, NULL mask,
     immediately ready descriptors, pending signal plus ready descriptor,
     setup failure, negative/invalid descriptors, NULL descriptor array, mask
     restoration, balanced teardown, and ordinary poll.
   - Cancellation points and four TLS cleanup slots are enabled. Cancellation
     of a heap-array ppoll returns PTHREAD_CANCELED, tears down once, and
     releases the held file reference. Driver removal and semaphore cleanup
     succeed. An initial run with cancellation points disabled and zero cleanup
     slots failed these cleanup checks on both baseline and branch; that
     configuration provides no TLS cleanup callbacks. Those failures are
     retained locally and are not claimed fixed by this PR.
   - The invalid-descriptor control uses an untagged out-of-range value. The
     initial literal 10000 was interpreted as a stale tagged handle by FDCHECK
     and deliberately panicked; that test setup error was corrected before
     rerunning the baseline and both final configurations.
   - A 64 KiB independent FS heap, FDCHECK and three descriptors per block:
     **254 checks, zero failures**.
   - Small `sim:nsh` build with DEFAULT_SMALL and no local regression app:
     text/data/bss changes are **+208/+0/+0 bytes**.
   - Protected `qemu-armv7r:pnsh` and kernel `qemu-armv8a:knsh` builds include
     nx_poll and ppoll. Make/CMake, OSTest, full-file/commit checkpatch and
     tested-HEAD verification pass.
   
   No real hardware, protected/kernel runtime or SMP was tested. The controlled
   test demonstrates the setup window; it is not an exhaustive concurrency
   stress test. Functional builds retain the existing readline_common.c
   maybe-uninitialized warning.
   
   Testing logs before change:
   
   <details>
   <summary>Baseline</summary>
   
   ```text
   rev 3a1dbb62655 fcntl: give O_RSYNC its own flag bit build rc=0
   run rc=0 
log=/home/mi/test/nuttx_apache/fs-upstream/pr-ppoll-setup-mask/baseline-final/run.log
   nsh> ppollsetupcheck
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=0 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=0 heap=1 ret=0 errno=0 handled=1 setup=1 teardown=1
   FAIL signal interrupts ppoll errno=0
   SIGNAL wait=1 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=1 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   PPOLLSETUP RESULT checks=254 failures=20
   nsh> echo PPOLLSETUP_DONE
   PPOLLSETUP_DONE
   nsh> poweroff
   ```
   
   </details>
   
   Testing logs after change:
   
   <details>
   <summary>branch-final</summary>
   
   ```text
   rev 914008cd268 sched/fs: move ppoll mask handling into nx_poll build rc=0
   run rc=0 
log=/home/mi/test/nuttx_apache/fs-upstream/pr-ppoll-setup-mask/branch-final/run.log
   nsh> ppollsetupcheck
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=1 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=1 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   PPOLLSETUP RESULT checks=254 failures=0
   nsh> echo PPOLLSETUP_DONE
   PPOLLSETUP_DONE
   nsh> poweroff
   ```
   
   </details>
   
   <details>
   <summary>branch-private</summary>
   
   ```text
   rev 914008cd268 sched/fs: move ppoll mask handling into nx_poll build rc=0
   run rc=0 
log=/home/mi/test/nuttx_apache/fs-upstream/pr-ppoll-setup-mask/branch-private/run.log
   nsh> ppollsetupcheck
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=0 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=1 heap=0 ret=-1 errno=4 handled=1 setup=1 teardown=1
   SIGNAL wait=1 heap=1 ret=-1 errno=4 handled=1 setup=1 teardown=1
   PPOLLSETUP RESULT checks=254 failures=0
   nsh> echo PPOLLSETUP_DONE
   PPOLLSETUP_DONE
   nsh> poweroff
   ```
   
   </details>
   
   <details>
   <summary>Final gate</summary>
   
   ```text
   target   : nuttx
   branch   : fs/ppoll-setup-mask
   head     : 914008cd268f5f22b58cfeeee1fb01bf6afb867c
   subject  : sched/fs: move ppoll mask handling into nx_poll
   commits  : 1
   base     : 3a1dbb6265 (merge-base with upstream/master)
   behind   : 0 commits of upstream/master
   nuttx    : 914008cd26
   apps     : a1b03f8926
   options  : CONFIG_FS_HEAPSIZE=65536 CONFIG_FDCHECK 
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=3 CONFIG_DEBUG_ASSERTIONS 
CONFIG_DEBUG_FULLOPT CONFIG_COVERAGE_NONE CONFIG_CANCELLATION_POINTS 
CONFIG_TLS_NCLEANUP=4
   host     : Linux x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
   checkpatch: rc=0
   signer   : jingfei <[email protected]>
   commits missing your Signed-off-by: 0
   make build: rc=0
   warnings in changed files: 0
   ostest: Exiting with status 0
   cmake reconfigure: rc=0
   cmake build: rc=0
   worktree tracked changes after: 0
   RESULT: PASS
   ```
   
   </details>
   
   <details>
   <summary>size-baseline</summary>
   
   ```text
      text         data     bss     dec     hex filename
    550829         2800   12896  566525   8a4fd nuttx
   ```
   
   </details>
   
   <details>
   <summary>size-branch</summary>
   
   ```text
      text         data     bss     dec     hex filename
    551037         2800   12896  566733   8a5cd nuttx
   ```
   
   </details>
   
   <details>
   <summary>protected</summary>
   
   ```text
   qemu-armv7r:pnsh build PASS
   arm-none-eabi-gcc (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.1 
20231009
   Copyright (C) 2023 Free Software Foundation, Inc.
   This is free software; see the source for copying conditions.  There is NO
   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   
   000132f0 T nx_poll
   00021bac T ppoll
   ```
   
   </details>
   
   <details>
   <summary>kernel</summary>
   
   ```text
   qemu-armv8a:knsh build PASS
   aarch64-none-elf-gcc (GCC) 13.4.0
   Copyright (C) 2023 Free Software Foundation, Inc.
   This is free software; see the source for copying conditions.  There is NO
   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   
   0000000040287e4c T nx_poll
   00000000402ad6b0 T ppoll
   ```
   
   </details>
   
   Reproducer: place these files in apps/examples/ppollsetupcheck, configure
   sim:nsh, enable EXAMPLES_PPOLLSETUPCHECK, DEBUG_ASSERTIONS and
   CANCELLATION_POINTS, set TLS_NCLEANUP=4, disable coverage, build and run
   ppollsetupcheck. The test registers a controlled driver and inspects internal
   file references, so its standalone source is attached here.
   
   <details>
   <summary>Regression app: ppollsetupcheck_main.c</summary>
   
   ```c
   /****************************************************************************
    * apps/examples/ppollsetupcheck/ppollsetupcheck_main.c
    *
    * SPDX-License-Identifier: Apache-2.0
    
****************************************************************************/
   
   /****************************************************************************
    * Included Files
    
****************************************************************************/
   
   #include <nuttx/config.h>
   
   #include <errno.h>
   #include <fcntl.h>
   #include <poll.h>
   #include <pthread.h>
   #include <signal.h>
   #include <stdbool.h>
   #include <stdio.h>
   #include <string.h>
   #include <unistd.h>
   
   #include <nuttx/fs/fs.h>
   #include <nuttx/semaphore.h>
   
   /****************************************************************************
    * Pre-processor Definitions
    
****************************************************************************/
   
   #define DEVICE "/dev/ppollsetupcheck"
   #define QUIET 0
   #define SIGNAL_SETUP 1
   #define READY 2
   #define ERROR_SETUP 3
   #define SIGNAL_WAIT 4
   
   /****************************************************************************
    * Private Data
    
****************************************************************************/
   
   static unsigned int g_checks;
   static unsigned int g_failures;
   static volatile sig_atomic_t g_handled;
   static sem_t g_entered;
   static sem_t g_release;
   static pthread_t g_waiter;
   static int g_sendret;
   static int g_mode;
   static int g_setups;
   static int g_teardowns;
   
   /****************************************************************************
    * Private Functions
    
****************************************************************************/
   
   static bool check(bool ok, FAR const char *label)
   {
     g_checks++;
     if (!ok)
       {
         g_failures++;
         printf("FAIL %s errno=%d\n", label, errno);
       }
   
     return ok;
   }
   
   static void handler(int signo)
   {
     g_handled++;
   }
   
   static FAR void *sender(FAR void *arg)
   {
     g_sendret = nxsem_wait_uninterruptible(&g_entered);
     if (g_sendret == 0)
       {
         g_sendret = pthread_kill(g_waiter, SIGUSR1);
         if (g_mode == SIGNAL_SETUP)
           {
             nxsem_post(&g_release);
           }
       }
   
     return NULL;
   }
   
   static ssize_t device_read(FAR struct file *filep, FAR char *buffer,
                              size_t length)
   {
     return -EAGAIN;
   }
   
   static int device_poll(FAR struct file *filep, FAR struct pollfd_s *fds,
                          bool setup)
   {
     int ret;
   
     if (!setup)
       {
         g_teardowns++;
         fds->priv = NULL;
         return 0;
       }
   
     g_setups++;
     if (g_mode == ERROR_SETUP)
       {
         return -EIO;
       }
   
     if (g_mode == SIGNAL_SETUP)
       {
         nxsem_post(&g_entered);
         ret = nxsem_wait_uninterruptible(&g_release);
         if (ret < 0)
           {
             return ret;
           }
       }
   
     fds->priv = &g_mode;
     if (g_mode == SIGNAL_WAIT)
       {
         nxsem_post(&g_entered);
       }
   
     if (g_mode == READY)
       {
         poll_notify(&fds, 1, POLLIN);
       }
   
     return 0;
   }
   
   static const struct file_operations g_operations =
   {
     .read = device_read,
     .poll = device_poll
   };
   
   static void check_mask(void)
   {
     sigset_t current;
   
     check(sigprocmask(SIG_SETMASK, NULL, &current) == 0, "read mask");
     check(sigismember(&current, SIGUSR1) == 1, "original mask restored");
   }
   
   static void setup_signal(int fd, FAR const sigset_t *mask, bool heap,
                            bool wait)
   {
     struct pollfd fds[6];
     struct timespec timeout =
     {
       0, 100000000
     };
   
     pthread_t thread;
     int ret;
     int saved;
     int i;
   
     for (i = 0; i < 6; i++)
       {
         fds[i].fd = i == 0 ? fd : -1;
         fds[i].events = POLLIN;
         fds[i].revents = 0;
       }
   
     g_mode = wait ? SIGNAL_WAIT : SIGNAL_SETUP;
     g_handled = 0;
     g_setups = 0;
     g_teardowns = 0;
     g_sendret = -1;
     if (!check(pthread_create(&thread, NULL, sender, NULL) == 0,
                "create synchronized sender"))
       {
         return;
       }
   
     errno = 0;
     ret = ppoll(fds, heap ? 6 : 1, wait ? NULL : &timeout, mask);
     saved = errno;
     check(pthread_join(thread, NULL) == 0, "join synchronized sender");
     printf("SIGNAL wait=%d heap=%d ret=%d errno=%d handled=%d "
            "setup=%d teardown=%d\n", wait, heap, ret, saved, g_handled,
            g_setups, g_teardowns);
     check(ret == -1 && saved == EINTR, "signal interrupts ppoll");
     check(g_sendret == 0, "sender delivered signal");
     check(g_handled == 1, "handler ran exactly once");
     check(g_setups == 1 && g_teardowns == 1, "one setup and teardown");
     check(fds[0].revents == 0, "no spurious ready events");
     check_mask();
   }
   
   static FAR void *cancel_waiter(FAR void *arg)
   {
     struct pollfd fds[6];
     sigset_t mask;
     int fd = *(FAR int *)arg;
     int i;
   
     sigprocmask(SIG_SETMASK, NULL, &mask);
     sigdelset(&mask, SIGUSR1);
     for (i = 0; i < 6; i++)
       {
         fds[i].fd = i == 0 ? fd : -1;
         fds[i].events = POLLIN;
         fds[i].revents = 0;
       }
   
     ppoll(fds, 6, NULL, &mask);
     return NULL;
   }
   
   static int file_refs(int fd)
   {
     FAR struct file *filep;
     int refs = -1;
   
     if (check(file_get(fd, &filep) == 0, "get file reference"))
       {
         refs = atomic_read(&filep->f_refs);
         file_put(filep);
       }
   
     return refs;
   }
   
   static void cancel_check(int fd)
   {
     pthread_t thread;
     FAR void *result;
     int refs = file_refs(fd);
   
     g_mode = SIGNAL_WAIT;
     g_setups = 0;
     g_teardowns = 0;
     if (!check(pthread_create(&thread, NULL, cancel_waiter, &fd) == 0,
                "create canceled waiter"))
       {
         return;
       }
   
     check(nxsem_wait_uninterruptible(&g_entered) == 0,
           "wait for cancellation setup");
     check(pthread_cancel(thread) == 0, "cancel ppoll waiter");
     check(pthread_join(thread, &result) == 0, "join canceled waiter");
     check(result == PTHREAD_CANCELED, "ppoll remains a cancellation point");
     check(g_setups == 1 && g_teardowns == 1, "cancel tears down once");
     check(file_refs(fd) == refs, "cancel releases file reference");
     check_mask();
   }
   
   static void controls(int fd, FAR const sigset_t *mask)
   {
     struct timespec zero =
     {
       0, 0
     };
   
     struct timespec timeout =
     {
       0, 10000000
     };
   
     struct pollfd fds;
     int ret;
   
     g_mode = QUIET;
     g_handled = 0;
     check(pthread_kill(g_waiter, SIGUSR1) == 0, "queue pending signal");
     errno = 0;
     ret = ppoll(NULL, 0, &timeout, mask);
     check(ret == -1 && errno == EINTR && g_handled == 1,
           "pending signal interrupts empty wait");
     check_mask();
   
     fds.fd = fd;
     fds.events = POLLIN;
     check(ppoll(&fds, 1, &zero, mask) == 0, "zero timeout");
     check_mask();
     check(ppoll(&fds, 1, &timeout, mask) == 0, "positive timeout");
     check_mask();
     check(ppoll(&fds, 1, &zero, NULL) == 0, "NULL mask zero timeout");
     check_mask();
   
     g_mode = READY;
     g_setups = 0;
     g_teardowns = 0;
     check(ppoll(&fds, 1, NULL, mask) == 1 && (fds.revents & POLLIN),
           "immediate ready with infinite timeout");
     check(g_setups == 1 && g_teardowns == 1, "ready tears down once");
     check_mask();
   
     g_handled = 0;
     g_setups = 0;
     g_teardowns = 0;
     check(pthread_kill(g_waiter, SIGUSR1) == 0, "queue signal with ready fd");
     errno = 0;
     ret = ppoll(&fds, 1, &zero, mask);
     check(ret == -1 && errno == EINTR && g_handled == 1,
           "pending signal with ready fd and zero timeout");
     check(g_setups == g_teardowns, "pending ready has no double teardown");
     check_mask();
   
     g_mode = ERROR_SETUP;
     g_setups = 0;
     g_teardowns = 0;
     check(ppoll(&fds, 1, &timeout, mask) == 1 && (fds.revents & POLLERR),
           "setup failure reports POLLERR");
     check(g_setups == 1 && g_teardowns == 0, "failed setup has no teardown");
     check_mask();
   
     g_mode = QUIET;
     fds.fd = -1;
     check(ppoll(&fds, 1, &zero, mask) == 0 && fds.revents == 0,
           "negative fd ignored");
   
     /* A zero tag avoids FDCHECK interpreting this as a stale tagged handle. */
   
     fds.fd = 0x10000;
     check(ppoll(&fds, 1, &zero, mask) == 1 && (fds.revents & POLLERR),
           "invalid fd reports POLLERR");
     check_mask();
     errno = 0;
     check(ppoll(NULL, 1, &zero, mask) == -1 && errno == EFAULT,
           "NULL fd array rejected");
     check_mask();
   
     g_mode = READY;
     fds.fd = fd;
     check(poll(&fds, 1, 0) == 1 && (fds.revents & POLLIN),
           "ordinary poll ready unchanged");
     g_mode = QUIET;
     check(poll(&fds, 1, 0) == 0, "ordinary poll timeout unchanged");
   }
   
   /****************************************************************************
    * Public Functions
    
****************************************************************************/
   
   int main(int argc, FAR char *argv[])
   {
     struct sigaction action;
     struct sigaction oldaction;
     sigset_t blocked;
     sigset_t oldmask;
     sigset_t temporary;
     int fd;
     int i;
   
     memset(&action, 0, sizeof(action));
     action.sa_handler = handler;
     sigemptyset(&action.sa_mask);
     check(sigaction(SIGUSR1, &action, &oldaction) == 0, "install handler");
     sigemptyset(&blocked);
     sigaddset(&blocked, SIGUSR1);
     check(sigprocmask(SIG_BLOCK, &blocked, &oldmask) == 0, "block signal");
     temporary = oldmask;
     sigdelset(&temporary, SIGUSR1);
     g_waiter = pthread_self();
     nxsem_init(&g_entered, 0, 0);
     nxsem_init(&g_release, 0, 0);
     if (!check(register_driver(DEVICE, &g_operations, 0600, NULL) == 0,
                "register poll driver"))
       {
         return 1;
       }
   
     fd = open(DEVICE, O_RDONLY);
     if (!check(fd >= 0, "open poll driver"))
       {
         return 1;
       }
   
     for (i = 0; i < 10; i++)
       {
         setup_signal(fd, &temporary, false, false);
         setup_signal(fd, &temporary, true, false);
       }
   
     setup_signal(fd, &temporary, false, true);
     setup_signal(fd, &temporary, true, true);
     cancel_check(fd);
     controls(fd, &temporary);
     check(close(fd) == 0, "close poll driver");
     check(unregister_driver(DEVICE) == 0, "remove poll driver");
     check(nxsem_destroy(&g_entered) == 0, "destroy setup semaphore");
     check(nxsem_destroy(&g_release) == 0, "destroy release semaphore");
     check(sigprocmask(SIG_SETMASK, &oldmask, NULL) == 0, "restore entry mask");
     check(sigaction(SIGUSR1, &oldaction, NULL) == 0, "restore entry handler");
     printf("PPOLLSETUP RESULT checks=%u failures=%u\n", g_checks, g_failures);
     return g_failures != 0;
   }
   ```
   
   </details>
   
   <details>
   <summary>Regression app: Kconfig</summary>
   
   ```text
   config EXAMPLES_PPOLLSETUPCHECK
        bool "Local ppoll setup signal regression"
        default n
        depends on BUILD_FLAT && !DISABLE_PTHREAD && !DISABLE_POLL
   ```
   
   </details>
   
   <details>
   <summary>Regression app: Makefile</summary>
   
   ```text
   include $(APPDIR)/Make.defs
   PROGNAME = ppollsetupcheck
   PRIORITY = SCHED_PRIORITY_DEFAULT
   STACKSIZE = 8192
   MODULE = $(CONFIG_EXAMPLES_PPOLLSETUPCHECK)
   MAINSRC = ppollsetupcheck_main.c
   include $(APPDIR)/Application.mk
   ```
   
   </details>
   
   <details>
   <summary>Regression app: Make.defs</summary>
   
   ```text
   ifeq ($(CONFIG_EXAMPLES_PPOLLSETUPCHECK),y)
   CONFIGURED_APPS += $(APPDIR)/examples/ppollsetupcheck
   endif
   ```
   
   </details>
   
   ## PR verification Self-Check
   
   - [x] This PR introduces only one functional change.
   - [x] I have updated all required description fields above.
   - [x] My PR follows the contributing guidelines for scope, coding style and 
testing.
   - [ ] My PR is still work in progress (not ready for review).
   - [x] My PR is ready for review and can be safely merged into the codebase.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] sched/fs: move ppoll mas... jingfei195887 (via GitHub) via commits

Reply via email to