Skip to content

Commit

Permalink
fix #102, revert commit 0b5d8fa
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Nov 19, 2024
1 parent 3fe2acb commit 206fcf7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
22 changes: 8 additions & 14 deletions iface.1.10.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,26 @@ type itabTableType struct {
entries [itabInitSize]*itab // really [size] large
}

//go:linkname __itabTable runtime.itabTable
var __itabTable unsafe.Pointer // pointer to current table
//go:linkname itabTable runtime.itabTable
var itabTable *itabTableType // pointer to current table

// Avoids "go.info.runtime.itabTable: relocation target go.info.*github.com/pkujhd/goloader.itabTableType not defined"
var itabTable = *(**itabTableType)(unsafe.Pointer(&__itabTable))

//go:linkname __itabLock runtime.itabLock
var __itabLock uintptr

// Avoids "go.info.runtime.itabLock: relocation target go.info.github.com/pkujhd/goloader.mutex not defined"
var itabLock = (*mutex)(unsafe.Pointer(&__itabLock))
//go:linkname itabLock runtime.itabLock
var itabLock mutex

//go:linkname itabAdd runtime.itabAdd
func itabAdd(m *itab)

func additabs(module *moduledata) {
lock(itabLock)
lock(&itabLock)
for _, itab := range module.itablinks {
itabAdd(itab)
}
unlock(itabLock)
unlock(&itabLock)
}

func removeitabs(module *moduledata) bool {
lock(itabLock)
defer unlock(itabLock)
lock(&itabLock)
defer unlock(&itabLock)

for i := uintptr(0); i < itabTable.size; i++ {
p := (**itab)(add(unsafe.Pointer(&itabTable.entries), i*PtrSize))
Expand Down
20 changes: 8 additions & 12 deletions iface.1.8.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,28 @@ type itab struct {
// See: src/runtime/iface.go
const hashSize = 1009

//go:linkname __hash runtime.hash
var __hash uintptr
//go:linkname hash runtime.hash
var hash [hashSize]*itab

var hash = (*[hashSize]*itab)(unsafe.Pointer(&__hash))

//go:linkname __ifaceLock runtime.ifaceLock
var __ifaceLock uintptr

var ifaceLock = (*mutex)(unsafe.Pointer(&__ifaceLock))
//go:linkname ifaceLock runtime.ifaceLock
var ifaceLock mutex

//go:linkname additab runtime.additab
func additab(m *itab, locked, canfail bool)

func additabs(module *moduledata) {
lock(ifaceLock)
lock(&ifaceLock)
for _, itab := range module.itablinks {
if itab.inhash == 0 {
additab(itab, true, false)
}
}
unlock(ifaceLock)
unlock(&ifaceLock)
}

func removeitabs(module *moduledata) bool {
lock(ifaceLock)
defer unlock(ifaceLock)
lock(&ifaceLock)
defer unlock(&ifaceLock)

//the itab alloc by runtime.persistentalloc, can't free
for index, h := range hash {
Expand Down

0 comments on commit 206fcf7

Please sign in to comment.