github.com/newrelic/go-agent@v3.26.0+incompatible/internal/sysinfo/memtotal_darwin.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package sysinfo 5 6 import ( 7 "syscall" 8 "unsafe" 9 ) 10 11 // PhysicalMemoryBytes returns the total amount of host memory. 12 func PhysicalMemoryBytes() (uint64, error) { 13 mib := []int32{6 /* CTL_HW */, 24 /* HW_MEMSIZE */} 14 15 buf := make([]byte, 8) 16 bufLen := uintptr(8) 17 18 _, _, e1 := syscall.Syscall6(syscall.SYS___SYSCTL, 19 uintptr(unsafe.Pointer(&mib[0])), uintptr(len(mib)), 20 uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bufLen)), 21 uintptr(0), uintptr(0)) 22 23 if e1 != 0 { 24 return 0, e1 25 } 26 27 if bufLen != 8 { 28 return 0, syscall.EIO 29 } 30 31 return *(*uint64)(unsafe.Pointer(&buf[0])), nil 32 }