dotgnu-pnet-commits
[Top][All Lists]
Advanced

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

[Dotgnu-pnet-commits] CVS: pnet/coremul .cvsignore,NONE,1.1 Makefile.am


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/coremul .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 README,NONE,1.1 cocreate.cpp,NONE,1.1 cor.h,NONE,1.1 corhdr.h,NONE,1.1 corole2.h,NONE,1.1 corwin32.h,NONE,1.1 corwinerror.h,NONE,1.1 guid.cpp,NONE,1.1 shim.c,NONE,1.1
Date: Thu, 13 Feb 2003 00:24:47 -0500

Update of /cvsroot/dotgnu-pnet/pnet/coremul
In directory subversions:/tmp/cvs-serv13903a/coremul

Added Files:
        .cvsignore Makefile.am README cocreate.cpp cor.h corhdr.h 
        corole2.h corwin32.h corwinerror.h guid.cpp shim.c 
Log Message:


Begin implementation of the mscoree.dll emulation routines.


--- NEW FILE ---
Makefile
Makefile.in
.deps

--- NEW FILE ---

lib_LIBRARIES = libILCorEmul.a

libILCorEmul_a_SOURCES = cocreate.cpp \
                                                 guid.cpp \
                                                 shim.c

AM_CFLAGS = -I$(top_srcdir)/include

--- NEW FILE ---

This directory will eventually contain an implementation of the
"mscoree.dll" shim, plus an emulation of Microsoft's metadata API's.

The shim is used to dynamically select a runtime engine to be
executed under Win32 systems.

The metadata API implementation is provided to assist Free Software
implementors port their code from dependence upon Windows.

The source is under the terms of the GNU General Public License,
with the following small exception: the shim may be used to automatically
launch an IL executable with no requirement to put the executable under
the terms of the GPL.

However, an application that uses the metadata emulation routines, or
which attempts to use the shim to embed the runtime engine in an unmanaged
application, must be placed under a license that is compatible with the
terms of the GPL.  This restriction is necessary to prevent circumvention
of the GPL on the core Portable.NET code.

--- NEW FILE ---
/*
 * cocreate.cpp - Create COM object instances.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "corwin32.h"

/*
 * If the platform is Win32, then we don't need to implement this.
 */
#ifndef _COR_REAL_WIN32

EXTERN_C STDMETHODIMP CoCreateInstance
                        (const CLSID *rclsid, const IID *riid, void **ppv)
{
        // TODO
        return RESULT(CLASS_E_CLASSNOTAVAILABLE);
}

#endif /* !_COR_REAL_WIN32 */

--- NEW FILE ---
/*
 * cor.h - Emulation of the "mscoree.dll" interface.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _COR_H_
#define _COR_H_

/*
 * Include the OLE2 definitions that we need to do COM-like things.
 */
#include "corole2.h"

/*
 * Include the common header structures and definitions.
 */
#include "corhdr.h"

/*
 * Define the C API's.
 */
