From patchwork Tue Nov 7 22:38:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 835496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-86875-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="ib9LRa5k"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yWkqP01hNz9s7C for ; Wed, 8 Nov 2017 09:38:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; q=dns; s=default; b=mqNQiLmqOkNRib96 uGOQWlBaYv7oof7vpc+84uC5urVupfdB/x9bUfpDWvFkWRj1+ExK0jhFDNFj+K7r myXMiW/9uHUzS2G5O5Wh6JW+bpveGw+Ykj95jrJzYvbjdR1OUj/IfLpBujzgqqfX T/ohTaQqSOCEm+O2Ch81XoQ2sKE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; s=default; bh=rWuj+3+eyMoTAKZUDUE3zM eCm5Y=; b=ib9LRa5kQvnoRosHmIKsQIJhL87sAoaYvJyP7nBsg+ScpWVNiU4B2u dJTyUJTr0kuM7iWFzmrsYPZqvvNxd1hnWy5KwigSH6n2dvtk2TeGScqHtIPXXhTu a9HvPST1Pr+zV/YhMTzJ7yF8f/rWU48pnwbZdzTqNByB37craagMg= Received: (qmail 12325 invoked by alias); 7 Nov 2017 22:38:27 -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 11976 invoked by uid 89); 7 Nov 2017 22:38:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-22.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy= X-HELO: mga11.intel.com X-ExtLoop1: 1 Date: Tue, 7 Nov 2017 14:38:21 -0800 From: "H.J. Lu" To: GNU C Library Subject: [PATCH 1/2] Add tst-jmp_buf.c and jmp_buf-macros.h Message-ID: <20171107223821.GA46190@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) Verify that sizes, alignments and field offsets of jmp_buf as well as sigjmp_buf are unchanged regardless how struct __jmp_buf_tag is defined. Since jmp_buf is target specific, jmp_buf-macros.h is added for each target. The new target must provides its own jmp_buf-macros.h. Tested with build-many-glibcs.py. OK for master? H.J. --- * setjmp/Makefile (tests): Add tst-jmp_buf. * setjmp/tst-jmp_buf.c: New file. * sysdeps/aarch64/jmp_buf-macros.h: Likewise. * sysdeps/alpha/jmp_buf-macros.h: Likewise. * sysdeps/arm/jmp_buf-macros.h: Likewise. * sysdeps/hppa/jmp_buf-macros.h: Likewise. * sysdeps/i386/jmp_buf-macros.h: Likewise. * sysdeps/ia64/jmp_buf-macros.h: Likewise. * sysdeps/m68k/jmp_buf-macros.h: Likewise. * sysdeps/microblaze/jmp_buf-macros.h: Likewise. * sysdeps/mips/mips32/jmp_buf-macros.h: Likewise. * sysdeps/mips/mips64/n32/jmp_buf-macros.h: Likewise. * sysdeps/mips/mips64/n64/jmp_buf-macros.h: Likewise. * sysdeps/nios2/jmp_buf-macros.h: Likewise. * sysdeps/powerpc/powerpc32/jmp_buf-macros.h: Likewise. * sysdeps/powerpc/powerpc64/jmp_buf-macros.h: Likewise. * sysdeps/s390/s390-32/jmp_buf-macros.h: Likewise. * sysdeps/s390/s390-64/jmp_buf-macros.h: Likewise. * sysdeps/sh/jmp_buf-macros.h: Likewise. * sysdeps/sparc/sparc32/jmp_buf-macros.h: Likewise. * sysdeps/sparc/sparc64/jmp_buf-macros.h: Likewise. * sysdeps/tile/tilegx/tilegx32/jmp_buf-macros.h: Likewise. * sysdeps/tile/tilegx/tilegx64/jmp_buf-macros.h: Likewise. * sysdeps/tile/tilepro/jmp_buf-macros.h: Likewise. * sysdeps/x86_64/64/jmp_buf-macros.h: Likewise. * sysdeps/x86_64/x32/jmp_buf-macros.h: Likewise. --- setjmp/Makefile | 2 +- setjmp/tst-jmp_buf.c | 60 +++++++++++++++++++++++++++ sysdeps/aarch64/jmp_buf-macros.h | 6 +++ sysdeps/alpha/jmp_buf-macros.h | 6 +++ sysdeps/arm/jmp_buf-macros.h | 6 +++ sysdeps/hppa/jmp_buf-macros.h | 6 +++ sysdeps/i386/jmp_buf-macros.h | 6 +++ sysdeps/ia64/jmp_buf-macros.h | 6 +++ sysdeps/m68k/jmp_buf-macros.h | 6 +++ sysdeps/microblaze/jmp_buf-macros.h | 6 +++ sysdeps/mips/mips32/jmp_buf-macros.h | 6 +++ sysdeps/mips/mips64/n32/jmp_buf-macros.h | 6 +++ sysdeps/mips/mips64/n64/jmp_buf-macros.h | 6 +++ sysdeps/nios2/jmp_buf-macros.h | 6 +++ sysdeps/powerpc/powerpc32/jmp_buf-macros.h | 6 +++ sysdeps/powerpc/powerpc64/jmp_buf-macros.h | 6 +++ sysdeps/s390/s390-32/jmp_buf-macros.h | 6 +++ sysdeps/s390/s390-64/jmp_buf-macros.h | 6 +++ sysdeps/sh/jmp_buf-macros.h | 6 +++ sysdeps/sparc/sparc32/jmp_buf-macros.h | 6 +++ sysdeps/sparc/sparc64/jmp_buf-macros.h | 6 +++ sysdeps/tile/tilegx/tilegx32/jmp_buf-macros.h | 6 +++ sysdeps/tile/tilegx/tilegx64/jmp_buf-macros.h | 6 +++ sysdeps/tile/tilepro/jmp_buf-macros.h | 6 +++ sysdeps/x86_64/64/jmp_buf-macros.h | 6 +++ sysdeps/x86_64/x32/jmp_buf-macros.h | 6 +++ 26 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 setjmp/tst-jmp_buf.c create mode 100644 sysdeps/aarch64/jmp_buf-macros.h create mode 100644 sysdeps/alpha/jmp_buf-macros.h create mode 100644 sysdeps/arm/jmp_buf-macros.h create mode 100644 sysdeps/hppa/jmp_buf-macros.h create mode 100644 sysdeps/i386/jmp_buf-macros.h create mode 100644 sysdeps/ia64/jmp_buf-macros.h create mode 100644 sysdeps/m68k/jmp_buf-macros.h create mode 100644 sysdeps/microblaze/jmp_buf-macros.h create mode 100644 sysdeps/mips/mips32/jmp_buf-macros.h create mode 100644 sysdeps/mips/mips64/n32/jmp_buf-macros.h create mode 100644 sysdeps/mips/mips64/n64/jmp_buf-macros.h create mode 100644 sysdeps/nios2/jmp_buf-macros.h create mode 100644 sysdeps/powerpc/powerpc32/jmp_buf-macros.h create mode 100644 sysdeps/powerpc/powerpc64/jmp_buf-macros.h create mode 100644 sysdeps/s390/s390-32/jmp_buf-macros.h create mode 100644 sysdeps/s390/s390-64/jmp_buf-macros.h create mode 100644 sysdeps/sh/jmp_buf-macros.h create mode 100644 sysdeps/sparc/sparc32/jmp_buf-macros.h create mode 100644 sysdeps/sparc/sparc64/jmp_buf-macros.h create mode 100644 sysdeps/tile/tilegx/tilegx32/jmp_buf-macros.h create mode 100644 sysdeps/tile/tilegx/tilegx64/jmp_buf-macros.h create mode 100644 sysdeps/tile/tilepro/jmp_buf-macros.h create mode 100644 sysdeps/x86_64/64/jmp_buf-macros.h create mode 100644 sysdeps/x86_64/x32/jmp_buf-macros.h diff --git a/setjmp/Makefile b/setjmp/Makefile index ca80b8ea13..857e0b8d0f 100644 --- a/setjmp/Makefile +++ b/setjmp/Makefile @@ -28,7 +28,7 @@ routines := setjmp sigjmp bsd-setjmp bsd-_setjmp \ longjmp __longjmp jmp-unwind tests := tst-setjmp jmpbug bug269-setjmp tst-setjmp-fp \ - tst-sigsetjmp tst-setjmp-static + tst-sigsetjmp tst-setjmp-static tst-jmp_buf tests-static := tst-setjmp-static diff --git a/setjmp/tst-jmp_buf.c b/setjmp/tst-jmp_buf.c new file mode 100644 index 0000000000..1b25d85876 --- /dev/null +++ b/setjmp/tst-jmp_buf.c @@ -0,0 +1,60 @@ +/* Check jmp_buf sizes, alignments and offsets. + Copyright (C) 2017 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; if not, see + . */ + +#include +#include +#include +#include + +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) + +static int +do_test (void) +{ +#define TEST_SIZE(type, size) \ + _Static_assert (sizeof (type) == size, \ + "size of " #type " != " \ + STR (size)) +#define TEST_ALIGN(type, align) \ + _Static_assert (__alignof__ (type) == align , \ + "align of " #type " != " \ + STR (align)) +#define TEST_OFFSET(type, member, offset) \ + _Static_assert (offsetof (type, member) == offset, \ + "offset of " #member " field of " #type " != " \ + STR (offset)) + + /* Check if jmp_buf have the expected sizes. */ + TEST_SIZE (jmp_buf, JMP_BUF_SIZE); + TEST_SIZE (sigjmp_buf, SIGJMP_BUF_SIZE); + + /* Check if jmp_buf have the expected alignments. */ + TEST_ALIGN (jmp_buf, JMP_BUF_ALIGN); + TEST_ALIGN (sigjmp_buf, SIGJMP_BUF_ALIGN); + + /* Check if internal fields in jmp_buf have the expected offsets. */ + TEST_OFFSET (struct __jmp_buf_tag, __mask_was_saved, + MASK_WAS_SAVED_OFFSET); + TEST_OFFSET (struct __jmp_buf_tag, __saved_mask, + SAVED_MASK_OFFSET); + + return 0; +} + +#include diff --git a/sysdeps/aarch64/jmp_buf-macros.h b/sysdeps/aarch64/jmp_buf-macros.h new file mode 100644 index 0000000000..608a7ad1f7 --- /dev/null +++ b/sysdeps/aarch64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 312 +#define SIGJMP_BUF_SIZE 312 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 176 +#define SAVED_MASK_OFFSET 184 diff --git a/sysdeps/alpha/jmp_buf-macros.h b/sysdeps/alpha/jmp_buf-macros.h new file mode 100644 index 0000000000..b595173e6f --- /dev/null +++ b/sysdeps/alpha/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 272 +#define SIGJMP_BUF_SIZE 272 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 136 +#define SAVED_MASK_OFFSET 144 diff --git a/sysdeps/arm/jmp_buf-macros.h b/sysdeps/arm/jmp_buf-macros.h new file mode 100644 index 0000000000..eb64802525 --- /dev/null +++ b/sysdeps/arm/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 392 +#define SIGJMP_BUF_SIZE 392 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 256 +#define SAVED_MASK_OFFSET 260 diff --git a/sysdeps/hppa/jmp_buf-macros.h b/sysdeps/hppa/jmp_buf-macros.h new file mode 100644 index 0000000000..6ede0d6af7 --- /dev/null +++ b/sysdeps/hppa/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 304 +#define SIGJMP_BUF_SIZE 304 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 168 +#define SAVED_MASK_OFFSET 172 diff --git a/sysdeps/i386/jmp_buf-macros.h b/sysdeps/i386/jmp_buf-macros.h new file mode 100644 index 0000000000..554bbed309 --- /dev/null +++ b/sysdeps/i386/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 156 +#define SIGJMP_BUF_SIZE 156 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 24 +#define SAVED_MASK_OFFSET 28 diff --git a/sysdeps/ia64/jmp_buf-macros.h b/sysdeps/ia64/jmp_buf-macros.h new file mode 100644 index 0000000000..41788657ec --- /dev/null +++ b/sysdeps/ia64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 704 +#define SIGJMP_BUF_SIZE 704 +#define JMP_BUF_ALIGN 16 +#define SIGJMP_BUF_ALIGN 16 +#define MASK_WAS_SAVED_OFFSET 560 +#define SAVED_MASK_OFFSET 568 diff --git a/sysdeps/m68k/jmp_buf-macros.h b/sysdeps/m68k/jmp_buf-macros.h new file mode 100644 index 0000000000..2f62ecb4b3 --- /dev/null +++ b/sysdeps/m68k/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 288 +#define SIGJMP_BUF_SIZE 288 +#define JMP_BUF_ALIGN 2 +#define SIGJMP_BUF_ALIGN 2 +#define MASK_WAS_SAVED_OFFSET 156 +#define SAVED_MASK_OFFSET 160 diff --git a/sysdeps/microblaze/jmp_buf-macros.h b/sysdeps/microblaze/jmp_buf-macros.h new file mode 100644 index 0000000000..9c435f7967 --- /dev/null +++ b/sysdeps/microblaze/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 216 +#define SIGJMP_BUF_SIZE 216 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 84 +#define SAVED_MASK_OFFSET 88 diff --git a/sysdeps/mips/mips32/jmp_buf-macros.h b/sysdeps/mips/mips32/jmp_buf-macros.h new file mode 100644 index 0000000000..d46d69ecbd --- /dev/null +++ b/sysdeps/mips/mips32/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 240 +#define SIGJMP_BUF_SIZE 240 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 104 +#define SAVED_MASK_OFFSET 108 diff --git a/sysdeps/mips/mips64/n32/jmp_buf-macros.h b/sysdeps/mips/mips64/n32/jmp_buf-macros.h new file mode 100644 index 0000000000..ed0f1232de --- /dev/null +++ b/sysdeps/mips/mips64/n32/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 288 +#define SIGJMP_BUF_SIZE 288 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 152 +#define SAVED_MASK_OFFSET 156 diff --git a/sysdeps/mips/mips64/n64/jmp_buf-macros.h b/sysdeps/mips/mips64/n64/jmp_buf-macros.h new file mode 100644 index 0000000000..38b5b0636a --- /dev/null +++ b/sysdeps/mips/mips64/n64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 304 +#define SIGJMP_BUF_SIZE 304 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 168 +#define SAVED_MASK_OFFSET 176 diff --git a/sysdeps/nios2/jmp_buf-macros.h b/sysdeps/nios2/jmp_buf-macros.h new file mode 100644 index 0000000000..1cb9cab420 --- /dev/null +++ b/sysdeps/nios2/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 172 +#define SIGJMP_BUF_SIZE 172 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 40 +#define SAVED_MASK_OFFSET 44 diff --git a/sysdeps/powerpc/powerpc32/jmp_buf-macros.h b/sysdeps/powerpc/powerpc32/jmp_buf-macros.h new file mode 100644 index 0000000000..11b0a8bb00 --- /dev/null +++ b/sysdeps/powerpc/powerpc32/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 592 +#define SIGJMP_BUF_SIZE 592 +#define JMP_BUF_ALIGN 16 +#define SIGJMP_BUF_ALIGN 16 +#define MASK_WAS_SAVED_OFFSET 448 +#define SAVED_MASK_OFFSET 452 diff --git a/sysdeps/powerpc/powerpc64/jmp_buf-macros.h b/sysdeps/powerpc/powerpc64/jmp_buf-macros.h new file mode 100644 index 0000000000..d3e0d4e146 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 656 +#define SIGJMP_BUF_SIZE 656 +#define JMP_BUF_ALIGN 16 +#define SIGJMP_BUF_ALIGN 16 +#define MASK_WAS_SAVED_OFFSET 512 +#define SAVED_MASK_OFFSET 520 diff --git a/sysdeps/s390/s390-32/jmp_buf-macros.h b/sysdeps/s390/s390-32/jmp_buf-macros.h new file mode 100644 index 0000000000..0f29ff90d0 --- /dev/null +++ b/sysdeps/s390/s390-32/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 188 +#define SIGJMP_BUF_SIZE 188 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 56 +#define SAVED_MASK_OFFSET 60 diff --git a/sysdeps/s390/s390-64/jmp_buf-macros.h b/sysdeps/s390/s390-64/jmp_buf-macros.h new file mode 100644 index 0000000000..4e5f348eaf --- /dev/null +++ b/sysdeps/s390/s390-64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 280 +#define SIGJMP_BUF_SIZE 280 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 144 +#define SAVED_MASK_OFFSET 152 diff --git a/sysdeps/sh/jmp_buf-macros.h b/sysdeps/sh/jmp_buf-macros.h new file mode 100644 index 0000000000..b2bc30db5d --- /dev/null +++ b/sysdeps/sh/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 192 +#define SIGJMP_BUF_SIZE 192 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 60 +#define SAVED_MASK_OFFSET 64 diff --git a/sysdeps/sparc/sparc32/jmp_buf-macros.h b/sysdeps/sparc/sparc32/jmp_buf-macros.h new file mode 100644 index 0000000000..388533f88a --- /dev/null +++ b/sysdeps/sparc/sparc32/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 144 +#define SIGJMP_BUF_SIZE 144 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 12 +#define SAVED_MASK_OFFSET 16 diff --git a/sysdeps/sparc/sparc64/jmp_buf-macros.h b/sysdeps/sparc/sparc64/jmp_buf-macros.h new file mode 100644 index 0000000000..e86afd7b3d --- /dev/null +++ b/sysdeps/sparc/sparc64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 640 +#define SIGJMP_BUF_SIZE 640 +#define JMP_BUF_ALIGN 16 +#define SIGJMP_BUF_ALIGN 16 +#define MASK_WAS_SAVED_OFFSET 496 +#define SAVED_MASK_OFFSET 504 diff --git a/sysdeps/tile/tilegx/tilegx32/jmp_buf-macros.h b/sysdeps/tile/tilegx/tilegx32/jmp_buf-macros.h new file mode 100644 index 0000000000..eb64802525 --- /dev/null +++ b/sysdeps/tile/tilegx/tilegx32/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 392 +#define SIGJMP_BUF_SIZE 392 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 256 +#define SAVED_MASK_OFFSET 260 diff --git a/sysdeps/tile/tilegx/tilegx64/jmp_buf-macros.h b/sysdeps/tile/tilegx/tilegx64/jmp_buf-macros.h new file mode 100644 index 0000000000..685f9b8236 --- /dev/null +++ b/sysdeps/tile/tilegx/tilegx64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 392 +#define SIGJMP_BUF_SIZE 392 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 256 +#define SAVED_MASK_OFFSET 264 diff --git a/sysdeps/tile/tilepro/jmp_buf-macros.h b/sysdeps/tile/tilepro/jmp_buf-macros.h new file mode 100644 index 0000000000..411e62a047 --- /dev/null +++ b/sysdeps/tile/tilepro/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 260 +#define SIGJMP_BUF_SIZE 260 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 128 +#define SAVED_MASK_OFFSET 132 diff --git a/sysdeps/x86_64/64/jmp_buf-macros.h b/sysdeps/x86_64/64/jmp_buf-macros.h new file mode 100644 index 0000000000..3ae63ab5c5 --- /dev/null +++ b/sysdeps/x86_64/64/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 200 +#define SIGJMP_BUF_SIZE 200 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 64 +#define SAVED_MASK_OFFSET 72 diff --git a/sysdeps/x86_64/x32/jmp_buf-macros.h b/sysdeps/x86_64/x32/jmp_buf-macros.h new file mode 100644 index 0000000000..2fa8e9ec38 --- /dev/null +++ b/sysdeps/x86_64/x32/jmp_buf-macros.h @@ -0,0 +1,6 @@ +#define JMP_BUF_SIZE 200 +#define SIGJMP_BUF_SIZE 200 +#define JMP_BUF_ALIGN 8 +#define SIGJMP_BUF_ALIGN 8 +#define MASK_WAS_SAVED_OFFSET 64 +#define SAVED_MASK_OFFSET 68 From patchwork Tue Nov 7 22:39:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 835497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-86876-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="yXeG+aC9"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yWkrB3p5Mz9ryr for ; Wed, 8 Nov 2017 09:39:22 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; q=dns; s=default; b=dVQHv85Xw/3J/uqD 4+b36BX4t8nbslwfvFsjRUyd5TxZDZf/QyZhSi9V0oDgT7zlnSxxZ1DeZ7i8rx3m 3UGUoWANCVPeLIJQXem2SfGzfSoH85rh/5u8KGHFH2hHYuanorlprTN8by1/Q20w nkKepqELsWV1kPK9MVkyFrkA07k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; s=default; bh=TW7TOR8Fo1lNqERwz59zJ+ ojDy4=; b=yXeG+aC9Pgvg0bmrNrOUu+ztQAWz0uJ2mvGJYkslZeyCLrKty2Viqr +XZPY1M4ecc/7n82KhIt9B7Zhnr+oYuRPyFP0wCqpLyHRTikgLMl8TKkfcdBERvk pCKVubI4zIdmttfsLZI6AvhDRF7hdkj061LQfunW3i2otvK/DSRIg= Received: (qmail 36200 invoked by alias); 7 Nov 2017 22:39:13 -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 35749 invoked by uid 89); 7 Nov 2017 22:39:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mga09.intel.com X-ExtLoop1: 1 Date: Tue, 7 Nov 2017 14:39:08 -0800 From: "H.J. Lu" To: GNU C Library Subject: [PATCH 2/2] jmpbuf: Add paddings for target specific usage Message-ID: <20171107223908.GB46190@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) To support Shadow Stack (SHSTK) in Intel Control-flow Enforcement Technology (CET) in setjmp/longjmp, we need to save shadow stack pointer in jmp_buf. The __saved_mask field in jmp_buf has type of __sigset_t. On Linux, __sigset_t is defined as #define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) typedef struct { unsigned long int __val[_SIGSET_NWORDS]; } __sigset_t; which is much bigger than expected by the __sigprocmask system call, which has typedef struct { unsigned long sig[_NSIG_WORDS]; } sigset_t; We can shrink __sigset_t used by __saved_mask in jmp_buf to add paddings for target specific usage. As long as the new __sigset_t is not smaller than sigset_t expected by the __sigprocmask system call, it should work correctly. This patch defines __jmp_buf_sigset_t for __saved_mask in jmp_buf on Linux and verifies __jmp_buf_sigset_t has the suitable size for the __sigprocmask system call. Tested with build-many-glibcs.py. OK for master? H.J. --- * bits/setjmp3.h: New file. * sysdeps/unix/sysv/linux/bits/setjmp3.h: Likewise. * setjmp/Makefile (headers): Add bits/setjmp3.h. * setjmp/longjmp.c (__libc_siglongjmp): Cast &env[0].__saved_mask to "sigset_t *". * setjmp/sigjmp.c (__sigjmp_save): Likewise. * sysdeps/powerpc/longjmp.c (__vmx__libc_siglongjmp): Likewise. * sysdeps/powerpc/novmx-longjmp.c (__novmx__libc_siglongjmp): Likewise. * sysdeps/powerpc/novmx-sigjmp.c (__novmx__sigjmp_save): Likewise. * sysdeps/powerpc/sigjmp.c (__vmx__sigjmp_save): Likewise. * sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c (__libc_unwind_longjmp): Likewise. * setjmp/setjmp.h: Include instead of . (__jmp_buf_tag): Change __saved_mask to __target. * setjmp/tst-jmp_buf.c: Include . [_NSIG] (KERNEL_NSIG_WORDS): New. [_NSIG] (kernel_sigset_t): Likewise. [_NSIG] (do_test): Add _Static_assert for size of __saved_mask in jmp_buf >= sizeof kernel_sigset_t. --- bits/setjmp3.h | 31 +++++++++++++++++ setjmp/Makefile | 2 +- setjmp/longjmp.c | 3 +- setjmp/setjmp.h | 4 +-- setjmp/sigjmp.c | 2 +- setjmp/tst-jmp_buf.c | 17 ++++++++++ sysdeps/powerpc/longjmp.c | 3 +- sysdeps/powerpc/novmx-longjmp.c | 3 +- sysdeps/powerpc/novmx-sigjmp.c | 2 +- sysdeps/powerpc/sigjmp.c | 2 +- sysdeps/unix/sysv/linux/bits/setjmp3.h | 48 +++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c | 3 +- 12 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 bits/setjmp3.h create mode 100644 sysdeps/unix/sysv/linux/bits/setjmp3.h diff --git a/bits/setjmp3.h b/bits/setjmp3.h new file mode 100644 index 0000000000..b164c8d449 --- /dev/null +++ b/bits/setjmp3.h @@ -0,0 +1,31 @@ +/* Generic __jmpbuf_target_t defition. + Copyright (C) 2017 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; if not, see + . */ + +#ifndef _SETJMP_H +# error "Never include directly; use instead." +#endif + +#include + +typedef struct + { + __sigset_t __saved_mask; + } __jmpbuf_target_t; + +/* Saved signal mask. */ +#define __saved_mask __target.__saved_mask diff --git a/setjmp/Makefile b/setjmp/Makefile index 857e0b8d0f..6ab9b4c3ca 100644 --- a/setjmp/Makefile +++ b/setjmp/Makefile @@ -22,7 +22,7 @@ subdir := setjmp include ../Makeconfig -headers := setjmp.h bits/setjmp.h bits/setjmp2.h +headers := setjmp.h bits/setjmp.h bits/setjmp2.h bits/setjmp3.h routines := setjmp sigjmp bsd-setjmp bsd-_setjmp \ longjmp __longjmp jmp-unwind diff --git a/setjmp/longjmp.c b/setjmp/longjmp.c index 2453c2c124..86a024b4b8 100644 --- a/setjmp/longjmp.c +++ b/setjmp/longjmp.c @@ -31,7 +31,8 @@ __libc_siglongjmp (sigjmp_buf env, int val) if (env[0].__mask_was_saved) /* Restore the saved signal mask. */ - (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask, + (void) __sigprocmask (SIG_SETMASK, + (sigset_t *) &env[0].__saved_mask, (sigset_t *) NULL); /* Call the machine-dependent function to restore machine state. */ diff --git a/setjmp/setjmp.h b/setjmp/setjmp.h index 86fb2edf6c..1082fb0142 100644 --- a/setjmp/setjmp.h +++ b/setjmp/setjmp.h @@ -27,7 +27,7 @@ __BEGIN_DECLS #include /* Get `__jmp_buf'. */ -#include +#include /* Calling environment, plus possibly a saved signal mask. */ struct __jmp_buf_tag @@ -38,7 +38,7 @@ struct __jmp_buf_tag or add others before it. */ __jmp_buf __jmpbuf; /* Calling environment. */ int __mask_was_saved; /* Saved the signal mask? */ - __sigset_t __saved_mask; /* Saved signal mask. */ + __jmpbuf_target_t __target; /* Target specific data. */ }; diff --git a/setjmp/sigjmp.c b/setjmp/sigjmp.c index 30839ae819..0cd733b3ee 100644 --- a/setjmp/sigjmp.c +++ b/setjmp/sigjmp.c @@ -28,7 +28,7 @@ __sigjmp_save (sigjmp_buf env, int savemask) { env[0].__mask_was_saved = (savemask && __sigprocmask (SIG_BLOCK, (sigset_t *) NULL, - &env[0].__saved_mask) == 0); + (sigset_t *) &env[0].__saved_mask) == 0); return 0; } diff --git a/setjmp/tst-jmp_buf.c b/setjmp/tst-jmp_buf.c index 1b25d85876..16ddebc224 100644 --- a/setjmp/tst-jmp_buf.c +++ b/setjmp/tst-jmp_buf.c @@ -18,9 +18,19 @@ #include #include +#include #include #include +#ifdef _NSIG +# define KERNEL_NSIG_WORDS (_NSIG / (8 * sizeof (unsigned long int))) + +typedef struct + { + unsigned long int __val[KERNEL_NSIG_WORDS]; + } kernel_sigset_t; +#endif + #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -54,6 +64,13 @@ do_test (void) TEST_OFFSET (struct __jmp_buf_tag, __saved_mask, SAVED_MASK_OFFSET); +#ifdef _NSIG + jmp_buf buf; + __typeof (buf[0].__saved_mask) saved_mask; + _Static_assert (sizeof (saved_mask) >= sizeof (kernel_sigset_t), + "size of saved_mask < size of kernel_sigset_t"); +#endif + return 0; } diff --git a/sysdeps/powerpc/longjmp.c b/sysdeps/powerpc/longjmp.c index bd3ed8c22b..a23f2c582b 100644 --- a/sysdeps/powerpc/longjmp.c +++ b/sysdeps/powerpc/longjmp.c @@ -39,7 +39,8 @@ __vmx__libc_siglongjmp (sigjmp_buf env, int val) if (env[0].__mask_was_saved) /* Restore the saved signal mask. */ - (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask, + (void) __sigprocmask (SIG_SETMASK, + (sigset_t *) &env[0].__saved_mask, (sigset_t *) NULL); /* Call the machine-dependent function to restore machine state. */ diff --git a/sysdeps/powerpc/novmx-longjmp.c b/sysdeps/powerpc/novmx-longjmp.c index b0020b728a..662fbc5432 100644 --- a/sysdeps/powerpc/novmx-longjmp.c +++ b/sysdeps/powerpc/novmx-longjmp.c @@ -37,7 +37,8 @@ __novmx__libc_siglongjmp (__novmx__sigjmp_buf env, int val) if (env[0].__mask_was_saved) /* Restore the saved signal mask. */ - (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask, + (void) __sigprocmask (SIG_SETMASK, + (sigset_t *) &env[0].__saved_mask, (sigset_t *) NULL); /* Call the machine-dependent function to restore machine state. */ diff --git a/sysdeps/powerpc/novmx-sigjmp.c b/sysdeps/powerpc/novmx-sigjmp.c index 7d0ae59437..62680fe38f 100644 --- a/sysdeps/powerpc/novmx-sigjmp.c +++ b/sysdeps/powerpc/novmx-sigjmp.c @@ -35,7 +35,7 @@ __novmx__sigjmp_save (__novmx__sigjmp_buf env, int savemask) { env[0].__mask_was_saved = (savemask && __sigprocmask (SIG_BLOCK, (sigset_t *) NULL, - &env[0].__saved_mask) == 0); + (sigset_t *) &env[0].__saved_mask) == 0); return 0; } diff --git a/sysdeps/powerpc/sigjmp.c b/sysdeps/powerpc/sigjmp.c index 6d593a0992..736491eff9 100644 --- a/sysdeps/powerpc/sigjmp.c +++ b/sysdeps/powerpc/sigjmp.c @@ -31,7 +31,7 @@ __vmx__sigjmp_save (sigjmp_buf env, int savemask) { env[0].__mask_was_saved = (savemask && __sigprocmask (SIG_BLOCK, (sigset_t *) NULL, - &env[0].__saved_mask) == 0); + (sigset_t *) &env[0].__saved_mask) == 0); return 0; } diff --git a/sysdeps/unix/sysv/linux/bits/setjmp3.h b/sysdeps/unix/sysv/linux/bits/setjmp3.h new file mode 100644 index 0000000000..e86dbdcba4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/setjmp3.h @@ -0,0 +1,48 @@ +/* __jmpbuf_target_t defition for Linux. + Copyright (C) 2017 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; if not, see + . */ + +#ifndef _SETJMP_H +# error "Never include directly; use instead." +#endif + +#include + +/* The biggest signal number + 1 */ +#define _JUMP_BUF_SIGSET_NSIG 257 +/* Number of longs to hold all signals. */ +#define _JUMP_BUF_SIGSET_NWORDS \ + ((_JUMP_BUF_SIGSET_NSIG - 1 + 7) / (8 * sizeof (unsigned long int))) + +typedef struct + { + unsigned long int __val[_JUMP_BUF_SIGSET_NWORDS]; + } __jmp_buf_sigset_t; + +typedef union + { + __sigset_t __saved_mask_compat; + struct + { + __jmp_buf_sigset_t __saved_mask; + /* Paddings for target specific usage. */ + unsigned long int __padding[12]; + } __saved; + } __jmpbuf_target_t; + +/* Saved signal mask. */ +#define __saved_mask __target.__saved.__saved_mask diff --git a/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c b/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c index 874ed18d6b..658a25b87b 100644 --- a/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c +++ b/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c @@ -34,7 +34,8 @@ __libc_unwind_longjmp (sigjmp_buf env, int val) if (env[0].__mask_was_saved) /* Restore the saved signal mask. */ - (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask, + (void) __sigprocmask (SIG_SETMASK, + (sigset_t *) &env[0].__saved_mask, (sigset_t *) NULL); /* Call the machine-dependent function to restore machine state. */