1 // Copyright 2013 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.
14 // TestMemmoveOverflow maps 3GB of memory and calls memmove on
15 // the corresponding slice.
16 func TestMemmoveOverflow(t *testing.T) {
18 // Create a temporary file.
19 tmp, err := os.CreateTemp("", "go-memmovetest")
23 _, err = tmp.Write(make([]byte, 65536))
27 defer os.Remove(tmp.Name())
31 base, _, errno := syscall.Syscall6(syscall.SYS_MMAP,
32 0xa0<<32, 3<<30, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUS, ^uintptr(0), 0)
34 t.Skipf("could not create memory mapping: %s", errno)
36 syscall.Syscall(syscall.SYS_MUNMAP, base, 3<<30, 0)
38 for off := uintptr(0); off < 3<<30; off += 65536 {
39 _, _, errno := syscall.Syscall6(syscall.SYS_MMAP,
40 base+off, 65536, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED|syscall.MAP_FIXED, tmp.Fd(), 0)
42 t.Skipf("could not map a page at requested 0x%x: %s", base+off, errno)
44 defer syscall.Syscall(syscall.SYS_MUNMAP, base+off, 65536, 0)
47 s := unsafe.Slice((*byte)(unsafe.Pointer(base)), 3<<30)
50 t.Fatalf("copied %d bytes, expected %d", n, 3<<30-1)
54 t.Fatalf("copied %d bytes, expected %d", n, 3<<30-1)