Debian Codegraph @

src/internal/runtime/gc/scan/mem_unix_test.go

raw
1 // Copyright 2025 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build unix
6
7 package scan_test
8
9 import (
10 "internal/runtime/gc"
11 "syscall"
12 "testing"
13 "unsafe"
14 )
15
16 func makeMem(t testing.TB, nPages int) ([]uintptr, func()) {
17 mem, err := syscall.Mmap(-1, 0, int(gc.PageSize*nPages), syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANON)
18 if err != nil {
19 t.Fatalf("mmap failed: %s", err)
20 }
21 free := func() {
22 syscall.Munmap(mem)
23 }
24 return unsafe.Slice((*uintptr)(unsafe.Pointer(unsafe.SliceData(mem))), len(mem)/8), free
25 }