cinvoke.h

Go to the documentation of this file.
00001 /*
00002 C/Invoke Source Code File
00003 
00004 Copyright (c) 2006 Will Weisser
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008 
00009    1. Redistributions of source code must retain the above copyright notice,
00010 this list of conditions and the following disclaimer.
00011    2. Redistributions in binary form must reproduce the above copyright notice,
00012 this list of conditions and the following disclaimer in the documentation
00013 and/or other materials provided with the distribution.
00014    3. The name of the author may not be used to endorse or promote products
00015 derived from this software without specific prior written permission.
00016 
00017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00018 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00020 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00021 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00022 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
00023 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026 POSSIBILITY OF SUCH DAMAGE.
00027 */
00028 #ifndef _CINVOKE_H
00029 #define _CINVOKE_H
00030 
00031 #include "cinvoke-arch.h"
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00114 typedef struct _CInvLibrary {
00115         ArchLibrary arch;
00116 } CInvLibrary;
00117 
00118 typedef struct _CInvFunction {
00119         cinv_callconv_t callconv;
00120         int hasreturn;
00121         cinv_type_t rettype;
00122         int numparms;
00123         int *parmstacksizes;
00124         int *parmalignments;
00125         int *parmmemsizes;
00126         cinv_type_t *parmtypes;
00127         short stacksize;
00128 } CInvFunction;
00129 
00139 typedef void (*cinv_cbfunc_t)(CInvFunction *f, void *parameters[],
00140         void *returnout, void *userdata);
00141 
00142 struct _CInvStructure;
00143 struct hashtable;
00144 
00145 typedef struct _CInvStructMember {
00146         struct _CInvStructure *structtype;
00147         cinv_type_t type;
00148         int offset;
00149         int alignment;
00150 } CInvStructMember;
00151 
00152 typedef struct _CInvStructure {
00153         struct hashtable *members;
00154         CInvStructMember *firstmember;
00155         int nextoffset;
00156         int finished;
00157 } CInvStructure;
00158 
00159 typedef struct _CInvCallback {
00160         CInvFunction *prototype;
00161         void *userdata;
00162         cinv_cbfunc_t cbfunc;
00163         char *stub;
00164 } CInvCallback;
00165 
00167 // public functions
00169 
00172 CInvContext *cinv_context_create();
00178 const char *cinv_context_geterrormsg(CInvContext *context);
00185 cinv_int32_t cinv_context_geterrorcode(CInvContext *context);
00190 cinv_status_t cinv_context_delete(CInvContext *context);
00191 
00199 CInvLibrary *cinv_library_create(CInvContext *context, const char *path);
00206 void *cinv_library_load_entrypoint(CInvContext *context,
00207         CInvLibrary *library, const char *name);
00213 cinv_status_t cinv_library_delete(CInvContext *context, CInvLibrary *library);
00214 
00252 CInvFunction *cinv_function_create(CInvContext *context,
00253         cinv_callconv_t callingconvention, const char *returnformat,
00254         const char *parameterformat);
00273 cinv_status_t cinv_function_invoke(CInvContext *context,
00274         CInvFunction *function, void *entrypoint, void *returnvalout,
00275         void *parameters[]);
00281 cinv_status_t cinv_function_delete(CInvContext *context,
00282         CInvFunction *function);
00283 
00288 CInvStructure *cinv_structure_create(CInvContext *context);
00296 cinv_status_t cinv_structure_addmember_value(CInvContext *context,
00297         CInvStructure *structure, const char *name, cinv_type_t type);
00308 cinv_status_t cinv_structure_addmember_struct(CInvContext *context,
00309         CInvStructure *structure, const char *name, CInvStructure *type);
00316 cinv_status_t cinv_structure_finish(CInvContext *context,
00317         CInvStructure *structure);
00325 cinv_status_t cinv_structure_getsize(CInvContext *context,
00326         CInvStructure *structure, int *size_out);
00332 void *cinv_structure_create_instance(CInvContext *context,
00333         CInvStructure *structure);
00348 cinv_status_t cinv_structure_instance_setvalue(CInvContext *context,
00349         CInvStructure *structure, void *instance, const char *name,
00350         void *value_ptr);
00365 void *cinv_structure_instance_getvalue(CInvContext *context,
00366         CInvStructure *structure, void *instance, const char *name);
00372 cinv_status_t cinv_structure_delete_instance(CInvContext *context,
00373         void *instance);
00380 cinv_status_t cinv_structure_delete(CInvContext *context,
00381         CInvStructure *structure);
00382 
00392 CInvCallback *cinv_callback_create(CInvContext *context,
00393         CInvFunction *prototype, void *userdata, cinv_cbfunc_t cbfunc);
00400 void *cinv_callback_getentrypoint(CInvContext *context,
00401         CInvCallback *callback);
00407 cinv_status_t cinv_callback_delete(CInvContext *context,
00408         CInvCallback *callback);
00411 #ifdef __cplusplus
00412 }
00413 #endif
00414 
00415 #endif

Generated on Sun Jul 2 23:50:42 2006 for C/Invoke by  doxygen 1.4.7