#ifdef __cplusplus
extern "C" {
#endif

/*
 * Define the name of the execution engine.
 */
#ifdef _COR_REAL_WIN32
        #define MSCOREE_SHIM_W          L"mscoree.dll"
        #define MSCOREE_SHIM_A          "mscoree.dll"
#else
        #define MSCOREE_SHIM_W          L"libmscoree.so"
        #define MSCOREE_SHIM_A          "libmscoree.so"
#endif

/*
 * Flags for "CoInitializeEE".
 */
typedef enum tagCOINITEE
{
        COINITEE_DEFAULT = 0,
        COINITEE_DLL     = 1,
        COINITEE_MAIN    = 2

} COINITIEE;

/*
 * Flags for "CoUninitializeEE".
 */
typedef enum tagCOUNINITEE
{
        COUNINITEE_DEFAULT = 0,
        COUNINITEE_DLL     = 1

} COUNINITIEE;

/*
 * Flags for "CoInitializeCor".
 */
typedef enum tagCOINITCOR
{
        COINITCOR_DEFAULT = 0

} COINITICOR;

/*
 * Initialize the execution engine.
 */
STDAPI CoInitializeEE(DWORD fFlags);

/*
 * Uninitialize the execution engine.
 */
STDAPI_(void) CoUninitializeEE(BOOL fFlags);

/*
 * Shutdown the COM routines that are used by the execution engine.
 */
STDAPI_(void) CoEEShutDownCOM(void);

/*
 * Entry point into the library that is called by a ".dll".
 */
BOOL STDMETHODCALLTYPE _CorDllMain
                (HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved);

/*
 * Entry point into the library that is called by a ".exe".
 */
__int32 STDMETHODCALLTYPE _CorExeMain(void);

/*
 * Internal version of the ".exe" entry point.
 */
__int32 STDMETHODCALLTYPE _CorExeMain2(PBYTE  pUnmappedPE,
                                                                           
DWORD  cUnmappedPE,
                                                                           
LPWSTR pImageNameIn,
                                                                           
LPWSTR pLoadersFileName,
                                                                           
LPWSTR pCmdLine);

/*
 * Validate an image.  Returns a HRESULT.
 */
STDAPI _CorValidateImage(PVOID *ImageBase, LPCSTR FileName);

/*
 * Notify the library of an image unload.
 */
STDAPI_(void) _CorImageUnloading(PVOID ImageBase);

/*
 * Higher-level common language runtime initialization.
 */
STDAPI CoInitializeCor(DWORD fFlags);

/*
 * Higher-level common language runtime termination.
 */
STDAPI_(void) CoUninitializeCor(void);

/*
 * Add a destructor callback for a specific CPU exception code.
 */
typedef void (*TDestructorCallback)(EXCEPTION_RECORD *);
STDAPI_(void) AddDestructorCallback(int code, TDestructorCallback cb);

#ifdef __cplusplus
};
#endif

/*
 * Define the C++ API's.
 */
#ifdef __cplusplus

/*
 * Determine if an element type is a modifier.
 */
_cor_inline int CorIsModifierElementType(CorElementType type)
{
        if(type == ELEMENT_TYPE_BYREF || type == ELEMENT_TYPE_PTR)
        {
                return 1;
        }
        else
        {
                return (type & ELEMENT_TYPE_MODIFIER);
        }
}

/*
 * Determine if an element type is primitive.
 */
_cor_inline int CorIsPrimitiveType(CorElementType type)
{
        return (type < ELEMENT_TYPE_PTR);
}

/*
 * Get the uncompressed size of a metadata-encoded value.
 */
inline ULONG CorSigUncompressDataSize(PBYTE value)
{
        register int lead = value[0];
        if((lead & 0x80) == 0)
        {
                return 1;
        }
        else if((lead & 0xC0) == 0x80)
        {
                return 2;
        }
        else
        {
                return 4;
        }
}

#endif /* __cplusplus */

#endif /* _COR_H */

--- NEW FILE ---
/*
 * corhdr.h - Metadata structure definitions.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
[...1497 lines suppressed...]
#define INTEROP_TYPELIBFUNC_TYPE_W      \
                        L"System.Runtime.InteropServices.TypeLibFuncAttribute"

#define INTEROP_TYPELIBTYPE_SIG \
                        {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, \
                         ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
#define INTEROP_TYPELIBTYPE_TYPE        \
                        "System.Runtime.InteropServices.TypeLibTypeAttribute"
#define INTEROP_TYPELIBTYPE_TYPE_W      \
                        L"System.Runtime.InteropServices.TypeLibTypeAttribute"

#define INTEROP_TYPELIBVAR_SIG  \
                        {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, \
                         ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
#define INTEROP_TYPELIBVAR_TYPE \
                        "System.Runtime.InteropServices.TypeLibVarAttribute"
#define INTEROP_TYPELIBVAR_TYPE_W       \
                        L"System.Runtime.InteropServices.TypeLibVarAttribute"

#endif /* __CORHDR_H__ */

