mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
rt0_64: preserve XMM registers when calling gate handlers
Some gate handlers may invoke Go runtime code that clobbers the XMM registers that could be in use by the code that triggered the gate handler. One case where this happens is when a growing a slice and the new location for the slice data resides in a RO page with a CoW flag. In this scenario, runtime.growslice will invoke runtime.memmove which may take a code path that uses XMM registers for copying data around. During the copy, a page fault occurs and the kernel page fault handler will detect the CoW flag, allocate a new frame and copy the original data to the new frame before resuming execution. As the page copy is performed using the built-in copy function this will cause the XMM registers to be clobbered. To prevent this from happening, the asm gate code that gets executed when an exception occurs will now preserve the XMM regs on the stack before invoking the registered exception handler. In addition, for Go 1.9+ the gate code will also temporarily disable use of AVX instructions by runtime.memmove by setting runtime.useAVXmemmove to 0. This is required so the gate does not need to also preserve any AVX registers.
This commit is contained in:
6
Makefile
6
Makefile
@@ -32,7 +32,8 @@ GOROOT := $(shell $(GO) env GOROOT)
|
||||
GC_FLAGS ?=
|
||||
LD_FLAGS := -n -T $(BUILD_DIR)/linker.ld -static --no-ld-generated-unwind-info
|
||||
AS_FLAGS := -g -f elf64 -F dwarf -I $(BUILD_DIR)/ -I src/arch/$(ARCH)/asm/ \
|
||||
-dNUM_REDIRECTS=$(shell GOPATH=$(GOPATH) $(GO) run tools/redirects/redirects.go count)
|
||||
-dNUM_REDIRECTS=$(shell GOPATH=$(GOPATH) $(GO) run tools/redirects/redirects.go count) \
|
||||
-dWITH_RUNTIME_AVXMEMMOVE=$(shell grep -r "var useAVXmemmove" $(GOROOT)/src/runtime/ | wc -l)
|
||||
|
||||
MIN_OBJCOPY_VERSION := 2.26.0
|
||||
HAVE_VALID_OBJCOPY := $(shell objcopy -V | head -1 | awk -F ' ' '{print "$(MIN_OBJCOPY_VERSION)\n" $$NF}' | sort -ct. -k1,1n -k2,2n && echo "y")
|
||||
@@ -74,13 +75,14 @@ go.o:
|
||||
@# objcopy to make that symbol exportable. Since nasm does not support externs
|
||||
@# with slashes we create a global symbol alias for kernel.Kmain
|
||||
@echo "[objcopy] create kernel.Kmain alias to gopheros/kernel/kmain.Kmain"
|
||||
@echo "[objcopy] globalizing symbols {_rt0_interrupt_handlers, runtime.g0/m0/physPageSize}"
|
||||
@echo "[objcopy] globalizing symbols {_rt0_interrupt_handlers, runtime.g0/m0/physPageSize/useAVXmemmove}"
|
||||
@objcopy \
|
||||
--add-symbol kernel.Kmain=.text:0x`nm $(BUILD_DIR)/go.o | grep "kmain.Kmain$$" | cut -d' ' -f1` \
|
||||
--globalize-symbol _rt0_interrupt_handlers \
|
||||
--globalize-symbol runtime.g0 \
|
||||
--globalize-symbol runtime.m0 \
|
||||
--globalize-symbol runtime.physPageSize \
|
||||
--globalize-symbol runtime.useAVXmemmove \
|
||||
$(BUILD_DIR)/go.o $(BUILD_DIR)/go.o
|
||||
|
||||
binutils_version_check:
|
||||
|
||||
Reference in New Issue
Block a user