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.
16 // TestMemmoveOverflow maps 3GB of memory and calls memmove on
17 // the corresponding slice.
18 func TestMemmoveOverflow(t
*testing
.T
) {
20 // Create a temporary file.
21 tmp
, err
:= ioutil
.TempFile("", "go-memmovetest")
25 _
, err
= tmp
.Write(make([]byte, 65536))
29 defer os
.Remove(tmp
.Name())
33 base
, _
, errno
:= syscall
.Syscall6(syscall
.SYS_MMAP
,
34 0xa0<<32, 3<<30, syscall
.PROT_READ|syscall
.PROT_WRITE
, syscall
.MAP_PRIVATE|syscall
.MAP_ANONYMOUS
, ^uintptr(0), 0)
36 t
.Skipf("could not create memory mapping: %s", errno
)
38 syscall
.Syscall(syscall
.SYS_MUNMAP
, base
, 3<<30, 0)
40 for off
:= uintptr(0); off
< 3<<30; off
+= 65536 {
41 _
, _
, errno
:= syscall
.Syscall6(syscall
.SYS_MMAP
,
42 base
+off
, 65536, syscall
.PROT_READ|syscall
.PROT_WRITE
, syscall
.MAP_SHARED|syscall
.MAP_FIXED
, tmp
.Fd(), 0)
44 t
.Skipf("could not map a page at requested 0x%x: %s", base
+off
, errno
)
46 defer syscall
.Syscall(syscall
.SYS_MUNMAP
, base
+off
, 65536, 0)
50 sp
:= (*reflect
.SliceHeader
)(unsafe
.Pointer(&s
))
52 sp
.Len
, sp
.Cap
= 3<<30, 3<<30
56 t
.Fatalf("copied %d bytes, expected %d", n
, 3<<30-1)
60 t
.Fatalf("copied %d bytes, expected %d", n
, 3<<30-1)