FFmpeg
aarch64.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2025, Niklas Haas
3  * Copyright © 2018, VideoLAN and dav1d authors
4  * Copyright © 2018, Two Orioles, LLC
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef CHECKASM_PLATFORM_AARCH64_H
30 #define CHECKASM_PLATFORM_AARCH64_H
31 
32 #include "checkasm/attributes.h"
33 #include "checkasm/checkasm.h"
34 #include <stdint.h>
35 
36 CHECKASM_API void checkasm_checked_call(void *func, ...);
37 
38 /* The upper 32 bits of 32-bit data types are undefined when passed as function
39  * parameters. In practice those bits usually end up being zero which may hide
40  * certain bugs, such as using a register containing undefined bits as a pointer
41  * offset, so we want to intentionally clobber those bits with junk to expose
42  * any issues. The following set of macros automatically calculates a bitmask
43  * specifying which parameters should have their upper halves clobbered. */
44 /* Up to 8 floating-point parameters are passed in float registers, which are
45  * handled orthogonally from integer parameters passed in GPR registers. */
46 #define IGNORED_FP_ARGS 8
47 
48 #if CHECKASM_HAVE_GENERIC
49  #define clobber_type(arg) \
50  _Generic((void (*)(void *, arg)) NULL, \
51  void (*)(void *, int32_t): clobber_mask |= 1 << mpos++, \
52  void (*)(void *, uint32_t): clobber_mask |= 1 << mpos++, \
53  void (*)(void *, float): mpos += (fp_args++ >= IGNORED_FP_ARGS), \
54  void (*)(void *, double): mpos += (fp_args++ >= IGNORED_FP_ARGS), \
55  default: mpos++)
56 
57  #define init_clobber_mask(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, ...) \
58  unsigned clobber_mask = 0; \
59  { \
60  int mpos = 0, fp_args = 0; \
61  clobber_type(a); \
62  clobber_type(b); \
63  clobber_type(c); \
64  clobber_type(d); \
65  clobber_type(e); \
66  clobber_type(f); \
67  clobber_type(g); \
68  clobber_type(h); \
69  clobber_type(i); \
70  clobber_type(j); \
71  clobber_type(k); \
72  clobber_type(l); \
73  clobber_type(m); \
74  clobber_type(n); \
75  clobber_type(o); \
76  }
77 #else
78  /* Skip parameter clobbering on compilers without support for _Generic() */
79  #define init_clobber_mask(...) unsigned clobber_mask = 0
80 #endif
81 
82 #define checkasm_declare_impl(ret, ...) \
83  ret (*checked_call)(__VA_ARGS__, int64_t, int64_t, int64_t, int64_t, int64_t, \
84  int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, \
85  int64_t, int64_t, int64_t, int64_t, void *, unsigned) \
86  = (ret (*)(__VA_ARGS__, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, \
87  int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, \
88  int64_t, int64_t, int64_t, void *, \
89  unsigned))(void *) checkasm_checked_call; \
90  init_clobber_mask(__VA_ARGS__, void *, void *, void *, void *, void *, void *, \
91  void *, void *, void *, void *, void *, void *, void *, void *)
92 
93 #define checkasm_call_checked(func, ...) \
94  (checkasm_set_signal_handler_state(1), \
95  checked_call(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, \
96  func, clobber_mask)); \
97  checkasm_set_signal_handler_state(0)
98 
99 /* ARM doesn't benefit from anything more than 16-byte alignment. */
100 #define CHECKASM_ALIGNMENT 16
101 
102 #endif /* CHECKASM_PLATFORM_AARCH64_H */
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:66
attributes.h
Platform and compiler attribute macros.
CHECKASM_API
#define CHECKASM_API
Symbol visibility attribute for public API functions.
Definition: attributes.h:90
checkasm_checked_call
CHECKASM_API void checkasm_checked_call(void *func,...)