-
Notifications
You must be signed in to change notification settings - Fork 23
/
STExternal.h
133 lines (109 loc) · 3.15 KB
/
STExternal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/******************************************************************************
File: STExternal.h
Description:
VM representation of Smalltalk external interfacing classes.
N.B. Some of the classes here defined are well known to the VM, and must not
be modified in the image. Note also that these classes may also have
a representation in the assembler modules (so see istasm.inc)
******************************************************************************/
#pragma once
#include "STObject.h"
// Declare forward references
namespace ST
{
class ExternalStructure;
class ExternalAddress;
class ExternalHandle;
}
typedef TOTE<ST::ExternalStructure> StructureOTE;
typedef TOTE<ST::ExternalAddress> AddressOTE;
typedef TOTE<ST::ExternalHandle> HandleOTE;
struct COMThunk
{
PROC* vtbl;
DWORD* argSizes;
DWORD id;
DWORD subId;
};
namespace ST
{
class ExternalStructure : public Object
{
public:
BytesOTE* m_contents;
static StructureOTE* __fastcall NewRefStruct(BehaviorOTE* classPointer, void* ptr);
static OTE* __fastcall NewPointer(BehaviorOTE* classPointer, void* ptr);
static OTE* __fastcall New(BehaviorOTE* classPointer, void* pContents);
};
// Really a subclass of ByteArray
class DWORDBytes : public Object
{
public:
DWORD m_dwValue;
};
class ExternalHandle : public Object
{
// ExternalHandle is really a variable byte subclass of length 4
public:
HANDLE m_handle;
static HandleOTE* New(HANDLE hValue);
static HANDLE handleFromOop(Oop oopHandle);
static Oop IntegerOrNew(HANDLE hValue);
};
class ExternalAddress : public Object
{
// ExternalAddress is really a variable byte subclass of length 4
public:
void* m_pointer;
static AddressOTE* New(void* ptrValue);
};
class CallbackDescriptor : public Object
{
public:
Oop m_convention;
Oop m_returnDescriptor;
Oop m_arguments[];
};
class DescriptorBytes;
typedef TOTE<DescriptorBytes> DescriptorOTE;
// Not a real class, but useful all the same
class DescriptorBytes : public Object
{
public:
BYTE m_callingConvention;
BYTE m_argumentCount;
BYTE m_returnType;
BYTE m_returnClass;
BYTE m_args[];
static unsigned argsLen(DescriptorOTE* ote) { return ote->getSize() - offsetof(DescriptorBytes, m_args); }
};
class ExternalDescriptor : public Object
{
public:
DescriptorOTE* m_descriptor; // Byte array of descriptor bytes
OTE* m_literals[];
};
///////////////////////////////////////////////////////////////////////////////
// Answer either a SmallInteger or an ExternalHandle (if too big) to hold
// the specified handle.
inline Oop ExternalHandle::IntegerOrNew(HANDLE hValue)
{
return isPositiveIntegerValue(hValue) ?
integerObjectOf(hValue) :
Oop(New(hValue));
}
// Answer either a SmallInteger or an ExternalHandle (if too big) to hold
// the specified handle.
inline HANDLE ExternalHandle::handleFromOop(Oop oopHandle)
{
if (isIntegerObject(oopHandle))
return HANDLE(integerValueOf(oopHandle));
else
{
HandleOTE* oteHandle = reinterpret_cast<HandleOTE*>(oopHandle);
ExternalHandle* eh = oteHandle->m_location;
return eh->m_handle;
}
}
}
std::wostream& operator<<(std::wostream& st, const HandleOTE* oteHandle);