mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
Enable support for interfaces and the map primitive
This commit is contained in:
parent
264ea09b9a
commit
cd7e7ed15a
@ -16,8 +16,27 @@ var (
|
|||||||
earlyReserveRegionFn = vmm.EarlyReserveRegion
|
earlyReserveRegionFn = vmm.EarlyReserveRegion
|
||||||
frameAllocFn = allocator.AllocFrame
|
frameAllocFn = allocator.AllocFrame
|
||||||
mallocInitFn = mallocInit
|
mallocInitFn = mallocInit
|
||||||
|
algInitFn = algInit
|
||||||
|
modulesInitFn = modulesInit
|
||||||
|
typeLinksInitFn = typeLinksInit
|
||||||
|
itabsInitFn = itabsInit
|
||||||
|
|
||||||
|
// A seed for the pseudo-random number generator used by getRandomData
|
||||||
|
prngSeed = 0xdeadc0de
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:linkname algInit runtime.alginit
|
||||||
|
func algInit()
|
||||||
|
|
||||||
|
//go:linkname modulesInit runtime.modulesinit
|
||||||
|
func modulesInit()
|
||||||
|
|
||||||
|
//go:linkname typeLinksInit runtime.typelinksinit
|
||||||
|
func typeLinksInit()
|
||||||
|
|
||||||
|
//go:linkname itabsInit runtime.itabsinit
|
||||||
|
func itabsInit()
|
||||||
|
|
||||||
//go:linkname mallocInit runtime.mallocinit
|
//go:linkname mallocInit runtime.mallocinit
|
||||||
func mallocInit()
|
func mallocInit()
|
||||||
|
|
||||||
@ -121,11 +140,30 @@ func nanotime() uint64 {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getRandomData populates the given slice with random data. The implementation
|
||||||
|
// is the runtime package reads a random stream from /dev/random but since this
|
||||||
|
// is not available, we use a prng instead.
|
||||||
|
//
|
||||||
|
//go:redirect-from runtime.getRandomData
|
||||||
|
func getRandomData(r []byte) {
|
||||||
|
for i := 0; i < len(r); i++ {
|
||||||
|
prngSeed = (prngSeed * 58321) + 11113
|
||||||
|
r[i] = byte((prngSeed >> 16) & 255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init enables support for various Go runtime features. After a call to init
|
// Init enables support for various Go runtime features. After a call to init
|
||||||
// the following runtime features become available for use:
|
// the following runtime features become available for use:
|
||||||
// - heap memory allocation (new, make e.t.c)
|
// - heap memory allocation (new, make e.t.c)
|
||||||
|
// - map primitives
|
||||||
|
// - interfaces
|
||||||
func Init() *kernel.Error {
|
func Init() *kernel.Error {
|
||||||
mallocInitFn()
|
mallocInitFn()
|
||||||
|
algInitFn() // setup hash implementation for map keys
|
||||||
|
modulesInitFn() // provides activeModules
|
||||||
|
typeLinksInitFn() // uses maps, activeModules
|
||||||
|
itabsInitFn() // uses activeModules
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,5 +179,6 @@ func init() {
|
|||||||
sysReserve(zeroPtr, 0, &reserved)
|
sysReserve(zeroPtr, 0, &reserved)
|
||||||
sysMap(zeroPtr, 0, reserved, &stat)
|
sysMap(zeroPtr, 0, reserved, &stat)
|
||||||
sysAlloc(0, &stat)
|
sysAlloc(0, &stat)
|
||||||
|
getRandomData(nil)
|
||||||
stat = nanotime()
|
stat = nanotime()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package goruntime
|
package goruntime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -236,11 +237,32 @@ func TestSysAlloc(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetRandomData(t *testing.T) {
|
||||||
|
sample1 := make([]byte, 128)
|
||||||
|
sample2 := make([]byte, 128)
|
||||||
|
|
||||||
|
getRandomData(sample1)
|
||||||
|
getRandomData(sample2)
|
||||||
|
|
||||||
|
if reflect.DeepEqual(sample1, sample2) {
|
||||||
|
t.Fatal("expected getRandomData to return different values for each invocation")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
mallocInitFn = mallocInit
|
mallocInitFn = mallocInit
|
||||||
|
algInitFn = algInit
|
||||||
|
modulesInitFn = modulesInit
|
||||||
|
typeLinksInitFn = typeLinksInit
|
||||||
|
itabsInitFn = itabsInit
|
||||||
}()
|
}()
|
||||||
|
|
||||||
mallocInitFn = func() {}
|
mallocInitFn = func() {}
|
||||||
|
algInitFn = func() {}
|
||||||
|
modulesInitFn = func() {}
|
||||||
|
typeLinksInitFn = func() {}
|
||||||
|
itabsInitFn = func() {}
|
||||||
|
|
||||||
if err := Init(); err != nil {
|
if err := Init(); err != nil {
|
||||||
t.Fatal(t)
|
t.Fatal(t)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user