~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/arm64/signal/testcases/testcases.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /* Copyright (C) 2019 ARM Limited */
  3 #ifndef __TESTCASES_H__
  4 #define __TESTCASES_H__
  5 
  6 #include <stddef.h>
  7 #include <stdio.h>
  8 #include <stdbool.h>
  9 #include <stdint.h>
 10 #include <stdlib.h>
 11 #include <ucontext.h>
 12 #include <signal.h>
 13 
 14 /* Architecture specific sigframe definitions */
 15 #include <asm/sigcontext.h>
 16 
 17 #define FPSIMD_CTX      (1 << 0)
 18 #define SVE_CTX         (1 << 1)
 19 #define ZA_CTX          (1 << 2)
 20 #define EXTRA_CTX       (1 << 3)
 21 #define ZT_CTX          (1 << 4)
 22 #define FPMR_CTX        (1 << 5)
 23 
 24 #define KSFT_BAD_MAGIC  0xdeadbeef
 25 
 26 #define HDR_SZ \
 27         sizeof(struct _aarch64_ctx)
 28 
 29 #define GET_SF_RESV_HEAD(sf) \
 30         (struct _aarch64_ctx *)(&(sf).uc.uc_mcontext.__reserved)
 31 
 32 #define GET_SF_RESV_SIZE(sf) \
 33         sizeof((sf).uc.uc_mcontext.__reserved)
 34 
 35 #define GET_BUF_RESV_HEAD(buf) \
 36         (struct _aarch64_ctx *)(&(buf).uc.uc_mcontext.__reserved)
 37 
 38 #define GET_BUF_RESV_SIZE(buf) \
 39         (sizeof(buf) - sizeof(buf.uc) + \
 40          sizeof((buf).uc.uc_mcontext.__reserved))
 41 
 42 #define GET_UCP_RESV_SIZE(ucp) \
 43         sizeof((ucp)->uc_mcontext.__reserved)
 44 
 45 #define ASSERT_BAD_CONTEXT(uc) do {                                     \
 46         char *err = NULL;                                               \
 47         if (!validate_reserved((uc), GET_UCP_RESV_SIZE((uc)), &err)) {  \
 48                 if (err)                                                \
 49                         fprintf(stderr,                                 \
 50                                 "Using badly built context - ERR: %s\n",\
 51                                 err);                                   \
 52         } else {                                                        \
 53                 abort();                                                \
 54         }                                                               \
 55 } while (0)
 56 
 57 #define ASSERT_GOOD_CONTEXT(uc) do {                                     \
 58         char *err = NULL;                                                \
 59         if (!validate_reserved((uc), GET_UCP_RESV_SIZE((uc)), &err)) {   \
 60                 if (err)                                                 \
 61                         fprintf(stderr,                                  \
 62                                 "Detected BAD context - ERR: %s\n", err);\
 63                 abort();                                                 \
 64         } else {                                                         \
 65                 fprintf(stderr, "uc context validated.\n");              \
 66         }                                                                \
 67 } while (0)
 68 
 69 /*
 70  * A simple record-walker for __reserved area: it walks through assuming
 71  * only to find a proper struct __aarch64_ctx header descriptor.
 72  *
 73  * Instead it makes no assumptions on the content and ordering of the
 74  * records, any needed bounds checking must be enforced by the caller
 75  * if wanted: this way can be used by caller on any maliciously built bad
 76  * contexts.
 77  *
 78  * head->size accounts both for payload and header _aarch64_ctx size !
 79  */
 80 #define GET_RESV_NEXT_HEAD(h) \
 81         (struct _aarch64_ctx *)((char *)(h) + (h)->size)
 82 
 83 struct fake_sigframe {
 84         siginfo_t       info;
 85         ucontext_t      uc;
 86 };
 87 
 88 
 89 bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err);
 90 
 91 struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic,
 92                                 size_t resv_sz, size_t *offset);
 93 
 94 static inline struct _aarch64_ctx *get_terminator(struct _aarch64_ctx *head,
 95                                                   size_t resv_sz,
 96                                                   size_t *offset)
 97 {
 98         return get_header(head, 0, resv_sz, offset);
 99 }
100 
101 static inline void write_terminator_record(struct _aarch64_ctx *tail)
102 {
103         if (tail) {
104                 tail->magic = 0;
105                 tail->size = 0;
106         }
107 }
108 
109 struct _aarch64_ctx *get_starting_head(struct _aarch64_ctx *shead,
110                                        size_t need_sz, size_t resv_sz,
111                                        size_t *offset);
112 #endif
113 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php