cinvoke-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cinvoke-svn] r29 - in trunk/cinvoke: . lib/arch


From: will
Subject: [cinvoke-svn] r29 - in trunk/cinvoke: . lib/arch
Date: 15 Jun 2006 23:04:04 -0400

Author: will
Date: 2006-06-15 23:04:03 -0400 (Thu, 15 Jun 2006)
New Revision: 29

Added:
   trunk/cinvoke/LICENSE.txt
   trunk/cinvoke/PORTING.txt
   trunk/cinvoke/TODO.txt
   trunk/cinvoke/lib/arch/empty_empty_empty.c
   trunk/cinvoke/lib/arch/empty_empty_empty.h
Removed:
   trunk/cinvoke/LICENSE
   trunk/cinvoke/TODO
Modified:
   trunk/cinvoke/lib/arch/cl_x86_win.c
   trunk/cinvoke/lib/arch/gcc_x86_unix.c
Log:
added helpful comments for porting


Deleted: trunk/cinvoke/LICENSE
===================================================================
--- trunk/cinvoke/LICENSE       2006-06-16 01:12:07 UTC (rev 28)
+++ trunk/cinvoke/LICENSE       2006-06-16 03:04:03 UTC (rev 29)
@@ -1,25 +0,0 @@
-C/Invoke Software Distribution
-
-Copyright (c) 2006 Will Weisser
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-   1. Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-   2. Redistributions in binary form must reproduce the above copyright notice,
-this list of conditions and the following disclaimer in the documentation
-and/or other materials provided with the distribution.
-   3. The name of the author may not be used to endorse or promote products
-derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.

Copied: trunk/cinvoke/LICENSE.txt (from rev 28, trunk/cinvoke/LICENSE)
===================================================================
--- trunk/cinvoke/LICENSE.txt                           (rev 0)
+++ trunk/cinvoke/LICENSE.txt   2006-06-16 03:04:03 UTC (rev 29)
@@ -0,0 +1,25 @@
+C/Invoke Software Distribution
+
+Copyright (c) 2006 Will Weisser
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+   2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+   3. The name of the author may not be used to endorse or promote products
+derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.

Added: trunk/cinvoke/PORTING.txt
===================================================================
--- trunk/cinvoke/PORTING.txt                           (rev 0)
+++ trunk/cinvoke/PORTING.txt   2006-06-16 03:04:03 UTC (rev 29)
@@ -0,0 +1,12 @@
+There are 4 steps (in general) to port C/Invoke to a new architecute:
+
+1) copy lib/arch/empty_empty_empty.c and .h to files named
+<compiler>_<cpu>_<os>.c and .h.  Add an entry to the main cinvoke-arch.h
+file to include your new file.
+2) Implement the new arch files.  Use the comments inside the empty files for
+guidance, the other arch files for examples, and the cinvoke-dev mailing list
+for help.
+3) Get the source building.  If your chosen platform has 'make', then you can
+make copies of the existing Makefiles and try to modify them.
+4) Get the test suite in the test/ directory running and spitting out the
+correct values.

Deleted: trunk/cinvoke/TODO
===================================================================
--- trunk/cinvoke/TODO  2006-06-16 01:12:07 UTC (rev 28)
+++ trunk/cinvoke/TODO  2006-06-16 03:04:03 UTC (rev 29)
@@ -1,4 +0,0 @@
-Developer documentation
-Public documentation
-Language binding(s)
-Website

Copied: trunk/cinvoke/TODO.txt (from rev 28, trunk/cinvoke/TODO)
===================================================================
--- trunk/cinvoke/TODO.txt                              (rev 0)
+++ trunk/cinvoke/TODO.txt      2006-06-16 03:04:03 UTC (rev 29)
@@ -0,0 +1,3 @@
+Public documentation
+Language binding(s)
+Website

Modified: trunk/cinvoke/lib/arch/cl_x86_win.c
===================================================================
--- trunk/cinvoke/lib/arch/cl_x86_win.c 2006-06-16 01:12:07 UTC (rev 28)
+++ trunk/cinvoke/lib/arch/cl_x86_win.c 2006-06-16 03:04:03 UTC (rev 29)
@@ -65,7 +65,6 @@
                
        library_out->dl = lib;
 