--- NEW FILE ---
/*
 * corole2.h - Emulate enough OLE2 infrastructure to fool non-Win32 systems.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __COROLE2_H__
#define __COROLE2_H__

#include "corwin32.h"

#ifdef  __cplusplus
extern  "C"     {
#endif

#ifdef _COR_REAL_WIN32

#include <ole2.h>

#else /* !_COR_REAL_WIN32 */

/*
 * Declare the IUnknown interface.
 */
EXTERN_C const IID IID_IUnknown;
#ifndef __IUnknown_INTERFACE_DEFINED__
#define __IUnknown_INTERFACE_DEFINED__
#undef INTERFACE
#define INTERFACE       IUnknown
DECLARE_INTERFACE(IUnknown)
{
        STDMETHOD(QueryInterface)(THIS_ REFIID, PVOID *) PURE;
        STDMETHOD_(ULONG,AddRef)(THIS) PURE;
        STDMETHOD_(ULONG,Release)(THIS) PURE;
};
typedef IUnknown *LPUNKNOWN;
#endif

/*
 * Declare the IClassFactory interface.
 */
EXTERN_C const IID IID_IClassFactory;
#ifndef __IClassFactory_INTERFACE_DEFINED__
#define __IClassFactory_INTERFACE_DEFINED__
#undef INTERFACE
#define INTERFACE       IClassFactory
DECLARE_INTERFACE_(IClassFactory,IUnknown)
{
        STDMETHOD(QueryInterface)(THIS_ REFIID, PVOID *) PURE;
        STDMETHOD_(ULONG,AddRef)(THIS) PURE;
        STDMETHOD_(ULONG,Release)(THIS) PURE;
        STDMETHOD(CreateInstance)(THIS_ LPUNKNOWN, REFIID, PVOID *) PURE;
        STDMETHOD(LockServer)(THIS_ BOOL) PURE;
};
typedef IClassFactory *LPCLASSFACTORY;
#endif

/*
 * C interface for calling methods on IUnknown and IClassFactory.
 */
#ifdef  COBJMACROS
#define IUnknown_QueryInterface(T,r,O)  \
                        (T)->lpVtbl->QueryInterface((T),(r),(O))
#define IUnknown_AddRef(T)      (T)->lpVtbl->AddRef((T))
#define IUnknown_Release(T)     (T)->lpVtbl->Release((T))
#define IClassFactory_QueryInterface(T,r,O)     \
                        (T)->lpVtbl->QueryInterface((T),(r),(O))
#define IClassFactory_AddRef(T)         (T)->lpVtbl->AddRef((T))
#define IClassFactory_Release(T)        (T)->lpVtbl->Release((T))
#define IClassFactory_CreateInstance(T,p,r,O)   \
                        (T)->lpVtbl->CreateInstance((T),(p),(r),(O))
#define IClassFactory_LockServer(T,f)   \
                        (T)->lpVtbl->LockServer((T),(f))
#endif

#endif /* !_COR_REAL_WIN32 */

/*
 * Determine how to force a definition inline in C++ code.
 */
#if defined(__GNUC__)
        #define _cor_inline             inline
#else
        #ifndef FORCEINLINE
                #if _MSC_VER < 1200
                        #define _cor_inline inline
                #else
                        #define _cor_inline __forceinline
                #endif
        #else
                #define _cor_inline FORCEINLINE
        #endif
#endif

#ifdef  __cplusplus
};
#endif

#endif /* __COROLE2_H__ */

--- NEW FILE ---
/*
 * corwin32.h - Emulate enough Win32 types to fool non-Win32 systems.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __CORWIN32_H__
#define __CORWIN32_H__

#ifdef  __cplusplus
extern  "C"     {
#endif

/*
 * Determine if we are building on a real Win32 system or not.
 */
#if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__)
        #include <windows.h>
        #define _COR_REAL_WIN32 1
