mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-24 14:29:08 +00:00
runtime: call initRand() before initHeap() during initialization.
The reason is that allocating without a heap is usually more visible than using an uninitialized random generator which is subtle and may lead to security vulnerabilities. Based on suggestion from @eliasnaur Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -34,8 +34,8 @@ func wasmEntryReactor() {
|
|||||||
// Initialize the heap.
|
// Initialize the heap.
|
||||||
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||||
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
||||||
initHeap()
|
|
||||||
initRand()
|
initRand()
|
||||||
|
initHeap()
|
||||||
|
|
||||||
if hasScheduler {
|
if hasScheduler {
|
||||||
// A package initializer might do funky stuff like start a goroutine and
|
// A package initializer might do funky stuff like start a goroutine and
|
||||||
|
|||||||
@@ -243,8 +243,8 @@ func sleep(duration int64) {
|
|||||||
// run is called by the program entry point to execute the go program.
|
// run is called by the program entry point to execute the go program.
|
||||||
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
|
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
|
||||||
func run() {
|
func run() {
|
||||||
initHeap()
|
|
||||||
initRand()
|
initRand()
|
||||||
|
initHeap()
|
||||||
go func() {
|
go func() {
|
||||||
initAll()
|
initAll()
|
||||||
callMain()
|
callMain()
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ func sleep(duration int64) {
|
|||||||
// This function is called on the first core in the system. It will wake up the
|
// This function is called on the first core in the system. It will wake up the
|
||||||
// other cores when ready.
|
// other cores when ready.
|
||||||
func run() {
|
func run() {
|
||||||
initHeap()
|
|
||||||
initRand()
|
initRand()
|
||||||
|
initHeap()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// Package initializers are currently run single-threaded.
|
// Package initializers are currently run single-threaded.
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ var schedulerExit bool
|
|||||||
// run is called by the program entry point to execute the go program.
|
// run is called by the program entry point to execute the go program.
|
||||||
// With the "none" scheduler, init and the main function are invoked directly.
|
// With the "none" scheduler, init and the main function are invoked directly.
|
||||||
func run() {
|
func run() {
|
||||||
initHeap()
|
|
||||||
initRand()
|
initRand()
|
||||||
|
initHeap()
|
||||||
initAll()
|
initAll()
|
||||||
callMain()
|
callMain()
|
||||||
mainExited = true
|
mainExited = true
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ var (
|
|||||||
// Because we just use OS threads, we don't need to do anything special here. We
|
// Because we just use OS threads, we don't need to do anything special here. We
|
||||||
// can just initialize everything and run main.main on the main thread.
|
// can just initialize everything and run main.main on the main thread.
|
||||||
func run() {
|
func run() {
|
||||||
initHeap()
|
|
||||||
initRand()
|
initRand()
|
||||||
|
initHeap()
|
||||||
task.Init(stackTop)
|
task.Init(stackTop)
|
||||||
initAll()
|
initAll()
|
||||||
callMain()
|
callMain()
|
||||||
|
|||||||
Reference in New Issue
Block a user