1 /* Check jmp_buf sizes, alignments and offsets.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
21 #include <jmp_buf-macros.h>
23 #define SJSTR_HELPER(x) #x
24 #define SJSTR(x) SJSTR_HELPER(x)
26 #define TEST_SIZE(type, size) \
27 _Static_assert (sizeof (type) == size, \
28 "size of " #type " != " \
30 #define TEST_ALIGN(type, align) \
31 _Static_assert (__alignof__ (type) == align , \
32 "align of " #type " != " \
34 #define TEST_OFFSET(type, member, offset) \
35 _Static_assert (offsetof (type, member) == offset, \
36 "offset of " #member " field of " #type " != " \
39 /* Check if jmp_buf have the expected sizes. */
40 TEST_SIZE (jmp_buf, JMP_BUF_SIZE
);
41 TEST_SIZE (sigjmp_buf
, SIGJMP_BUF_SIZE
);
43 /* Check if jmp_buf have the expected alignments. */
44 TEST_ALIGN (jmp_buf, JMP_BUF_ALIGN
);
45 TEST_ALIGN (sigjmp_buf
, SIGJMP_BUF_ALIGN
);
47 /* Check if internal fields in jmp_buf have the expected offsets. */
48 TEST_OFFSET (struct __jmp_buf_tag
, __mask_was_saved
,
49 MASK_WAS_SAVED_OFFSET
);
50 TEST_OFFSET (struct __jmp_buf_tag
, __saved_mask
,
54 main (int argc
, char *argv
[])