forked from dvyukov/go-fuzz
/
sys_posix.go
43 lines (35 loc) · 1016 Bytes
/
sys_posix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2015 Dmitry Vyukov. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// +build darwin linux freebsd dragonfly
package main
import (
"log"
"os"
"os/exec"
"syscall"
)
func lowerProcessPrio() {
syscall.Setpriority(syscall.PRIO_PROCESS, 0, 19)
}
type Mapping struct {
f *os.File
}
func createMapping(name string, size int) (*Mapping, []byte) {
f, err := os.OpenFile(name, os.O_RDWR, 0)
if err != nil {
log.Fatalf("failed to open comm file: %v", err)
}
mem, err := syscall.Mmap(int(f.Fd()), 0, size, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
if err != nil {
log.Fatalf("failed to mmap comm file: %v", err)
}
return &Mapping{f}, mem
}
func (m *Mapping) destroy() {
m.f.Close()
}
func setupCommMapping(cmd *exec.Cmd, comm *Mapping, rOut, wIn *os.File) {
cmd.ExtraFiles = append(cmd.ExtraFiles, comm.f)
cmd.ExtraFiles = append(cmd.ExtraFiles, rOut)
cmd.ExtraFiles = append(cmd.ExtraFiles, wIn)
}