1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 // This file contains remote runtime definitions. Using reflection,
14 // we convert all of these to interpreter types and layout their
15 // remote representations using the architecture rules.
17 // We could get most of these definitions from our own runtime
18 // package; however, some of them differ in convenient ways, some of
19 // them are not defined or exported by the runtime, and having our own
20 // definitions makes it easy to support multiple remote runtime
21 // versions. This may turn out to be overkill.
23 // All of these structures are prefixed with rt1 to indicate the
24 // runtime version and to mark them as types used only as templates
28 * Runtime data headers
30 * See $GOROOT/src/pkg/runtime/runtime.h
33 type rt1String
struct {
38 type rt1Slice
struct {
44 type rt1Eface
struct {
50 * Runtime type structures
52 * See $GOROOT/src/pkg/runtime/type.h and $GOROOT/src/pkg/runtime/type.go
55 type rt1UncommonType
struct {
61 type rt1CommonType
struct {
64 alg
, align
, fieldAlign
uint8
66 uncommonType
*rt1UncommonType
70 // While Type is technically an Eface, treating the
71 // discriminator as an opaque pointer and taking advantage of
72 // the commonType prologue on all Type's makes type parsing
78 type rt1StructField
struct {
86 type rt1StructType
struct {
88 fields
[]rt1StructField
91 type rt1PtrType
struct {
96 type rt1SliceType
struct {
101 type rt1ArrayType
struct {
108 * Runtime scheduler structures
110 * See $GOROOT/src/pkg/runtime/runtime.h
113 // Fields beginning with _ are only for padding
115 type rt1Stktop
struct {
123 type rt1Gobuf
struct {
143 var rt1GStatus
= runtimeGStatus
{
153 // runtimeIndexes stores the indexes of fields in the runtime
154 // structures. It is filled in using reflection, so the name of the
155 // fields must match the names of the remoteType's in runtimeValues
156 // exactly and the names of the index fields must be the capitalized
157 // version of the names of the fields in the runtime structures above.
158 type runtimeIndexes
struct {
169 UncommonType
struct {
173 Size
, Hash
, Alg
, Align
, FieldAlign
, String
, UncommonType
int
179 Name
, PkgPath
, Typ
, Tag
, Offset
int
195 Stackguard
, Stackbase
, Gobuf
int
201 Stackbase
, Sched
, Status
, Alllink
int
205 // Values of G status codes
206 type runtimeGStatus
struct {
207 Gidle
, Grunnable
, Grunning
, Gsyscall
, Gwaiting
, Gmoribund
, Gdead
int64
210 // runtimeValues stores the types and values that correspond to those
211 // in the remote runtime package.
212 type runtimeValues
struct {
213 // Runtime data headers
214 String
, Slice
, Eface
*remoteType
215 // Runtime type structures
216 Type
, CommonType
, UncommonType
, StructField
, StructType
, PtrType
,
217 ArrayType
, SliceType
*remoteType
218 // Runtime scheduler structures
219 Stktop
, Gobuf
, G
*remoteType
220 // Addresses of *runtime.XType types. These are the
221 // discriminators on the runtime.Type interface. We use local
222 // reflection to fill these in from the remote symbol table,
223 // so the names must match the runtime names.
225 PUint8Type
, PUint16Type
, PUint32Type
, PUint64Type
, PUintType
, PUintptrType
,
226 PInt8Type
, PInt16Type
, PInt32Type
, PInt64Type
, PIntType
,
227 PFloat32Type
, PFloat64Type
, PFloatType
,
228 PArrayType
, PStringType
, PStructType
, PPtrType
, PFuncType
,
229 PInterfaceType
, PSliceType
, PMapType
, PChanType
,
230 PDotDotDotType
, PUnsafePointerType proc
.Word
235 // fillRuntimeIndexes fills a runtimeIndexes structure will the field
236 // indexes gathered from the remoteTypes recorded in a runtimeValues
238 func fillRuntimeIndexes(runtime
*runtimeValues
, out
*runtimeIndexes
) {
239 outv
:= reflect
.Indirect(reflect
.NewValue(out
)).(*reflect
.StructValue
)
240 outt
:= outv
.Type().(*reflect
.StructType
)
241 runtimev
:= reflect
.Indirect(reflect
.NewValue(runtime
)).(*reflect
.StructValue
)
243 // out contains fields corresponding to each runtime type
244 for i
:= 0; i
< outt
.NumField(); i
++ {
245 // Find the interpreter type for this runtime type
246 name
:= outt
.Field(i
).Name
247 et
:= runtimev
.FieldByName(name
).Interface().(*remoteType
).Type
.(*eval
.StructType
)
249 // Get the field indexes of the interpreter struct type
250 indexes
:= make(map[string]int, len(et
.Elems
))
251 for j
, f
:= range et
.Elems
{
256 if name
[0] >= 'a' && name
[0] <= 'z' {
257 name
= string(name
[0]+'A'-'a') + name
[1:]
262 // Fill this field of out
263 outStructv
:= outv
.Field(i
).(*reflect
.StructValue
)
264 outStructt
:= outStructv
.Type().(*reflect
.StructType
)
265 for j
:= 0; j
< outStructt
.NumField(); j
++ {
266 f
:= outStructv
.Field(j
).(*reflect
.IntValue
)
267 name
:= outStructt
.Field(j
).Name
268 f
.Set(int64(indexes
[name
]))