aboutsummaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-03-08 02:05:54 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-03-09 22:50:14 +0800
commit5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8 (patch)
tree19e34d409d1a999079e007698f33766973676bc8 /vendor
parentb7d93500f13e3054c81196273ebf676ad8ecb5ba (diff)
downloadgo-tangerine-5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8.tar
go-tangerine-5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8.tar.gz
go-tangerine-5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8.tar.bz2
go-tangerine-5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8.tar.lz
go-tangerine-5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8.tar.xz
go-tangerine-5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8.tar.zst
go-tangerine-5c8fa6ae1a42813e7aec477bd68d98f66f85e0b8.zip
crypto, pow, vendor: hash optimizations, mmap ethash
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/edsrzf/mmap-go/LICENSE25
-rw-r--r--vendor/github.com/edsrzf/mmap-go/README.md12
-rw-r--r--vendor/github.com/edsrzf/mmap-go/mmap.go112
-rw-r--r--vendor/github.com/edsrzf/mmap-go/mmap_unix.go67
-rw-r--r--vendor/github.com/edsrzf/mmap-go/mmap_windows.go125
-rw-r--r--vendor/github.com/edsrzf/mmap-go/msync_netbsd.go8
-rw-r--r--vendor/github.com/edsrzf/mmap-go/msync_unix.go14
-rw-r--r--vendor/vendor.json6
8 files changed, 369 insertions, 0 deletions
diff --git a/vendor/github.com/edsrzf/mmap-go/LICENSE b/vendor/github.com/edsrzf/mmap-go/LICENSE
new file mode 100644
index 000000000..8f05f338a
--- /dev/null
+++ b/vendor/github.com/edsrzf/mmap-go/LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2011, Evan Shaw <edsrzf@gmail.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the copyright holder nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/vendor/github.com/edsrzf/mmap-go/README.md b/vendor/github.com/edsrzf/mmap-go/README.md
new file mode 100644
index 000000000..4cc2bfe1c
--- /dev/null
+++ b/vendor/github.com/edsrzf/mmap-go/README.md
@@ -0,0 +1,12 @@
+mmap-go
+=======
+
+mmap-go is a portable mmap package for the [Go programming language](http://golang.org).
+It has been tested on Linux (386, amd64), OS X, and Windows (386). It should also
+work on other Unix-like platforms, but hasn't been tested with them. I'm interested
+to hear about the results.
+
+I haven't been able to add more features without adding significant complexity,
+so mmap-go doesn't support mprotect, mincore, and maybe a few other things.
+If you're running on a Unix-like platform and need some of these features,
+I suggest Gustavo Niemeyer's [gommap](http://labix.org/gommap).
diff --git a/vendor/github.com/edsrzf/mmap-go/mmap.go b/vendor/github.com/edsrzf/mmap-go/mmap.go
new file mode 100644
index 000000000..7bb4965ed
--- /dev/null
+++ b/vendor/github.com/edsrzf/mmap-go/mmap.go
@@ -0,0 +1,112 @@
+// Copyright 2011 Evan Shaw. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file defines the common package interface and contains a little bit of
+// factored out logic.
+
+// Package mmap allows mapping files into memory. It tries to provide a simple, reasonably portable interface,
+// but doesn't go out of its way to abstract away every little platform detail.
+// This specifically means:
+// * forked processes may or may not inherit mappings
+// * a file's timestamp may or may not be updated by writes through mappings
+// * specifying a size larger than the file's actual size can increase the file's size
+// * If the mapped file is being modified by another process while your program's running, don't expect consistent results between platforms
+package mmap
+
+import (
+ "errors"
+ "os"
+ "reflect"
+ "unsafe"
+)
+
+const (
+ // RDONLY maps the memory read-only.
+ // Attempts to write to the MMap object will result in undefined behavior.
+ RDONLY = 0
+ // RDWR maps the memory as read-write. Writes to the MMap object will update the
+ // underlying file.
+ RDWR = 1 << iota
+ // COPY maps the memory as copy-on-write. Writes to the MMap object will affect
+ // memory, but the underlying file will remain unchanged.
+ COPY
+ // If EXEC is set, the mapped memory is marked as executable.
+ EXEC
+)
+
+const (
+ // If the ANON flag is set, the mapped memory will not be backed by a file.
+ ANON = 1 << iota
+)
+
+// MMap represents a file mapped into memory.
+type MMap []byte
+
+// Map maps an entire file into memory.
+// If ANON is set in flags, f is ignored.
+func Map(f *os.File, prot, flags int) (MMap, error) {
+ return MapRegion(f, -1, prot, flags, 0)
+}
+
+// MapRegion maps part of a file into memory.
+// The offset parameter must be a multiple of the system's page size.
+// If length < 0, the entire file will be mapped.
+// If ANON is set in flags, f is ignored.
+func MapRegion(f *os.File, length int, prot, flags int, offset int64) (MMap, error) {
+ var fd uintptr
+ if flags&ANON == 0 {
+ fd = uintptr(f.Fd())
+ if length < 0 {
+ fi, err := f.Stat()
+ if err != nil {
+ return nil, err
+ }
+ length = int(fi.Size())
+ }
+ } else {
+ if length <= 0 {
+ return nil, errors.New("anonymous mapping requires non-zero length")
+ }
+ fd = ^uintptr(0)
+ }
+ return mmap(length, uintptr(prot), uintptr(flags), fd, offset)
+}
+
+func (m *MMap) header() *reflect.SliceHeader {
+ return (*reflect.SliceHeader)(unsafe.Pointer(m))
+}
+
+// Lock keeps the mapped region in physical memory, ensuring that it will not be
+// swapped out.
+func (m MMap) Lock() error {
+ dh := m.header()
+ return lock(dh.Data, uintptr(dh.Len))
+}
+
+// Unlock reverses the effect of Lock, allowing the mapped region to potentially
+// be swapped out.
+// If m is already unlocked, aan error will result.
+func (m MMap) Unlock() error {
+ dh := m.header()
+ return unlock(dh.Data, uintptr(dh.Len))
+}
+
+// Flush synchronizes the mapping's contents to the file's contents on disk.
+func (m MMap) Flush() error {
+ dh := m.header()
+ return flush(dh.Data, uintptr(dh.Len))
+}
+
+// Unmap deletes the memory mapped region, flushes any remaining changes, and sets
+// m to nil.
+// Trying to read or write any remaining references to m after Unmap is called will
+// result in undefined behavior.
+// Unmap should only be called on the slice value that was originally returned from
+// a call to Map. Calling Unmap on a derived slice may cause errors.
+func (m *MMap) Unmap() error {
+ dh := m.header()
+ err := unmap(dh.Data, uintptr(dh.Len))
+ *m = nil
+ return err
+}
diff --git a/vendor/github.com/edsrzf/mmap-go/mmap_unix.go b/vendor/github.com/edsrzf/mmap-go/mmap_unix.go
new file mode 100644
index 000000000..4af98420d
--- /dev/null
+++ b/vendor/github.com/edsrzf/mmap-go/mmap_unix.go
@@ -0,0 +1,67 @@
+// Copyright 2011 Evan Shaw. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin dragonfly freebsd linux openbsd solaris netbsd
+
+package mmap
+
+import (
+ "syscall"
+)
+
+func mmap(len int, inprot, inflags, fd uintptr, off int64) ([]byte, error) {
+ flags := syscall.MAP_SHARED
+ prot := syscall.PROT_READ
+ switch {
+ case inprot&COPY != 0:
+ prot |= syscall.PROT_WRITE
+ flags = syscall.MAP_PRIVATE
+ case inprot&RDWR != 0:
+ prot |= syscall.PROT_WRITE
+ }
+ if inprot&EXEC != 0 {
+ prot |= syscall.PROT_EXEC
+ }
+ if inflags&ANON != 0 {
+ flags |= syscall.MAP_ANON
+ }
+
+ b, err := syscall.Mmap(int(fd), off, len, prot, flags)
+ if err != nil {
+ return nil, err
+ }
+ return b, nil
+}
+
+func flush(addr, len uintptr) error {
+ _, _, errno := syscall.Syscall(_SYS_MSYNC, addr, len, _MS_SYNC)
+ if errno != 0 {
+ return syscall.Errno(errno)
+ }
+ return nil
+}
+
+func lock(addr, len uintptr) error {
+ _, _, errno := syscall.Syscall(syscall.SYS_MLOCK, addr, len, 0)
+ if errno != 0 {
+ return syscall.Errno(errno)
+ }
+ return nil
+}
+
+func unlock(addr, len uintptr) error {
+ _, _, errno := syscall.Syscall(syscall.SYS_MUNLOCK, addr, len, 0)
+ if errno != 0 {
+ return syscall.Errno(errno)
+ }
+ return nil
+}
+
+func unmap(addr, len uintptr) error {
+ _, _, errno := syscall.Syscall(syscall.SYS_MUNMAP, addr, len, 0)
+ if errno != 0 {
+ return syscall.Errno(errno)
+ }
+ return nil
+}
diff --git a/vendor/github.com/edsrzf/mmap-go/mmap_windows.go b/vendor/github.com/edsrzf/mmap-go/mmap_windows.go
new file mode 100644
index 000000000..c3d2d02d3
--- /dev/null
+++ b/vendor/github.com/edsrzf/mmap-go/mmap_windows.go
@@ -0,0 +1,125 @@
+// Copyright 2011 Evan Shaw. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package mmap
+
+import (
+ "errors"
+ "os"
+ "sync"
+ "syscall"
+)
+
+// mmap on Windows is a two-step process.
+// First, we call CreateFileMapping to get a handle.
+// Then, we call MapviewToFile to get an actual pointer into memory.
+// Because we want to emulate a POSIX-style mmap, we don't want to expose
+// the handle -- only the pointer. We also want to return only a byte slice,
+// not a struct, so it's convenient to manipulate.
+
+// We keep this map so that we can get back the original handle from the memory address.
+var handleLock sync.Mutex
+var handleMap = map[uintptr]syscall.Handle{}
+
+func mmap(len int, prot, flags, hfile uintptr, off int64) ([]byte, error) {
+ flProtect := uint32(syscall.PAGE_READONLY)
+ dwDesiredAccess := uint32(syscall.FILE_MAP_READ)
+ switch {
+ case prot&COPY != 0:
+ flProtect = syscall.PAGE_WRITECOPY
+ dwDesiredAccess = syscall.FILE_MAP_COPY
+ case prot&RDWR != 0:
+ flProtect = syscall.PAGE_READWRITE
+ dwDesiredAccess = syscall.FILE_MAP_WRITE
+ }
+ if prot&EXEC != 0 {
+ flProtect <<= 4
+ dwDesiredAccess |= syscall.FILE_MAP_EXECUTE
+ }
+
+ // The maximum size is the area of the file, starting from 0,
+ // that we wish to allow to be mappable. It is the sum of
+ // the length the user requested, plus the offset where that length
+ // is starting from. This does not map the data into memory.
+ maxSizeHigh := uint32((off + int64(len)) >> 32)
+ maxSizeLow := uint32((off + int64(len)) & 0xFFFFFFFF)
+ // TODO: Do we need to set some security attributes? It might help portability.
+ h, errno := syscall.CreateFileMapping(syscall.Handle(hfile), nil, flProtect, maxSizeHigh, maxSizeLow, nil)
+ if h == 0 {
+ return nil, os.NewSyscallError("CreateFileMapping", errno)
+ }
+
+ // Actually map a view of the data into memory. The view's size
+ // is the length the user requested.
+ fileOffsetHigh := uint32(off >> 32)
+ fileOffsetLow := uint32(off & 0xFFFFFFFF)
+ addr, errno := syscall.MapViewOfFile(h, dwDesiredAccess, fileOffsetHigh, fileOffsetLow, uintptr(len))
+ if addr == 0 {
+ return nil, os.NewSyscallError("MapViewOfFile", errno)
+ }
+ handleLock.Lock()
+ handleMap[addr] = h
+ handleLock.Unlock()
+
+ m := MMap{}
+ dh := m.header()
+ dh.Data = addr
+ dh.Len = len
+ dh.Cap = dh.Len
+
+ return m, nil
+}
+
+func flush(addr, len uintptr) error {
+ errno := syscall.FlushViewOfFile(addr, len)
+ if errno != nil {
+ return os.NewSyscallError("FlushViewOfFile", errno)
+ }
+
+ handleLock.Lock()
+ defer handleLock.Unlock()
+ handle, ok := handleMap[addr]
+ if !ok {
+ // should be impossible; we would've errored above
+ return errors.New("unknown base address")
+ }
+
+ errno = syscall.FlushFileBuffers(handle)
+ return os.NewSyscallError("FlushFileBuffers", errno)
+}
+
+func lock(addr, len uintptr) error {
+ errno := syscall.VirtualLock(addr, len)
+ return os.NewSyscallError("VirtualLock", errno)
+}
+
+func unlock(addr, len uintptr) error {
+ errno := syscall.VirtualUnlock(addr, len)
+ return os.NewSyscallError("VirtualUnlock", errno)
+}
+
+func unmap(addr, len uintptr) error {
+ flush(addr, len)
+ // Lock the UnmapViewOfFile along with the handleMap deletion.
+ // As soon as we unmap the view, the OS is free to give the
+ // same addr to another new map. We don't want another goroutine
+ // to insert and remove the same addr into handleMap while
+ // we're trying to remove our old addr/handle pair.
+ handleLock.Lock()
+ defer handleLock.Unlock()
+ err := syscall.UnmapViewOfFile(addr)
+ if err != nil {
+ return err
+ }
+
+ handle, ok := handleMap[addr]
+ if !ok {
+ // should be impossible; we would've errored above
+ return errors.New("unknown base address")
+ }
+ delete(handleMap, addr)
+
+ e := syscall.CloseHandle(syscall.Handle(handle))
+ return os.NewSyscallError("CloseHandle", e)
+}
diff --git a/vendor/github.com/edsrzf/mmap-go/msync_netbsd.go b/vendor/github.com/edsrzf/mmap-go/msync_netbsd.go
new file mode 100644
index 000000000..a64b003e2
--- /dev/null
+++ b/vendor/github.com/edsrzf/mmap-go/msync_netbsd.go
@@ -0,0 +1,8 @@
+// Copyright 2011 Evan Shaw. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package mmap
+
+const _SYS_MSYNC = 277
+const _MS_SYNC = 0x04
diff --git a/vendor/github.com/edsrzf/mmap-go/msync_unix.go b/vendor/github.com/edsrzf/mmap-go/msync_unix.go
new file mode 100644
index 000000000..91ee5f40f
--- /dev/null
+++ b/vendor/github.com/edsrzf/mmap-go/msync_unix.go
@@ -0,0 +1,14 @@
+// Copyright 2011 Evan Shaw. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin dragonfly freebsd linux openbsd solaris
+
+package mmap
+
+import (
+ "syscall"
+)
+
+const _SYS_MSYNC = syscall.SYS_MSYNC
+const _MS_SYNC = syscall.MS_SYNC
diff --git a/vendor/vendor.json b/vendor/vendor.json
index eb6d3ac62..58bbd82ff 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -35,6 +35,12 @@
"revisionTime": "2016-10-29T20:57:26Z"
},
{
+ "checksumSHA1": "zYnPsNAVm1/ViwCkN++dX2JQhBo=",
+ "path": "github.com/edsrzf/mmap-go",
+ "revision": "935e0e8a636ca4ba70b713f3e38a19e1b77739e8",
+ "revisionTime": "2016-05-12T03:30:02Z"
+ },
+ {
"checksumSHA1": "7oFpbmDfGobwKsFLIf6wMUvVoKw=",
"path": "github.com/fatih/color",
"revision": "5ec5d9d3c2cf82e9688b34e9bc27a94d616a7193",