aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mem_darwin.go
diff options
context:
space:
mode:
authorSrdjan Petrovic <spetrovic@google.com>2015-04-16 14:32:18 -0700
committerDavid Crawshaw <crawshaw@golang.org>2015-04-24 16:53:26 +0000
commit6ad33be2d9d6b24aa741b3007a4bcd52db222c41 (patch)
tree904764e1cb4fcf37f7bd4022c43eae35d45b6bfb /src/runtime/mem_darwin.go
parent8566979972d51236c37b2823d2c0d52c6efe5406 (diff)
downloadgo-6ad33be2d9d6b24aa741b3007a4bcd52db222c41.tar.gz
go-6ad33be2d9d6b24aa741b3007a4bcd52db222c41.zip
runtime: implement xadduintptr and update system mstats using it
The motivation is that sysAlloc/Free() currently aren't safe to be called without a valid G, because arm's xadd64() uses locks that require a valid G. The solution here was proposed by Dmitry Vyukov: use xadduintptr() instead of xadd64(), until arm can support xadd64 on all of its architectures (not a trivial task for arm). Change-Id: I250252079357ea2e4360e1235958b1c22051498f Reviewed-on: https://go-review.googlesource.com/9002 Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Diffstat (limited to 'src/runtime/mem_darwin.go')
-rw-r--r--src/runtime/mem_darwin.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/runtime/mem_darwin.go b/src/runtime/mem_darwin.go
index e3b8845549..3bebd97c57 100644
--- a/src/runtime/mem_darwin.go
+++ b/src/runtime/mem_darwin.go
@@ -6,13 +6,15 @@ package runtime
import "unsafe"
+// Don't split the stack as this function may be invoked without a valid G,
+// which prevents us from allocating more stack.
//go:nosplit
-func sysAlloc(n uintptr, stat *uint64) unsafe.Pointer {
+func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
v := (unsafe.Pointer)(mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0))
if uintptr(v) < 4096 {
return nil
}
- xadd64(stat, int64(n))
+ mSysStatInc(sysStat, n)
return v
}
@@ -24,8 +26,11 @@ func sysUnused(v unsafe.Pointer, n uintptr) {
func sysUsed(v unsafe.Pointer, n uintptr) {
}
-func sysFree(v unsafe.Pointer, n uintptr, stat *uint64) {
- xadd64(stat, -int64(n))
+// Don't split the stack as this function may be invoked without a valid G,
+// which prevents us from allocating more stack.
+//go:nosplit
+func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
+ mSysStatDec(sysStat, n)
munmap(v, n)
}
@@ -46,8 +51,8 @@ const (
_ENOMEM = 12
)
-func sysMap(v unsafe.Pointer, n uintptr, reserved bool, stat *uint64) {
- xadd64(stat, int64(n))
+func sysMap(v unsafe.Pointer, n uintptr, reserved bool, sysStat *uint64) {
+ mSysStatInc(sysStat, n)
p := (unsafe.Pointer)(mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0))
if uintptr(p) == _ENOMEM {
throw("runtime: out of memory")