#endif

#ifndef _COR_REAL_WIN32

/*
 * Get common definitions such as NULL and wchar_t.
 */
#include <stdio.h>
#include <stddef.h>
#include <wchar.h>

/*
 * Include Windows error codes.
 */
#include "corwinerror.h"

/*
 * Defining API function prototypes.
 */
#ifndef IN
#define IN
#endif
#ifndef OUT
#define OUT
#endif
#ifndef OPTIONAL
#define OPTIONAL
#endif
#ifndef PACKED
#define PACKED
#endif
#ifndef _stdcall
#define _stdcall
#endif
#ifndef __stdcall
#define __stdcall
#endif
#ifndef _cdecl
#define _cdecl
#endif
#ifndef __cdecl
#define __cdecl
#endif
#ifndef __declspec
#define __declspec(x)
#endif
#ifndef _declspec
#define _declspec(x)
#endif
#ifndef pascal
#define pascal
#endif
#ifndef _pascal
#define _pascal
#endif
#ifndef __pascal
#define __pascal
#endif
#ifndef PASCAL
#define PASCAL  __pascal
#endif
#ifndef CDECL
#define CDECL   __cdecl
#endif
#ifndef STDCALL
#define STDCALL __stdcall
#endif
#ifndef WINAPI
#define WINAPI  __stdcall
#endif
#ifndef WINAPIV
#define WINAPIV __cdecl
#endif
#ifndef APIENTRY
#define APIENTRY __stdcall
#endif
#ifndef CALLBACK
#define CALLBACK __stdcall
#endif
#ifndef APIPRIVATE
#define APIPRIVATE __stdcall
#endif
#ifndef DECLSPEC_IMPORT
#define DECLSPEC_IMPORT
#endif
#ifndef DECLSPEC_EXPORT
#define DECLSPEC_EXPORT
#endif
#ifndef DECLSPEC_NORETURN
#define DECLSPEC_NORETURN
#endif
#ifndef DECLARE_STDCALL_P
#define DECLARE_STDCALL_P(type) type __stdcall
#endif
#ifndef _export
#define _export
#endif
#ifndef __export
#define __export
#endif

/*
 * Define the basic Win32 types.
 */
#if !defined(NO_STRICT) && !defined(STRICT)
#define STRICT  1
#endif
#ifndef TRUE
#define TRUE    1
#endif
#ifndef FALSE
#define FALSE   0
#endif
#ifndef VOID
#define VOID                    void
#endif
#ifndef CONST
#define CONST                   const
#endif
typedef int                             WINBOOL, *PWINBOOL, *LPWINBOOL;
typedef int                             BOOL, *PBOOL, *LPBOOL;
typedef char                    CHAR, CCHAR, *PCHAR, *LPCHAR, *PCH, *LPCH;
typedef unsigned char   BYTE, *PBYTE, *LPBYTE;
typedef unsigned char   UCHAR, *PUCHAR, *LPUCHAR;
typedef wchar_t                 WCHAR, *PWCHAR, *LPWCHAR, *PWCH, *LPWCH;
#ifdef UNICODE
typedef WCHAR                   TCHAR, _TCHAR;
#else
typedef CHAR                    TCHAR, _TCHAR;
#endif
typedef short                   SHORT, *PSHORT, *LPSHORT;
typedef unsigned short  USHORT, *PUSHORT, *LPUSHORT;
typedef unsigned short  WORD, *PWORD, *LPWORD;
typedef unsigned long   DWORD, *PDWORD, *LPDWORD;
typedef long                    LONG, *PLONG, *LPLONG;
typedef unsigned long   ULONG, *PULONG, *LPULONG;
typedef int                             INT, *PINT, *LPINT;
typedef unsigned int    UINT, *PUINT, *LPUINT;
typedef float                   FLOAT, *PFLOAT, *LPFLOAT;
typedef void               *PVOID, *LPVOID;
typedef CONST void         *PCVOID, *LPCVOID;
typedef UINT                    WPARAM;
typedef LONG                    LPARAM, LRESULT;
#ifndef _HRESULT_DEFINED
#define _HRESULT_DEFINED
typedef LONG                    HRESULT;
#endif
typedef WORD                    ATOM;
typedef void               *HANDLE;
typedef HANDLE             *PHANDLE, *LPHANDLE;
#ifndef STRICT
#define DECLARE_HANDLE(name)    typedef struct name##__ { int i } *name
#else
#define DECLARE_HANDLE(name)    typedef HANDLE name
#endif
typedef int (WINAPI *FARPROC)();
typedef int (WINAPI *NEARPROC)();
typedef int (WINAPI *PROC)(), *NPCSTR;
typedef char *PSZ;
typedef WCHAR *PWSTR, *LPWSTR, *NWPSTR;
typedef CONST WCHAR *PCWSTR, *LPCWSTR, *PCWCH, *LPCWCH;
typedef CHAR *PSTR, *LPSTR, *NPSTR;
typedef CONST CHAR *PCSTR, *LPCSTR;
typedef TCHAR TBYTE, *PTSTR, *LPTSTR, *PTCH, *LPTCH, *PTBYTE, *LP, *PTCHAR;
typedef CONST TCHAR *PCTSTR, *LPCTSTR;
typedef DWORD LCID, PLCID;
DECLARE_HANDLE(HINSTANCE);

