nintendoswitch: Fix invalid memory read / write in print calls

Этот коммит содержится в:
Lucas Teske 2020-09-09 13:51:00 -03:00 коммит произвёл GitHub
родитель f20c932bb9
коммит 0b9b293651
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 8 добавлений и 17 удалений

Просмотреть файл

@ -40,21 +40,18 @@ func ticks() timeUnit {
return timeUnit(ticksToNanoseconds(timeUnit(getArmSystemTick()))) return timeUnit(ticksToNanoseconds(timeUnit(getArmSystemTick())))
} }
var stdoutBuffer = make([]byte, 0, 120) var stdoutBuffer = make([]byte, 120)
var position = 0
func putchar(c byte) { func putchar(c byte) {
if c == '\n' || len(stdoutBuffer)+1 >= 120 { if c == '\n' || position > len(stdoutBuffer) {
NxOutputString(string(stdoutBuffer)) nxOutputString(&stdoutBuffer[0], uint64(position))
stdoutBuffer = stdoutBuffer[:0] position = 0
return return
} }
stdoutBuffer = append(stdoutBuffer, c) stdoutBuffer[position] = c
} position++
func usleep(usec uint) int {
sleepThread(uint64(usec) * 1000)
return 0
} }
func abort() { func abort() {

Просмотреть файл

@ -4,17 +4,11 @@
package runtime package runtime
import "unsafe"
const heapSize = 0x2000000 * 16 // Default by libnx const heapSize = 0x2000000 * 16 // Default by libnx
//go:extern _stack_top
var stackTopSymbol [0]byte
var ( var (
heapStart = uintptr(0) heapStart = uintptr(0)
heapEnd = uintptr(0) heapEnd = uintptr(0)
stackTop = uintptr(unsafe.Pointer(&stackTopSymbol))
) )
//export setHeapSize //export setHeapSize
@ -24,7 +18,7 @@ func preinit() {
setHeapSize(&heapStart, heapSize) setHeapSize(&heapStart, heapSize)
if heapStart == 0 { if heapStart == 0 {
panic("failed to allocate heap") runtimePanic("failed to allocate heap")
} }
heapEnd = heapStart + heapSize heapEnd = heapStart + heapSize