From patchwork Thu Aug 15 11:59:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 34114 Received: (qmail 17157 invoked by alias); 15 Aug 2019 11:59:53 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 17148 invoked by uid 89); 15 Aug 2019 11:59:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com From: Florian Weimer To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v2 1/2] Refactor sigcontextinfo.h References: <20190801181534.8802-1-adhemerval.zanella@linaro.org> Date: Thu, 15 Aug 2019 13:59:48 +0200 In-Reply-To: <20190801181534.8802-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Thu, 1 Aug 2019 15:15:33 -0300") Message-ID: <87d0h67i6j.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 I did this: -#define GET_PC(ctx) ((intptr_t) (((ucontext_t *) \ +#define GET_PC(ctx) (1 + (intptr_t) (((ucontext_t *) \ (ctx))->uc_mcontext.gregs[REG_RIP])) And none of the existing x86-64 tests failed. 8-( So I strongly urge you to add a test like the one below. I can commit it separately after your patch. I still need to verify that it builds on all architectures. Thanks, Florian diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 1ab6bcbfc8..df960aa7b4 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -55,7 +55,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \ tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \ tst-tgkill -tests-internal += tst-ofdlocks-compat +tests-internal += tst-ofdlocks-compat tst-sigcontextinfo-get_pc # Generate the list of SYS_* macros for the system calls (__NR_* # macros). The file syscall-names.list contains all possible system diff --git a/sysdeps/unix/sysv/linux/tst-sigcontextinfo-get_pc.c b/sysdeps/unix/sysv/linux/tst-sigcontextinfo-get_pc.c new file mode 100644 index 0000000000..f16b30250e --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-sigcontextinfo-get_pc.c @@ -0,0 +1,84 @@ +/* Test that the GET_PC macro is consistent with the unwinder. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see . */ + +/* This test searches for the value of the GET_PC macro in the + addresses obtained from the backtrace function. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* This file defines macros to access the content of the sigcontext element + passed up by the signal handler. */ +#include + +#ifdef SA_SIGINFO +# define SIGCONTEXT siginfo_t *info, void * +#endif + +static bool handler_called; + +static void +handler (int signal, SIGCONTEXT ctx) +{ + TEST_COMPARE (signal, SIGUSR1); + + uintptr_t pc = GET_PC (ctx); + printf ("info: address in signal handler: 0x%" PRIxPTR "\n", pc); + + void *callstack[10]; + int callstack_count = backtrace (callstack, array_length (callstack)); + TEST_VERIFY_EXIT (callstack_count > 0); + TEST_VERIFY_EXIT (callstack_count <= array_length (callstack)); + bool found = false; + for (int i = 0; i < callstack_count; ++i) + { + const char *marker; + if ((uintptr_t) callstack[i] == pc) + { + found = true; + marker = " *"; + } + else + marker = ""; + printf ("info: call stack entry %d: 0x%" PRIxPTR "%s\n", + i, (uintptr_t) callstack[i], marker); + } + TEST_VERIFY (found); + handler_called = true; +} + +static int +do_test (void) +{ + struct sigaction sa = + { + .sa_sigaction = &handler, + }; + xsigaction (SIGUSR1, &sa, NULL); + raise (SIGUSR1); + TEST_VERIFY (handler_called); + return 0; +} + +#include