/*
 * Types with specific sizes.
 */
typedef int __int32;
typedef unsigned long ULONG32;

/*
 * Useful PE file section types.
 */
typedef struct _IMAGE_DATA_DIRECTORY
{
        DWORD   VirtualAddress;
        DWORD   Size;

} IMAGE_DATA_DIRECTORY;

/*
 * Manipulate words.
 */
#define MAKEWORD(a,b)   ((WORD)(((BYTE)(a)) |(((WORD)((BYTE)(b)))<<8)))
#define MAKELONG(a,b)   ((LONG)(((WORD)(a)) |(((DWORD)((WORD)(b)))<<16)))
#define LOWORD(l)               ((WORD)((DWORD)(l)))
#define HIWORD(l)               ((WORD)((((DWORD)(l)) >> 16) & 0xFFFF))
#define LOBYTE(w)               ((BYTE)((w)))
#define HIBYTE(w)               ((BYTE)((((WORD)(w)) >> 8) & 0xFF))

/*
 * Structured C exceptions.
 */
#define __try
#define __except(x)     if (0)
#define __finally
#define _try            __try
#define _except(x)      __except((x))
#define _finally        __finally
#define EXCEPTION_MAXIMUM_PARAMETERS    15
typedef struct _EXCEPTION_RECORD
{
        DWORD ExceptionCode, ExceptionFlags;
        struct _EXCEPTION_RECORD *ExceptionRecord;
        PVOID ExceptionAddress;
        DWORD NumberParameters;
        DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];

} EXCEPTION_RECORD, *PEXCEPTION_RECORD;

/*
 * COM-style function and interface declarations.
 */
