comparison dyncall/dyncall.h @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents ddfb9577a00e
children 0c8838766866
comparison
equal deleted inserted replaced
532:d4bf63ab9164 533:71c884e610f0
4 Library: dyncall 4 Library: dyncall
5 File: dyncall/dyncall.h 5 File: dyncall/dyncall.h
6 Description: public header for library dyncall 6 Description: public header for library dyncall
7 License: 7 License:
8 8
9 Copyright (c) 2007-2020 Daniel Adler <dadler@uni-goettingen.de>, 9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
10 Tassilo Philipp <tphilipp@potion-studios.com> 10 Tassilo Philipp <tphilipp@potion-studios.com>
11 11
12 Permission to use, copy, modify, and distribute this software for any 12 Permission to use, copy, modify, and distribute this software for any
13 purpose with or without fee is hereby granted, provided that the above 13 purpose with or without fee is hereby granted, provided that the above
14 copyright notice and this permission notice appear in all copies. 14 copyright notice and this permission notice appear in all copies.
33 #ifdef __cplusplus 33 #ifdef __cplusplus
34 extern "C" { 34 extern "C" {
35 #endif 35 #endif
36 36
37 typedef struct DCCallVM_ DCCallVM; 37 typedef struct DCCallVM_ DCCallVM;
38 typedef struct DCstruct_ DCstruct; 38 typedef struct DCaggr_ DCaggr;
39 39
40 /* Supported Calling Convention Modes */ 40 /* Supported Calling Convention Modes */
41 41
42 #define DC_CALL_C_DEFAULT 0 42 /* default */
43 #define DC_CALL_C_DEFAULT_THIS 99 43 #define DC_CALL_C_DEFAULT 0 /* C default (platform native) */
44 #define DC_CALL_C_ELLIPSIS 100 44 #define DC_CALL_C_DEFAULT_THIS 99 /* for C++ calls where first param is hidden this ptr (platform native) */
45 #define DC_CALL_C_ELLIPSIS_VARARGS 101 45 #define DC_CALL_C_ELLIPSIS 100 /* to be set for vararg calls' non-hidden (e.g. C++ this ptr), named arguments */
46 #define DC_CALL_C_ELLIPSIS_VARARGS 101 /* to be set for vararg calls' non-hidden (e.g. C++ this ptr), variable arguments (in ... part) */
47 /* platform specific */
46 #define DC_CALL_C_X86_CDECL 1 48 #define DC_CALL_C_X86_CDECL 1
47 #define DC_CALL_C_X86_WIN32_STD 2 49 #define DC_CALL_C_X86_WIN32_STD 2
48 #define DC_CALL_C_X86_WIN32_FAST_MS 3 50 #define DC_CALL_C_X86_WIN32_FAST_MS 3
49 #define DC_CALL_C_X86_WIN32_FAST_GNU 4 51 #define DC_CALL_C_X86_WIN32_FAST_GNU 4
50 #define DC_CALL_C_X86_WIN32_THIS_MS 5 52 #define DC_CALL_C_X86_WIN32_THIS_MS 5
51 #define DC_CALL_C_X86_WIN32_THIS_GNU DC_CALL_C_X86_CDECL /* alias - identical to cdecl (w/ this-ptr as 1st arg) */ 53 #define DC_CALL_C_X86_WIN32_THIS_GNU DC_CALL_C_X86_CDECL /* alias - identical to cdecl (w/ this-ptr as 1st arg) */
52 #define DC_CALL_C_X64_WIN64 7 54 #define DC_CALL_C_X64_WIN64 7
53 #define DC_CALL_C_X64_WIN64_THIS 70 /* only needed when using aggregate by value as return type @@@STRUCT implement */ 55 #define DC_CALL_C_X64_WIN64_THIS 70 /* only needed when using aggregate by value as return type */
54 #define DC_CALL_C_X64_SYSV 8 56 #define DC_CALL_C_X64_SYSV 8
55 #define DC_CALL_C_X64_SYSV_THIS DC_CALL_C_X64_SYSV /* alias */ 57 #define DC_CALL_C_X64_SYSV_THIS DC_CALL_C_X64_SYSV /* alias */
56 #define DC_CALL_C_PPC32_DARWIN 9 58 #define DC_CALL_C_PPC32_DARWIN 9
57 #define DC_CALL_C_PPC32_OSX DC_CALL_C_PPC32_DARWIN /* alias */ 59 #define DC_CALL_C_PPC32_OSX DC_CALL_C_PPC32_DARWIN /* alias */
58 #define DC_CALL_C_ARM_ARM_EABI 10 60 #define DC_CALL_C_ARM_ARM_EABI 10
71 #define DC_CALL_C_SPARC32 20 73 #define DC_CALL_C_SPARC32 20
72 #define DC_CALL_C_SPARC64 21 74 #define DC_CALL_C_SPARC64 21
73 #define DC_CALL_C_ARM64 22 75 #define DC_CALL_C_ARM64 22
74 #define DC_CALL_C_PPC64 23 76 #define DC_CALL_C_PPC64 23
75 #define DC_CALL_C_PPC64_LINUX DC_CALL_C_PPC64 /* alias */ 77 #define DC_CALL_C_PPC64_LINUX DC_CALL_C_PPC64 /* alias */
78 /* syscalls, default */
76 #define DC_CALL_SYS_DEFAULT 200 79 #define DC_CALL_SYS_DEFAULT 200
80 /* syscalls, platform specific */
77 #define DC_CALL_SYS_X86_INT80H_LINUX 201 81 #define DC_CALL_SYS_X86_INT80H_LINUX 201
78 #define DC_CALL_SYS_X86_INT80H_BSD 202 82 #define DC_CALL_SYS_X86_INT80H_BSD 202
79 #define DC_CALL_SYS_X64_SYSCALL_SYSV 204 83 #define DC_CALL_SYS_X64_SYSCALL_SYSV 204
80 #define DC_CALL_SYS_PPC32 210 84 #define DC_CALL_SYS_PPC32 210
81 #define DC_CALL_SYS_PPC64 211 85 #define DC_CALL_SYS_PPC64 211
83 /* Error codes. */ 87 /* Error codes. */
84 88
85 #define DC_ERROR_NONE 0 89 #define DC_ERROR_NONE 0
86 #define DC_ERROR_UNSUPPORTED_MODE -1 90 #define DC_ERROR_UNSUPPORTED_MODE -1
87 91
88 DC_API DCCallVM* dcNewCallVM (DCsize size); 92 DC_API DCCallVM* dcNewCallVM (DCsize size);
89 DC_API void dcFree (DCCallVM* vm); 93 DC_API void dcFree (DCCallVM* vm);
90 DC_API void dcReset (DCCallVM* vm); 94 DC_API void dcReset (DCCallVM* vm);
91 95
92 DC_API void dcMode (DCCallVM* vm, DCint mode); 96 DC_API void dcMode (DCCallVM* vm, DCint mode);
93 97
94 DC_API void dcArgBool (DCCallVM* vm, DCbool value); 98 DC_API void dcBeginCallAggr (DCCallVM* vm, const DCaggr* ag);
95 DC_API void dcArgChar (DCCallVM* vm, DCchar value);
96 DC_API void dcArgShort (DCCallVM* vm, DCshort value);
97 DC_API void dcArgInt (DCCallVM* vm, DCint value);
98 DC_API void dcArgLong (DCCallVM* vm, DClong value);
99 DC_API void dcArgLongLong (DCCallVM* vm, DClonglong value);
100 DC_API void dcArgFloat (DCCallVM* vm, DCfloat value);
101 DC_API void dcArgDouble (DCCallVM* vm, DCdouble value);
102 DC_API void dcArgPointer (DCCallVM* vm, DCpointer value);
103 DC_API void dcArgStruct (DCCallVM* vm, DCstruct* s, DCpointer value);
104 99
105 DC_API void dcCallVoid (DCCallVM* vm, DCpointer funcptr); 100 DC_API void dcArgBool (DCCallVM* vm, DCbool value);
106 DC_API DCbool dcCallBool (DCCallVM* vm, DCpointer funcptr); 101 DC_API void dcArgChar (DCCallVM* vm, DCchar value);
107 DC_API DCchar dcCallChar (DCCallVM* vm, DCpointer funcptr); 102 DC_API void dcArgShort (DCCallVM* vm, DCshort value);
108 DC_API DCshort dcCallShort (DCCallVM* vm, DCpointer funcptr); 103 DC_API void dcArgInt (DCCallVM* vm, DCint value);
109 DC_API DCint dcCallInt (DCCallVM* vm, DCpointer funcptr); 104 DC_API void dcArgLong (DCCallVM* vm, DClong value);
110 DC_API DClong dcCallLong (DCCallVM* vm, DCpointer funcptr); 105 DC_API void dcArgLongLong (DCCallVM* vm, DClonglong value);
111 DC_API DClonglong dcCallLongLong (DCCallVM* vm, DCpointer funcptr); 106 DC_API void dcArgFloat (DCCallVM* vm, DCfloat value);
112 DC_API DCfloat dcCallFloat (DCCallVM* vm, DCpointer funcptr); 107 DC_API void dcArgDouble (DCCallVM* vm, DCdouble value);
113 DC_API DCdouble dcCallDouble (DCCallVM* vm, DCpointer funcptr); 108 DC_API void dcArgPointer (DCCallVM* vm, DCpointer value);
114 DC_API DCpointer dcCallPointer (DCCallVM* vm, DCpointer funcptr); 109 DC_API void dcArgAggr (DCCallVM* vm, const DCaggr* ag, const void* value);
115 DC_API void dcCallStruct (DCCallVM* vm, DCpointer funcptr, DCstruct* s, DCpointer returnValue);
116 110
117 DC_API DCint dcGetError (DCCallVM* vm); 111 DC_API void dcCallVoid (DCCallVM* vm, DCpointer funcptr);
112 DC_API DCbool dcCallBool (DCCallVM* vm, DCpointer funcptr);
113 DC_API DCchar dcCallChar (DCCallVM* vm, DCpointer funcptr);
114 DC_API DCshort dcCallShort (DCCallVM* vm, DCpointer funcptr);
115 DC_API DCint dcCallInt (DCCallVM* vm, DCpointer funcptr);
116 DC_API DClong dcCallLong (DCCallVM* vm, DCpointer funcptr);
117 DC_API DClonglong dcCallLongLong (DCCallVM* vm, DCpointer funcptr);
118 DC_API DCfloat dcCallFloat (DCCallVM* vm, DCpointer funcptr);
119 DC_API DCdouble dcCallDouble (DCCallVM* vm, DCpointer funcptr);
120 DC_API DCpointer dcCallPointer (DCCallVM* vm, DCpointer funcptr);
121 DC_API DCpointer dcCallAggr (DCCallVM* vm, DCpointer funcptr, const DCaggr* ag, DCpointer ret); /* retval is written to *ret, returns ret */
118 122
119 #define DEFAULT_ALIGNMENT 0 123 DC_API DCint dcGetError (DCCallVM* vm);
120 DC_API DCstruct* dcNewStruct (DCsize fieldCount, DCint alignment);
121 DC_API void dcStructField (DCstruct* s, DCint type, DCint alignment, DCsize arrayLength);
122 DC_API void dcSubStruct (DCstruct* s, DCsize fieldCount, DCint alignment, DCsize arrayLength);
123 /* Each dcNewStruct or dcSubStruct call must be paired with a dcCloseStruct. */
124 DC_API void dcCloseStruct (DCstruct* s);
125 DC_API DCsize dcStructSize (DCstruct* s);
126 DC_API DCsize dcStructAlignment(DCstruct* s);
127 DC_API void dcFreeStruct (DCstruct* s);
128 124
129 DC_API DCstruct* dcDefineStruct (const char* signature); 125 DC_API DCaggr* dcNewAggr (DCsize maxFieldCount, DCsize size);
126 DC_API void dcFreeAggr (DCaggr* ag);
127 /* if type == DC_SIGCHAR_AGGREGATE, pass DCaggr* of nested struct/union in ... */
128 DC_API void dcAggrField (DCaggr* ag, DCsigchar type, DCint offset, DCsize array_len, ...);
129 DC_API void dcCloseAggr (DCaggr* ag); /* to indicate end of struct definition, required */
130 130
131 131
132 /* helpers */ 132 /* helpers */
133 133
134 /* returns respective mode for callconv sig char (w/o checking if mode exists */ 134 /* returns respective mode for callconv sig char (w/o checking if mode exists */