(root)/
glibc-2.38/
sysdeps/
unix/
sysv/
linux/
x86/
tst-cet-property-2.c
       1  /* Test CET property note parser for [BZ #23467].
       2     Copyright (C) 2018-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <stdlib.h>
      20  #include <stdio.h>
      21  #include <string.h>
      22  #include <signal.h>
      23  #include <support/check.h>
      24  
      25  extern void bar (void);
      26  
      27  void
      28  __attribute__ ((noclone, noinline))
      29  test (void (*func_p) (void))
      30  {
      31    func_p ();
      32  }
      33  
      34  /* bar contains an IBT violation if it is called indirectly via a
      35     function pointer.  On IBT machines, it should lead to segfault
      36     unless IBT is disabled by error.  */
      37  
      38  static void
      39  sig_handler (int signo)
      40  {
      41    exit (EXIT_SUCCESS);
      42  }
      43  
      44  static int
      45  do_test (void)
      46  {
      47    char buf[4];
      48  
      49    if (scanf ("%3s", buf) != 1)
      50      FAIL_UNSUPPORTED ("IBT not supported");
      51  
      52    if (strcmp (buf, "IBT") != 0)
      53      FAIL_UNSUPPORTED ("IBT not supported");
      54  
      55    TEST_VERIFY_EXIT (signal (SIGSEGV, &sig_handler) != SIG_ERR);
      56  
      57    /* Call bar via a function pointer to force an IBT violation.  */
      58    test (bar);
      59  
      60    return EXIT_FAILURE;
      61  }
      62  
      63  #include <support/test-driver.c>