mirror of
https://github.com/golang/go
synced 2024-11-06 13:46:16 -07:00
4f1b0a44cb
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
// Copyright 2013 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package runtime_test
|
|
|
|
import (
|
|
"os"
|
|
"reflect"
|
|
"syscall"
|
|
"testing"
|
|
"unsafe"
|
|
)
|
|
|
|
// TestMemmoveOverflow maps 3GB of memory and calls memmove on
|
|
// the corresponding slice.
|
|
func TestMemmoveOverflow(t *testing.T) {
|
|
t.Parallel()
|
|
// Create a temporary file.
|
|
tmp, err := os.CreateTemp("", "go-memmovetest")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = tmp.Write(make([]byte, 65536))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(tmp.Name())
|
|
defer tmp.Close()
|
|
|
|
// Set up mappings.
|
|
base, _, errno := syscall.Syscall6(syscall.SYS_MMAP,
|
|
0xa0<<32, 3<<30, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUS, ^uintptr(0), 0)
|
|
if errno != 0 {
|
|
t.Skipf("could not create memory mapping: %s", errno)
|
|
}
|
|
syscall.Syscall(syscall.SYS_MUNMAP, base, 3<<30, 0)
|
|
|
|
for off := uintptr(0); off < 3<<30; off += 65536 {
|
|
_, _, errno := syscall.Syscall6(syscall.SYS_MMAP,
|
|
base+off, 65536, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED|syscall.MAP_FIXED, tmp.Fd(), 0)
|
|
if errno != 0 {
|
|
t.Skipf("could not map a page at requested 0x%x: %s", base+off, errno)
|
|
}
|
|
defer syscall.Syscall(syscall.SYS_MUNMAP, base+off, 65536, 0)
|
|
}
|
|
|
|
var s []byte
|
|
sp := (*reflect.SliceHeader)(unsafe.Pointer(&s))
|
|
sp.Data = base
|
|
sp.Len, sp.Cap = 3<<30, 3<<30
|
|
|
|
n := copy(s[1:], s)
|
|
if n != 3<<30-1 {
|
|
t.Fatalf("copied %d bytes, expected %d", n, 3<<30-1)
|
|
}
|
|
n = copy(s, s[1:])
|
|
if n != 3<<30-1 {
|
|
t.Fatalf("copied %d bytes, expected %d", n, 3<<30-1)
|
|
}
|
|
}
|