1
/****************************************************************************
2
* PROJECT: Squeak foreign function interface
4
* CONTENT: Declarations for the foreign function interface
6
* AUTHOR: Andreas Raab (ar)
7
* ADDRESS: Walt Disney Imagineering, Glendale, CA
8
* EMAIL: andreasr@wdi.disney.com
9
* RCSID: $Id: sqFFI.h 2158 2010-03-29 01:16:36Z johnmci $
13
*****************************************************************************/
17
/* Calling conventions */
18
#define FFICallTypeCDecl 0
19
#define FFICallTypeApi 1
24
#define FFITypeUnsignedByte 2
25
#define FFITypeSignedByte 3
26
#define FFITypeUnsignedShort 4
27
#define FFITypeSignedShort 5
28
#define FFITypeUnsignedInt 6
29
#define FFITypeSignedInt 7
30
#define FFITypeUnsignedLongLong 8
31
#define FFITypeSignedLongLong 9
32
#define FFITypeUnsignedChar 10
33
#define FFITypeSignedChar 11
34
#define FFITypeSingleFloat 12
35
#define FFITypeDoubleFloat 13
37
/* Shift and mask for atomic types */
38
#define FFIAtomicTypeShift 24
39
#define FFIAtomicTypeMask 251658240
42
#define FFIFlagPointer 131072
43
#define FFIFlagStructure 65536
44
#define FFIFlagAtomic 262144
47
#define FFIStructSizeMask 65535
50
#define FFINoCalloutAvailable -1
51
#define FFIErrorGenericError 0
52
#define FFIErrorNotFunction 1
53
#define FFIErrorBadArgs 2
54
#define FFIErrorBadArg 3
55
#define FFIErrorIntAsPointer 4
56
#define FFIErrorBadAtomicType 5
57
#define FFIErrorCoercionFailed 6
58
#define FFIErrorWrongType 7
59
#define FFIErrorStructSize 8
60
#define FFIErrorCallType 9
61
#define FFIErrorBadReturn 10
62
#define FFIErrorBadAddress 11
63
#define FFIErrorNoModule 12
64
#define FFIErrorAddressNotFound 13
65
#define FFIErrorAttemptToPassVoid 14
66
#define FFIErrorModuleNotFound 15
67
#define FFIErrorBadExternalLibrary 16
68
#define FFIErrorBadExternalFunction 17
69
#define FFIErrorInvalidPointer 18
71
/* Announce a coming FFI call */
72
int ffiInitialize(void);
77
/* Allocate/free external memory */
78
int ffiAlloc(int byteSize);
81
/* general <=32bit integer loads */
82
int ffiPushSignedByte(int value);
83
int ffiPushUnsignedByte(int value);
84
int ffiPushSignedShort(int value);
85
int ffiPushUnsignedShort(int value);
86
int ffiPushSignedInt(int value);
87
int ffiPushUnsignedInt(int value);
88
int ffiPushBool(int value);
90
/* 64bit integer loads */
91
int ffiPushSignedLongLong(int lowWord, int highWord);
92
int ffiPushUnsignedLongLong(int lowWord, int highWord);
93
/* 64bit integer returns */
94
int ffiLongLongResultLow(void);
95
int ffiLongLongResultHigh(void);
97
/* special <=32bit loads */
98
int ffiPushSignedChar(int value);
99
int ffiPushUnsignedChar(int value);
102
int ffiPushSingleFloat(double value);
103
int ffiPushDoubleFloat(double value);
105
/* structure loads */
106
int ffiPushStructureOfLength(int pointer, int* structSpec, int specSize);
109
int ffiPushPointer(int pointer);
112
int ffiPushStringOfLength(int srcIndex, int length);
114
/* return true if calling convention is supported */
115
int ffiSupportsCallingConvention(int callType);
117
/* return true if these types can be returned */
118
int ffiCanReturn(int* structSpec, int specSize);
120
/* call the appropriate function w/ the given return type */
121
int ffiCallAddressOfWithPointerReturn(int fn, int callType);
122
int ffiCallAddressOfWithStructReturn(int fn, int callType,
123
int* structSpec, int specSize);
124
int ffiCallAddressOfWithReturnType(int fn, int callType, int typeSpec);
126
/* store the structure result of a previous call */
127
int ffiStoreStructure(int address, int structSize);
129
/* return the float value from a previous call */
130
double ffiReturnFloatValue(void);
132
/* The following are for creating, manipulating, and detroying "manual surfaces".
133
These are surfaces that are managed by Squeak code, which has manual control
134
over the memory location where the image data is stored (the pointer used may
135
be obtained via FFI calls, or other means).
137
Upon creation, no memory is allocated for the surface. Squeak code is
138
responsible for passing in a pointer to the memory to use. It is OK to set
139
the pointer to different values, or to NULL. If the pointer is NULL, then
140
BitBlt calls to ioLockSurface() will fail.
142
createManualFunction() returns a non-negative surface ID if successful, and
143
-1 otherwise. The other return true for success, and false for failure.
145
#include "../SurfacePlugin/SurfacePlugin.h"
146
void initManualSurfaceFunctionPointers(fn_ioRegisterSurface reg, fn_ioUnregisterSurface unreg, fn_ioFindSurface find);
147
int createManualSurface(int width, int height, int rowPitch, int depth, int isMSB);
148
int destroyManualSurface(int surfaceID);
149
int setManualSurfacePointer(int surfaceID, void* ptr);
151
#endif /* SQ_FFI_H */