#ifndef EXTERN_C
#ifdef  __cplusplus
#define EXTERN_C        extern "C"
#else
#define EXTERN_C        extern
#endif
#endif
#define STDMETHODCALLTYPE               __stdcall
#define STDMETHODVCALLTYPE              __cdecl
#define STDAPICALLTYPE                  __stdcall
#define STDAPIVCALLTYPE                 __cdecl
#define STDAPI                                  EXTERN_C HRESULT STDAPICALLTYPE
#define STDAPI_(type)                   EXTERN_C type STDAPICALLTYPE
#define STDAPIV                                 EXTERN_C HRESULT STDAPIVCALLTYPE
#define STDAPIV_(type)                  EXTERN_C type STDAPIVCALLTYPE
#define STDMETHODIMP                    HRESULT STDMETHODCALLTYPE
#define STDMETHODIMP_(type)             type STDMETHODCALLTYPE
#define STDMETHODIMPV                   HRESULT STDMETHODVCALLTYPE
#define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
#define interface                               struct
#ifdef __cplusplus
#define STDMETHOD(m)                    virtual HRESULT STDMETHODCALLTYPE m
#define STDMETHOD_(type,m)              virtual type STDMETHODCALLTYPE m
#define PURE                                    =0
#define THIS_
#define THIS                                    void
#else
#define STDMETHOD(m)                    HRESULT (STDMETHODCALLTYPE *m)
#define STDMETHOD_(type,m)              type (STDMETHODCALLTYPE *m)
#define PURE
#define THIS_                                   INTERFACE *,
#define THIS                                    INTERFACE *
#ifndef CONST_VTABLE
#define CONST_VTABLE
#endif
#endif
#if defined(__cplusplus) && !defined(CINTERFACE)
#define DECLARE_INTERFACE(i)    interface i
#define DECLARE_INTERFACE_(i,b) interface i : public b
#define IENUM_THIS_(T)
#define IENUM_THIS(T)
#else
#define DECLARE_INTERFACE(i)    \
                        typedef interface i { CONST_VTABLE struct i##Vtbl 
*lpVtbl; } i; \
                        typedef CONST_VTABLE struct i##Vtbl i##Vtbl; \
                        CONST_VTABLE struct i##Vtbl
#define DECLARE_INTERFACE_(i,b) DECLARE_INTERFACE(i)
#define IENUM_THIS_(T)                  T *,
#define IENUM_THIS(T)                   T *
#endif
#define BEGIN_INTERFACE
#define END_INTERFACE
#define FWD_DECL(i)                             typedef interface i i
#define DECLARE_ENUMERATOR_(I,T)        \
DECLARE_INTERFACE_(I,IUnknown) \
{ \
        STDMETHOD(QueryInterface)(IENUM_THIS_(I) REFIID, PVOID*) PURE; \
        STDMETHOD_(ULONG,AddRef)(IENUM_THIS(I)) PURE; \
        STDMETHOD_(ULONG,Release)(IENUM_THIS(I)) PURE; \
        STDMETHOD(Next)(IENUM_THIS_(I) ULONG, T*, ULONG*) PURE; \
        STDMETHOD(Skip)(IENUM_THIS_(I) ULONG) PURE; \
        STDMETHOD(Reset)(IENUM_THIS(I)) PURE; \
        STDMETHOD(Clone)(IENUM_THIS_(I) I**) PURE; \
}
#define DECLARE_ENUMERATOR(T)   DECLARE_ENUMERATOR_(IEnum##T,T)
#ifndef _GUID_DEFINED
#define _GUID_DEFINED
typedef struct _GUID
{
        unsigned long Data1;
        unsigned short Data2, Data3;
        unsigned char Data4[8];

} GUID, *REFGUID, *LPGUID;
#endif
#ifndef UUID_DEFINED
#define UUID_DEFINED
typedef GUID UUID;
#endif
typedef GUID IID, CLSID, *LPCLSID, *LPIID, *REFIID, *REFCLSID;
typedef GUID FMTID, *REFFMTID;
#define uuid_t  UUID
typedef unsigned long PROPID;
#ifndef _REFGUID_DEFINED
#if defined(__cplusplus) && !defined(CINTERFACE)
#define REFGUID         const GUID &
#define REFIID          const IID &
#define REFCLSID        const CLSID &
#else
#define REFGUID         const GUID * const
#define REFIID          const IID * const
#define REFCLSID        const CLSID * const
#endif
#define _REFGUID_DEFINED
#define _REFGIID_DEFINED
#define _REFCLSID_DEFINED
#endif
#ifndef GUID_SECTION
#define GUID_SECTION            ".text"
#endif
#ifdef __GNUC__
#define GUID_SECT                       __attribute__((section(GUID_SECTION)))
#else
#define GUID_SECT
#endif
#if !defined(INITGUID) || defined(__cplusplus)
#define GUID_EXT                        EXTERN_C
#else
#define GUID_EXT
#endif
#ifdef  INITGUID
#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)  \
        GUID_EXT const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
