FFmpeg
longjmp.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,
11  * this 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"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef CHECKASM_LONGJMP_H
31 #define CHECKASM_LONGJMP_H
32 
33 #include "checkasm_config.h"
34 
35 #if defined(_WIN32) && !ARCH_X86_32
36 
37  #include <windows.h>
38 
39  /* setjmp/longjmp on Windows on architectures using SEH (all except
40  * x86_32) will try to use SEH to unwind the stack, which doesn't work
41  * for assembly functions without unwind information. */
42 
43  #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
44 
45 typedef struct {
46  CONTEXT c;
47  int status;
49 
50  #define checkasm_save_context(ctx) \
51  ((ctx).status = 0, RtlCaptureContext(&(ctx).c), (ctx).status)
52  #define checkasm_load_context(ctx) \
53  ((ctx).status = 1, RtlRestoreContext(&(ctx).c, NULL))
54 
55  #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
56 
57 #elif !defined(_WASI_EMULATED_SIGNAL) /* (!_WIN32 || ARCH_X86_32) && !_WASI_EMULATED_SIGNAL */
58 
59  #include <setjmp.h>
60 
61  #if HAVE_SIGLONGJMP
62 typedef sigjmp_buf checkasm_jmp_buf;
63  #define checkasm_save_context(ctx) sigsetjmp(ctx, 1)
64  #define checkasm_load_context(ctx) siglongjmp(ctx, 1)
65  #else /* !HAVE_SIGLONGJMP */
66 typedef jmp_buf checkasm_jmp_buf;
67  #define checkasm_save_context(ctx) setjmp(ctx)
68  #define checkasm_load_context(ctx) longjmp(ctx, 1)
69  #endif /* !HAVE_SIGLONGJMP */
70 
71 #endif /* (!_WIN32 || ARCH_X86_32) && !_WASI_EMULATED_SIGNAL */
72 
73 #ifdef checkasm_save_context
74  #define CHECKASM_HAVE_LONGJMP 1
75 #else
76 /* Dummy fallback if no other implementation was found */
77 typedef int checkasm_jmp_buf;
78  #define checkasm_save_context(ctx) 0
79  #define checkasm_load_context(ctx)
80  #define CHECKASM_HAVE_LONGJMP 0
81 #endif
82 
83 #endif /* CHECKASM_LONGJMP_H */
checkasm_config.h
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
checkasm_jmp_buf
jmp_buf checkasm_jmp_buf
Definition: longjmp.h:66
CONTEXT
#define CONTEXT
Definition: af_asetrate.c:32
status
ov_status_e status
Definition: dnn_backend_openvino.c:100