(root)/
strace-6.5/
tests-m32/
get_sigset_size.c
       1  /*
       2   * Find out the size of kernel's sigset_t.
       3   *
       4   * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2017-2021 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include <signal.h>
      13  #include <unistd.h>
      14  #include "scno.h"
      15  
      16  /*
      17   * If the sigset size specified to rt_sigprocmask is not equal to the size
      18   * of kernel's sigset_t, the kernel does not look at anything else and fails
      19   * with EINVAL.
      20   *
      21   * Otherwise, if both pointers specified to rt_sigprocmask are NULL,
      22   * the kernel just returns 0.
      23   *
      24   * This vaguely documented kernel feature can be used to probe
      25   * the kernel and find out the size of kernel's sigset_t.
      26   */
      27  
      28  unsigned int
      29  get_sigset_size(void)
      30  {
      31  	static unsigned int set_size;
      32  
      33  	if (!set_size) {
      34  		static const unsigned int big_size = 1024 / 8;
      35  
      36  		for (set_size = big_size; set_size; set_size >>= 1) {
      37  			if (!syscall(__NR_rt_sigprocmask, SIG_SETMASK,
      38  				     NULL, NULL, set_size))
      39  				break;
      40  		}
      41  
      42  		if (!set_size)
      43  			perror_msg_and_fail("rt_sigprocmask");
      44  	}
      45  
      46  	return set_size;
      47  }