1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2019 ARM Limited */
3 #ifndef __TESTCASES_H__
4 #define __TESTCASES_H__
14 /* Architecture specific sigframe definitions */
15 #include <asm/sigcontext.h>
17 #define FPSIMD_CTX (1 << 0)
18 #define SVE_CTX (1 << 1)
19 #define EXTRA_CTX (1 << 2)
21 #define KSFT_BAD_MAGIC 0xdeadbeef
24 sizeof(struct _aarch64_ctx)
26 #define GET_SF_RESV_HEAD(sf) \
27 (struct _aarch64_ctx *)(&(sf).uc.uc_mcontext.__reserved)
29 #define GET_SF_RESV_SIZE(sf) \
30 sizeof((sf).uc.uc_mcontext.__reserved)
32 #define GET_UCP_RESV_SIZE(ucp) \
33 sizeof((ucp)->uc_mcontext.__reserved)
35 #define ASSERT_BAD_CONTEXT(uc) do { \
37 if (!validate_reserved((uc), GET_UCP_RESV_SIZE((uc)), &err)) { \
40 "Using badly built context - ERR: %s\n",\
47 #define ASSERT_GOOD_CONTEXT(uc) do { \
49 if (!validate_reserved((uc), GET_UCP_RESV_SIZE((uc)), &err)) { \
52 "Detected BAD context - ERR: %s\n", err);\
55 fprintf(stderr, "uc context validated.\n"); \
60 * A simple record-walker for __reserved area: it walks through assuming
61 * only to find a proper struct __aarch64_ctx header descriptor.
63 * Instead it makes no assumptions on the content and ordering of the
64 * records, any needed bounds checking must be enforced by the caller
65 * if wanted: this way can be used by caller on any maliciously built bad
68 * head->size accounts both for payload and header _aarch64_ctx size !
70 #define GET_RESV_NEXT_HEAD(h) \
71 (struct _aarch64_ctx *)((char *)(h) + (h)->size)
73 struct fake_sigframe
{
79 bool validate_reserved(ucontext_t
*uc
, size_t resv_sz
, char **err
);
81 bool validate_extra_context(struct extra_context
*extra
, char **err
);
83 struct _aarch64_ctx
*get_header(struct _aarch64_ctx
*head
, uint32_t magic
,
84 size_t resv_sz
, size_t *offset
);
86 static inline struct _aarch64_ctx
*get_terminator(struct _aarch64_ctx
*head
,
90 return get_header(head
, 0, resv_sz
, offset
);
93 static inline void write_terminator_record(struct _aarch64_ctx
*tail
)
101 struct _aarch64_ctx
*get_starting_head(struct _aarch64_ctx
*shead
,
102 size_t need_sz
, size_t resv_sz
,