-       context_clear_error(context);
        return CINV_SUCCESS;
 }
 cinv_status_t arch_library_get_entrypoint(CInvContext *context,
@@ -78,7 +77,6 @@
 
        *entrypoint_out = sym;
 
-       context_clear_error(context);
        return CINV_SUCCESS;
 }
 cinv_status_t arch_library_delete(CInvContext *context, ArchLibrary *library) {
@@ -87,7 +85,6 @@
                return CINV_ERROR;
        }
 
-       context_clear_error(context);
        return CINV_SUCCESS;
 }
 const static int LEN = 4096;

Added: trunk/cinvoke/lib/arch/empty_empty_empty.c
===================================================================
--- trunk/cinvoke/lib/arch/empty_empty_empty.c                          (rev 0)
+++ trunk/cinvoke/lib/arch/empty_empty_empty.c  2006-06-16 03:04:03 UTC (rev 29)
@@ -0,0 +1,280 @@
+/*
+C/Invoke Source Code File
+
+Copyright (c) 2006 Will Weisser
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+   2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+   3. The name of the author may not be used to endorse or promote products
+derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+*/
+/*
+This is a skeleton arch .c file, with helpful comments.
+If more specific examples are needed, see the other
+files in this directory.
+*/
+
+#ifdef CINVOKE_BUILD
+#include "../cinvoke.h"
+#include "../cinvoke-private.h"
+#else
+#include "cinvoke.h"
+#include "cinvoke-private.h"
+#endif
+
+void arch_free_errstr(char *str) {
+       // TODO: free the given error string.  Note that some archs
+       // don't allocate errors on the heap and can leave this blank.
+}
+
+cinv_status_t arch_library_create(CInvContext *context, const char *path,
+       ArchLibrary *library_out) {
+       // TODO: load the shared library given by 'path' and store in
+       // the library_out structure.  The below example is for
+       // UNIX.  Note that the error is set in the context
+       // before returning CINV_ERROR.
+       /*void *dl = dlopen(path, RTLD_LAZY);
+       if (!dl) {
+               context_set_error(context, -1, (char*)dlerror(), 0);
+               return CINV_ERROR;
+       }
+               
+       library_out->dl = dl;
+
+       return CINV_SUCCESS;*/
+}
+cinv_status_t arch_library_get_entrypoint(CInvContext *context,
+       ArchLibrary *library, const char *name, void **entrypoint_out) {
+       // TODO: load an entrypoint from the given shared library.  Again,
+       // example below from UNIX.
+
+       /*void *sym = dlsym(library->dl, name);
+       if (!sym) {
+               context_set_error(context, -1, (char*)dlerror(), 0);
+               return CINV_ERROR;
+       }
+
+       *entrypoint_out = sym;
+
+       return CINV_SUCCESS;*/
+}
+cinv_status_t arch_library_delete(CInvContext *context, ArchLibrary *library) {
+       // TODO: delete the library handle and any entrypoints associated with
+       // it.
+       /*if (dlclose(library->dl)) {
+               context_set_error(context, -1, (char*)dlerror(), 0);
+               return CINV_ERROR;
+       }
+
+       return CINV_SUCCESS;*/
+}
+
+//const static int LEN = 4096;
+
+char *arch_callback_stub(void *functionp, void *param,
+       short stacksize, cinv_callconv_t cc) {
+       // TODO: this function returns a chunk of executable memory
+       // which contains a compiled function.  This compiled function
+       // performs one task: call the function pointed to by functionp,
+       // passing it the argument param.  The cc parameter specifies
+       // the calling convention that the compiled function will need
+       // to follow.  The stacksize parameter indicates the size of the
+       // "true" stack being passed to the function, which is used by
+       // calling conventions (such as Windows stdcall) to clean up 
+       // their own stacks.
+
+       // in the example below, the function:
+       // void f() { ((void (*)(void *))0xAAAAAAAA)((void *)0xBBBBBBBB); }
+       // was compiled, loaded in gdb, and then memory dumped to produce
+       // the base string value given below.  This string value is then
+       // modified to replace the placeholder values with the given
+       // parameters.  
+       
+/*     char *ret = mmap(0, LEN, PROT_EXEC|PROT_READ|PROT_WRITE,
+               MAP_ANON|MAP_PRIVATE, -1, 0);
+       if (ret == MAP_FAILED)
+               return NULL;
+       
+       // void f() { ((void (*)(void *))0xAAAAAAAA)((void *)0xBBBBBBBB); }
+       memcpy(ret,
+               "\x55\x89\xe5\x83\xec\x08\x83\xec\x0c\x68"
+               "\xbb\xbb\xbb\xbb\xb8\xaa\xaa\xaa\xaa\xff"
+               "\xd0\x83\xc4\x10\xc9\xc3",
+               26);
+
+       memcpy(ret + 10, &param, 4);
+       memcpy(ret + 15, &functionp, 4);
+       
+       return ret;*/
+}
+void arch_free_stub(char *stub) {
+       // TODO: "free" the memory returned by arch_callback_stub
+       /*munmap(stub, LEN);*/
+}
+
+int arch_is_register_parm(cinv_callconv_t callingconvention, int index,
+       int num_params, cinv_type_t types[]) {
+       // TODO: given the calling convention, the index (zero-based) of
+       // a parameter, the total number of parameters and the types of
+       // all the parameters, return 1 if the parameter at said index needs
+       // to be passed in a register in the given calling convention, or 0
+       // if it should be passed on the stack.
+       /*return 0;*/
+}
+void arch_set_register_parms(ArchRegParms *regparms, 
+       cinv_callconv_t callingconvention, int num_params, void *parameters[], 
+       cinv_type_t types[]) {
+       // TODO: given the parameter values pointed to by the pointers in
+       // the 'parameters' array, copy the ones which need to be passed in
+       // registers into the regparms structure.
+}
+void arch_get_register_parms(ArchRegParms *regparms,
+       cinv_callconv_t callingconvention, int num_params, void 
*parameters_out[],
+       cinv_type_t types[]) {
+       // TODO: this does the opposite of arch_get_register_parms; copy the
+       // values in the regparms structure into the memory pointed to by the
+       // pointers in the parameters_out array.  The array will already contain
+       // pointers to memory areas which are allocated with a size large enough
+       // to contain the corresponding types from the 'types' array.  
+}
+
+// TODO: the following eight functions marshal return values
+// from the given structure and return them for different
+// types.  The x86 implementation is provided for reference
+void arch_getval_char(ArchRetValue *archval, char *outval) {
+       *outval = archval->ivallow;
+}
+void arch_getval_short(ArchRetValue *archval, short *outval) {
+       *outval = archval->ivallow;
+}
+void arch_getval_int(ArchRetValue *archval, int *outval) {
+       *outval = archval->ivallow;
+}
+void arch_getval_long(ArchRetValue *archval, long int *outval) {
+       *outval = archval->ivallow;
+}
+void arch_getval_extralong(ArchRetValue *archval, long long int *outval) {
+       *outval = archval->ivalhigh;
+       *outval <<= 32;
+       *outval |= archval->ivallow;
+}
+void arch_getval_float(ArchRetValue *archval, float *outval) {
+       *outval = (float)archval->dval;
+}
+void arch_getval_double(ArchRetValue *archval, double *outval) {
+       *outval = archval->dval;
+}
+void arch_getval_ptr(ArchRetValue *archval, void **outval) {
+       *outval = (void *)archval->ivallow;
+}
+
+// TODO: These eight functions do the opposite; set a return
+// of a specific type in the archval structure.
+// Again, the x86 implementation is provided for reference
+void arch_setval_char(ArchRetValue *archval, char val) {
+       archval->ivallow = val;
+}
+void arch_setval_short(ArchRetValue *archval, short val) {
+       archval->ivallow = val;
+}
+void arch_setval_int(ArchRetValue *archval, int val) {
+       archval->ivallow = val;
+}
+void arch_setval_long(ArchRetValue *archval, long int val) {
+       archval->ivallow = val;
+}
+void arch_setval_extralong(ArchRetValue *archval, long long int val) {
+       archval->ivalhigh = (val >> 32);
+       archval->ivallow = val;
+}
+void arch_setval_float(ArchRetValue *archval, float val) {
+       archval->dval = val;
+}
+void arch_setval_double(ArchRetValue *archval, double val) {
+       archval->dval = val;
+}
+void arch_setval_ptr(ArchRetValue *archval, void *val) {
+       archval->ivallow = (int)val;
+}
+
+// TODO: Finally, these eight functions give the sizes
+// and alignments for different types.  Two sizes and
+// alignments are given, one for the stack when passing
+// parameters, and one for values inside a structure
+// (for an automatic or heap variable).  It is important
+// to differentiate these; for example, on x86, a char
+// takes up 1 byte in a struct but is pushed on the stack
+// as 4 bytes when passed as an argument.  Also, gcc for x86
+// aligns 8-byte integers on a 4-byte boundary in structures,
+// but Microsoft cl aligns them on an 8-byte boundary.  If you
+// do not set either stackalign_out or structalign_out, then
+// they are implcitly assumed to be 1.
+
+// Incidentally, the best way to determine these values
+// (and just about everything else in this file and the header)
+// is not by consulting docs but by writing test programs, and
+// using your C compiler to dump them to assembly.
+void arch_size_char(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 4;
+       *structsize_out = 1;
+}
+void arch_size_short(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 4;
+       *structsize_out = 2;
+       *structalign_out = 2;
+}
+void arch_size_int(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 4;
+       *structsize_out = 4;
+       *structalign_out = 4;
+}
+void arch_size_long(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 4;
+       *structsize_out = 4;
+       *structalign_out = 4;
+}
+void arch_size_extralong(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 8;
+       *structsize_out = 8;
+       *structalign_out = 4;
+}
+void arch_size_float(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 4;
+       *structsize_out = 4;
+       *structalign_out = 4;
+}
+void arch_size_double(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 8;
+       *structsize_out = 8;
+       *structalign_out = 4;
+}
+void arch_size_ptr(int *stacksize_out, int *structsize_out,
+       int *stackalign_out, int *structalign_out) {
+       *stacksize_out = 4;
+       *structsize_out = 4;
+       *structalign_out = 4;
+}

