1/*
2    Title:  polyexports.h
3
4    Copyright (c) 2006, 2011, 2015 David C.J. Matthews
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License version 2.1 as published by the Free Software Foundation.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18*/
19
20/*
21This header contains the structures used in saved state created by "export".
22*/
23
24#ifndef _STANDALONE_H
25#define _STANDALONE_H 1
26
27// Get time_t
28#ifdef HAVE_TIME_H
29#include <time.h>
30#endif
31
32// Get uintptr_t
33#if HAVE_STDINT_H
34#  include <stdint.h>
35#endif
36
37#if HAVE_INTTYPES_H
38#  ifndef __STDC_FORMAT_MACROS
39#    define __STDC_FORMAT_MACROS
40#  endif
41#  include <inttypes.h>
42#endif
43
44#ifdef HAVE_STDDEF_H
45#  include <stddef.h>
46#endif
47
48#if defined(HAVE_WINDOWS_H)
49#  include <windows.h>
50#endif
51
52// There are several entries
53typedef struct _memTableEntry {
54    void *mtAddr;                       // The address of the area of memory
55    uintptr_t mtLength;              // The length in bytes of the area
56    uintptr_t mtFlags;               // Flags describing the area.
57    uintptr_t mtIndex;               // An index to identify permanent spaces.
58} memoryTableEntry;
59
60#define MTF_WRITEABLE         0x00000001  // The area is writeable by ML code
61#define MTF_EXECUTABLE        0x00000002  // The area contains executable code
62#define MTF_NO_OVERWRITE      0x00000004  // With MTF_WRITEABLE: Don't load over the top
63#define MTF_BYTES             0x00000008  // Contains only byte data and no addresses
64
65typedef struct _exportDescription {
66    unsigned structLength;         // The length of this structure
67    unsigned memTableSize;         // The size of each entry in the memory table
68    unsigned memTableEntries;      // The number of entries in the memory table
69    memoryTableEntry *memTable;    // Pointer to the memory table.
70    void *rootFunction;            // Points to the start-up function
71    time_t timeStamp;              // Creation time stamp
72    unsigned architecture;         // Machine architecture
73    unsigned rtsVersion;           // Run-time system version
74} exportDescription;
75
76extern exportDescription poly_exports;
77
78#ifdef __cplusplus
79extern "C" {
80#endif
81
82#if (defined(_WIN32) && ! defined(__CYGWIN__))
83#include <windows.h>
84
85# ifdef LIBPOLYML_BUILD
86#  ifdef DLL_EXPORT
87#   define POLYLIB_API            __declspec (dllexport)
88#  endif
89# elif defined _MSC_VER
90    // Visual C - POLYLIB_EXPORTS is defined in the library project settings
91#  ifdef POLYLIB_EXPORTS
92#   define POLYLIB_API             __declspec (dllexport)
93#  else
94#   define POLYLIB_API             __declspec (dllimport)
95#  endif
96# elif defined DLL_EXPORT
97#  define POLYLIB_API             __declspec (dllimport)
98# else
99#  define POLYLIB_API
100# endif
101
102extern POLYLIB_API int PolyWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
103                    LPSTR lpCmdLine, int nCmdShow, exportDescription *exports);
104#else
105int polymain(int argc, char *argv[], exportDescription *exports);
106#endif
107
108#ifdef __cplusplus
109};
110#endif
111
112#endif
113