#else
#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)  \
        GUID_EXT const GUID n
#endif
#define DEFINE_OLEGUID(n,l,w1,w2) DEFINE_GUID(n,l,w1,w2,0xC0,0,0,0,0,0,0,0x46)
#define EXTERN_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)  \
        GUID_EXT const GUID n
#define RESULT(x)               ((HRESULT)(x))

/*
 * Create an instance of a COM-like class.
 */
STDMETHODIMP CoCreateInstance(const CLSID *rclsid, const IID *riid, void **ppv);

#endif /* !_COR_REAL_WIN32 */

#ifdef  __cplusplus
};
#endif

#endif /* __CORWIN32_H__ */

--- NEW FILE ---
/* This file was borred from cygwin/mingw32 */

#ifndef _CORWINERROR_H
#define _CORWINERROR_H
#if __GNUC__ >=3
#pragma GCC system_header
#endif

#define ERROR_SUCCESS 0L
#define NO_ERROR 0L
#define ERROR_INVALID_FUNCTION 1L
#define ERROR_FILE_NOT_FOUND 2L
#define ERROR_PATH_NOT_FOUND 3L
#define ERROR_TOO_MANY_OPEN_FILES 4L
#define ERROR_ACCESS_DENIED 5L
#define ERROR_INVALID_HANDLE 6L
#define ERROR_ARENA_TRASHED 7L
#define ERROR_NOT_ENOUGH_MEMORY 8L
#define ERROR_INVALID_BLOCK 9L
[...1017 lines suppressed...]
#define NTE_NOT_FOUND 0x80090011L
#define NTE_DOUBLE_ENCRYPT 0x80090012L
#define NTE_BAD_PROVIDER 0x80090013L
#define NTE_BAD_PROV_TYPE 0x80090014L
#define NTE_BAD_PUBLIC_KEY 0x80090015L
#define NTE_BAD_KEYSET 0x80090016L
#define NTE_PROV_TYPE_NOT_DEF 0x80090017L
#define NTE_PROV_TYPE_ENTRY_BAD 0x80090018L
#define NTE_KEYSET_NOT_DEF 0x80090019L
#define NTE_KEYSET_ENTRY_BAD 0x8009001AL
#define NTE_PROV_TYPE_NO_MATCH 0x8009001BL
#define NTE_SIGNATURE_FILE_BAD 0x8009001CL
#define NTE_PROVIDER_DLL_FAIL 0x8009001DL
#define NTE_PROV_DLL_NOT_FOUND 0x8009001EL
#define NTE_BAD_KEYSET_PARAM 0x8009001FL
#define NTE_FAIL 0x80090020L
#define NTE_SYS_ERR 0x80090021L
/* #define NTE_TOKEN_KEYSET_STORAGE ??? */

#endif

--- NEW FILE ---
/*
 * guid.cpp - Define GUID's for the COR routines.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define INITGUID
#include "corole2.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
 * If the platform is Win32, then we don't need IUnknown and IClassFactory.
 */
#ifndef _COR_REAL_WIN32

DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

DEFINE_GUID(IID_IClassFactory, 0x00000001, 0x0000, 0x0000,
                        0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

#endif /* !_COR_REAL_WIN32 */

#ifdef __cplusplus
};
#endif

--- NEW FILE ---
/*
 * shim.c - Implementation of the runtime switching shim.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "cor.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Get the direct CLR engine's module instance handle.
 */
static HINSTANCE GetDirectEngine(void)
{
#ifdef _COR_REAL_WIN32
        static HINSTANCE hInst = 0;

        /* TODO: lock the access to "hInst" */

        /* Return the cached module instance handle, if present */
        if(hInst)
        {
                return hInst;
        }

        /* TODO: find the direct engine and load it */
        return hInst;
#else
        /* The direct CLR engine API is not available on this platform */
        return 0;
#endif
}

