| 1 |
// Copyright 2025 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. |
| 4 |
|
| 5 |
package windows |
| 6 |
|
| 7 |
import ( |
| 8 |
"internal/goarch" |
| 9 |
"unsafe" |
| 10 |
) |
| 11 |
|
| 12 |
const CONTEXT_CONTROL = 0x10001 |
| 13 |
|
| 14 |
type FloatingSaveArea struct { |
| 15 |
ControlWord uint32 |
| 16 |
StatusWord uint32 |
| 17 |
TagWord uint32 |
| 18 |
ErrorOffset uint32 |
| 19 |
ErrorSelector uint32 |
| 20 |
DataOffset uint32 |
| 21 |
DataSelector uint32 |
| 22 |
RegisterArea [80]uint8 |
| 23 |
Cr0NpxState uint32 |
| 24 |
} |
| 25 |
|
| 26 |
type Context struct { |
| 27 |
ContextFlags uint32 |
| 28 |
Dr0 uint32 |
| 29 |
Dr1 uint32 |
| 30 |
Dr2 uint32 |
| 31 |
Dr3 uint32 |
| 32 |
Dr6 uint32 |
| 33 |
Dr7 uint32 |
| 34 |
FloatingSaveArea FloatingSaveArea |
| 35 |
SegGs uint32 |
| 36 |
SegFs uint32 |
| 37 |
SegEs uint32 |
| 38 |
SegDs uint32 |
| 39 |
Edi uint32 |
| 40 |
Esi uint32 |
| 41 |
Ebx uint32 |
| 42 |
Edx uint32 |
| 43 |
Ecx uint32 |
| 44 |
Eax uint32 |
| 45 |
Ebp uint32 |
| 46 |
Eip uint32 |
| 47 |
SegCs uint32 |
| 48 |
EFlags uint32 |
| 49 |
Esp uint32 |
| 50 |
SegSs uint32 |
| 51 |
ExtendedRegisters [512]uint8 |
| 52 |
} |
| 53 |
|
| 54 |
func (c *Context) PC() uintptr { return uintptr(c.Eip) } |
| 55 |
func (c *Context) SP() uintptr { return uintptr(c.Esp) } |
| 56 |
|
| 57 |
// 386 does not have link register, so this returns 0. |
| 58 |
func (c *Context) LR() uintptr { return 0 } |
| 59 |
func (c *Context) SetLR(x uintptr) {} |
| 60 |
|
| 61 |
func (c *Context) SetPC(x uintptr) { c.Eip = uint32(x) } |
| 62 |
func (c *Context) SetSP(x uintptr) { c.Esp = uint32(x) } |
| 63 |
|
| 64 |
// 386 does not have frame pointer register. |
| 65 |
func (c *Context) SetFP(x uintptr) {} |
| 66 |
|
| 67 |
func (c *Context) PushCall(targetPC, resumePC uintptr) { |
| 68 |
sp := c.SP() - goarch.StackAlign |
| 69 |
*(*uintptr)(unsafe.Pointer(sp)) = resumePC |
| 70 |
c.SetSP(sp) |
| 71 |
c.SetPC(targetPC) |
| 72 |
} |
| 73 |
|
| 74 |
// DISPATCHER_CONTEXT is not defined on 386. |
| 75 |
type DISPATCHER_CONTEXT struct{} |
| 76 |
|
| 77 |
func (c *DISPATCHER_CONTEXT) Ctx() *Context { |
| 78 |
return nil |
| 79 |
} |