Added: trunk/cinvoke/lib/arch/empty_empty_empty.h
===================================================================
--- trunk/cinvoke/lib/arch/empty_empty_empty.h                          (rev 0)
+++ trunk/cinvoke/lib/arch/empty_empty_empty.h  2006-06-16 03:04:03 UTC (rev 29)
@@ -0,0 +1,169 @@
+/*
+C/Invoke Source Code File
+
+Copyright (c) 2006 Will Weisser
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+   2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+   3. The name of the author may not be used to endorse or promote products
+derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+This is a skeleton arch .h file, with helpful comments.
+If more specific examples are needed, see the other
+files in this directory.
+*/
+
+// TODO: replace these with symbols for your architecture
+#ifndef _EMPTY_EMPTY_EMPTY_H
+#define _EMPTY_EMPTY_EMPTY_H
+
+// This structure represents the arch-specific portion of
+// a shared library.  Most architectures will only need to
+// store a void* here.
+typedef struct _ArchLibrary {
+       // TODO
+} ArchLibrary;
+
+// This structure holds values which will be or have been
+// returned from a function call.  For example, on x86,
+// return values can be in the eax, eax and edx, or st(0)
+// registers.  This structure on that architecture contains
+// two integers and a double, so that the values of all
+// registers can be placed into it without clobbering
+// each other.
+typedef struct _ArchRetValue {
+       // TODO
+} ArchRetValue;
+
+// This structure holds parameters which can be passed in
+// registers.  For example if an arch's calling convention
+// specified a maximum of seven input registers to pass
+// arguments in in addition to the stack, then this struct
+// should have seven ints
+typedef struct _ArchRegParms {
+       // TODO
+} ArchRegParms;
+
+// TODO: define these to be correct for your arch. The
+// examples given here are for most 32-bit machines.
+typedef char cinv_int8_t;
+typedef short cinv_int16_t;
+typedef int cinv_int32_t;
+typedef long long cinv_int64_t; 
+
+// TODO: these are constants used to provide error
+// messages/codes. The CINV_NOMEM_NEEDSFREE value determines
+// if C/Invoke will call arch_free_errstr on the returned
+// CINV_S_NOMEM string value.  In the examples given below
+// from UNIX, the answer is 0 since strerror returns a
+// constant.
+#define CINV_E_NOMEM (ENOMEM)
+#define CINV_S_NOMEM (strerror(ENOMEM))
+#define CINV_NOMEM_NEEDSFREE 0
+#define CINV_E_INVAL (EINVAL)
+
+// TODO: this sets the default calling convention.  most
+// archs only have one, so just add it to the cinv_cc_t enum
+// and use that.
+#define CINV_CC_DEFAULT CINV_CC_CDECL 
+
+// TODO: set these similarly to the cinv_int*_t types above
+#define CINV_T_2BYTE CINV_T_SHORT
+#define CINV_T_4BYTE CINV_T_INT
+#define CINV_T_8BYTE CINV_T_EXTRALONG
+
+/////////////////////////////////////
+// macros
+/////////////////////////////////////
+
+// the following examples are given
+// for x86 in MASM syntax.  Some of these
+// macros might not need to be implemented
+// in inline assembly, depending on the arch,
+// but likely most of them will.
+
+// this macro stores the values in the input
+// registers in the ArchRegParms structure passed as 'regparms'.
+// In the example below we store ecx and edx because
+// they are used in the fastcall convention to pass
+// parameters.
+#define ARCH_SAVE_REGPARMS(regparms) \
+       __asm mov [(regparms).first], ecx \
+       __asm mov [(regparms).second], edx // TODO: fix this for your arch
+
+// this macro does two things: copies the values
+// stored in regparms into the input registers,
+// and calls the function pointed to by the pointer
+// ep.
+#define ARCH_CALL(regparms, ep) \
+       __asm mov ecx, [(regparms).first] \
+       __asm mov edx, [(regparms).second] \
+       __asm call dword ptr [ep] // TODO: fix this for your arch
+
+// saves any possible return values in the ArchRetValue
+// structure given by archvalue.
+#define ARCH_SAVE_RETURN(archvalue) \
+       __asm mov [(archvalue).ivallow], eax \
+       __asm mov [(archvalue).ivalhigh], edx \
+       __asm fstp [(archvalue).dval] // TODO: fix this for your arch
+
+// stores the return values in the ArchRetValue structure
+// into any place where a caller might expect to find them
+#define ARCH_SET_RETURN(archvalue) \
+       __asm mov eax, [(archvalue).ivallow] \
+       __asm mov edx, [(archvalue).ivalhigh] \
+       __asm fld [(archvalue).dval] // TODO: fix this for your arch
+
+// increases the stack size by bcount bytes
+#define ARCH_PUT_STACK_BYTES(bcount) \
+       __asm sub esp, bcount; // TODO: fix this for your arch
+
+// decreases the stack size by bcount bytes
+#define ARCH_REMOVE_STACK_BYTES(bcount) \
+       __asm add esp, bcount; // TODO: fix this for your arch
+
+// copies the current stack pointer into the pointer variable
+// stackp
+#define ARCH_GET_STACK(stackp) \
+       __asm mov stackp, esp; // TODO: fix this for your arch
+
+// copies the current frame pointer into the pointer variable
+// framep
+#define ARCH_GET_FRAME_PTR(framep) \
+       __asm mov framep, ebp; // TODO: fix this for your arch
+
+// TODO: This is the number of bytes up the stack
+// from the frame pointer at which cinv_cbthunk can
+// start looking for argument values.  The easiest
+// way to determine this value is to run the test
+// program under a debugger, set a breakpoint in
+// cinv_cbthunk, look at the memory at the frame
+// pointer, then start counting bytes upwards until
+// you see where the first argument is stored.
+#define ARCH_CALLBACK_ARG_OFFSET (96)
+
+// TODO: Whether the stack grows larger as the
+// stack pointer gets numerically smaller.  Set to 1 on
+// x86.
+#define ARCH_STACK_GROWS_DOWN 1
+
+#endif

Modified: trunk/cinvoke/lib/arch/gcc_x86_unix.c
===================================================================
--- trunk/cinvoke/lib/arch/gcc_x86_unix.c       2006-06-16 01:12:07 UTC (rev 28)
+++ trunk/cinvoke/lib/arch/gcc_x86_unix.c       2006-06-16 03:04:03 UTC (rev 29)
@@ -53,7 +53,6 @@
                
        library_out->dl = dl;
 
-       context_clear_error(context);
        return CINV_SUCCESS;
 }
 cinv_status_t arch_library_get_entrypoint(CInvContext *context,
@@ -66,7 +65,6 @@
 
        *entrypoint_out = sym;
 
-       context_clear_error(context);
        return CINV_SUCCESS;
 }
 cinv_status_t arch_library_delete(CInvContext *context, ArchLibrary *library) {
@@ -75,7 +73,6 @@
                return CINV_ERROR;
        }
 
-       context_clear_error(context);
        return CINV_SUCCESS;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]