/*
 * Stub out "GetProcAddress" on platforms that don't use the direct CLR.
 */
#ifndef _COR_REAL_WIN32
static void *GetProcAddress(HINSTANCE hInst, const char *name)
{
        return 0;
}
#endif

/*
 * Main entry point for IL applications.  This gets the name of the
 * calling program, determines which runtime engine should be used to
 * execute it, and then launches that engine.
 */
__int32 STDCALL _CorExeMain(void)
{
        HINSTANCE hInst;
        void *func;

        /* Get the full pathname of the application */
        /* TODO */

        /* Determine which engine to use for the application */
        /* TODO */

        /* TODO: overlay this process with the engine if it is non-direct */

        /* Find the direct engine and call its "_CorExeMain" function */
        hInst = GetDirectEngine();
        if(hInst)
        {
                func = GetProcAddress(hInst, "_CorExeMain");
                if(func)
                {
                        return (*((__int32 (*)(void))func))();
                }
        }
        return 0;
}

/*
 * The rest of the "mscoree.dll" API's are stubbed out to pass
 * through to the underlying "direct" implementation, if any.
 * This will only happen for native applications that directly
 * host the direct CLR, or for DLL's that were previously loaded
 * by the direct CLR.  For non-direct CLR's such as Portable.Net,
 * Mono, or Rotor, we always bypass the following code.
 */

#define COR_PASS_THROUGH(rettype,name,params,args,defreturn)    \
        rettype STDCALL name params \
        { \
                HINSTANCE __hInst = GetDirectEngine(); \
                void *func; \
                if(__hInst) \
                { \
                        func = GetProcAddress(__hInst, #name); \
                        if(func) \
                        { \
                                return (*((rettype (*) params)func)) args; \
                        } \
                } \
                return defreturn; \
        }
#define COR_PASS_THROUGH_VOID(name,params,args) \
        void STDCALL name params \
        { \
                HINSTANCE __hInst = GetDirectEngine(); \
                void *func; \
                if(__hInst) \
                { \
                        func = GetProcAddress(__hInst, #name); \
                        if(func) \
                        { \
                                (*((void (*) params)func)) args; \
                        } \
                } \
        }

COR_PASS_THROUGH(HRESULT, CoInitializeEE, (DWORD fFlags),
                                 (fFlags), RESULT(E_NOTIMPL))
COR_PASS_THROUGH_VOID(CoUninitializeEE, (BOOL fFlags), (fFlags))
COR_PASS_THROUGH(BOOL, _CorDllMain,
                                 (HINSTANCE hInst, DWORD dwReason, LPVOID 
lpReserved),
                                 (hInst, dwReason, lpReserved), 0)
COR_PASS_THROUGH(__int32, _CorExeMain2,
                                 (PBYTE pUnmappedPE, DWORD cUnmappedPE,
                                  LPWSTR pImageNameIn, LPWSTR pLoadersFileName,
                                  LPWSTR pCmdLine),
                                 (pUnmappedPE, cUnmappedPE, pImageNameIn,
                                  pLoadersFileName, pCmdLine), 0)
COR_PASS_THROUGH(HRESULT, _CorValidateImage,
                                 (PVOID *ImageBase, LPCSTR FileName),
                                 (ImageBase, FileName), RESULT(E_NOTIMPL))
COR_PASS_THROUGH_VOID(_CorImageUnloading, (PVOID ImageBase), (ImageBase))
COR_PASS_THROUGH(HRESULT, CoInitializeCor,
                                 (DWORD fFlags), (fFlags), RESULT(E_NOTIMPL))
COR_PASS_THROUGH_VOID(CoUninitializeCor, (void), ())
COR_PASS_THROUGH_VOID(AddDestructorCallback,
                                          (int code, TDestructorCallback cb), 
(code, cb))

#ifdef __cplusplus
};
#endif





reply via email to

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