github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/jit-apply-func.h (about) 1 /* 2 * jit-apply-func.h - Definition of "__builtin_apply" and friends. 3 * 4 * Copyright (C) 2004 Southern Storm Software, Pty Ltd. 5 * 6 * This file is part of the libjit library. 7 * 8 * The libjit library is free software: you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public License 10 * as published by the Free Software Foundation, either version 2.1 of 11 * the License, or (at your option) any later version. 12 * 13 * The libjit library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with the libjit library. If not, see 20 * <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef _JIT_APPLY_FUNC_H 24 #define _JIT_APPLY_FUNC_H 25 26 #if defined(__i386) || defined(__i386__) || defined(_M_IX86) 27 28 #include "jit-apply-x86.h" 29 30 #elif defined(__arm) || defined(__arm__) 31 32 #include "jit-apply-arm.h" 33 34 #elif defined(__alpha) || defined(__alpha__) 35 36 #include "jit-apply-alpha.h" 37 38 #elif defined(__x86_64) || defined(__x86_64__) 39 40 #include "jit-apply-x86-64.h" 41 42 #endif 43 44 #if !defined(jit_builtin_apply) 45 #define jit_builtin_apply(func,args,size,return_float,return_buf) \ 46 do { \ 47 (return_buf) = __builtin_apply \ 48 ((void (*)())(func), (args), (size)); \ 49 } while (0) 50 #endif 51 52 #if !defined(jit_builtin_apply_args) 53 #define jit_builtin_apply_args(type,args) \ 54 do { \ 55 (args) = (type)__builtin_apply_args(); \ 56 } while (0) 57 #endif 58 59 #if !defined(jit_builtin_return_int) 60 #define jit_builtin_return_int(return_buf) \ 61 do { \ 62 __builtin_return((return_buf)); \ 63 } while (0) 64 #endif 65 66 #if !defined(jit_builtin_return_long) 67 #define jit_builtin_return_long(return_buf) \ 68 do { \ 69 __builtin_return((return_buf)); \ 70 } while (0) 71 #endif 72 73 #if !defined(jit_builtin_return_float) 74 #define jit_builtin_return_float(return_buf) \ 75 do { \ 76 __builtin_return((return_buf)); \ 77 } while (0) 78 #endif 79 80 #if !defined(jit_builtin_return_double) 81 #define jit_builtin_return_double(return_buf) \ 82 do { \ 83 __builtin_return((return_buf)); \ 84 } while (0) 85 #endif 86 87 #if !defined(jit_builtin_return_nfloat) 88 #define jit_builtin_return_nfloat(return_buf) \ 89 do { \ 90 __builtin_return((return_buf)); \ 91 } while (0) 92 #endif 93 94 /* 95 * Create a closure for the underlying platform in the given buffer. 96 * The closure must arrange to call "func" with two arguments: 97 * "closure" and a pointer to an apply structure. 98 */ 99 void _jit_create_closure(unsigned char *buf, void *func, 100 void *closure, void *type); 101 102 /* 103 * Create a redirector stub for the underlying platform in the given buffer. 104 * The redirector arranges to call "func" with the "user_data" argument. 105 * It is assumed that "func" returns a pointer to the actual function. 106 * Returns a pointer to the position in "buf" where the redirector starts, 107 * which may be different than "buf" if alignment occurred. 108 */ 109 void *_jit_create_redirector(unsigned char *buf, void *func, 110 void *user_data, int abi); 111 112 113 /* 114 * Create the indirector for the function. 115 */ 116 void *_jit_create_indirector(unsigned char *buf, void **entry); 117 118 /* 119 * Pad a buffer with NOP instructions. Used to align code. 120 * This will only be called if "jit_should_pad" is defined. 121 */ 122 void _jit_pad_buffer(unsigned char *buf, int len); 123 124 #endif /* _JIT_APPLY_FUNC_H */