syscall_nonhosted.mx raw

   1  //go:build baremetal || wasm_unknown
   2  
   3  package syscall
   4  
   5  import (
   6  	"internal/itoa"
   7  )
   8  
   9  // Most code here has been copied from the Go sources:
  10  //   https://github.com/golang/go/blob/go1.12/src/syscall/syscall_js.go
  11  // It has the following copyright note:
  12  //
  13  //     Copyright 2018 The Go Authors. All rights reserved.
  14  //     Use of this source code is governed by a BSD-style
  15  //     license that can be found in the LICENSE file.
  16  
  17  // A Signal is a number describing a process signal.
  18  // It implements the os.Signal interface.
  19  type Signal int
  20  
  21  const (
  22  	_ Signal = iota
  23  	SIGCHLD
  24  	SIGINT
  25  	SIGKILL
  26  	SIGTRAP
  27  	SIGQUIT
  28  	SIGTERM
  29  	SIGILL
  30  	SIGABRT
  31  	SIGBUS
  32  	SIGFPE
  33  	SIGSEGV
  34  	SIGPIPE
  35  )
  36  
  37  func (s Signal) Signal() {}
  38  
  39  func (s Signal) String() string {
  40  	if 0 <= s && int(s) < len(signals) {
  41  		str := signals[s]
  42  		if str != "" {
  43  			return str
  44  		}
  45  	}
  46  	return "signal " + itoa.Itoa(int(s))
  47  }
  48  
  49  var signals = [...]string{}
  50  
  51  // File system
  52  
  53  const (
  54  	Stdin  = 0
  55  	Stdout = 1
  56  	Stderr = 2
  57  )
  58  
  59  const (
  60  	O_RDONLY = 0
  61  	O_WRONLY = 1
  62  	O_RDWR   = 2
  63  
  64  	O_CREAT  = 0100
  65  	O_CREATE = O_CREAT
  66  	O_TRUNC  = 01000
  67  	O_APPEND = 02000
  68  	O_EXCL   = 0200
  69  	O_SYNC   = 010000
  70  
  71  	O_CLOEXEC = 0
  72  )
  73  
  74  // Dummy values to allow compiling tests
  75  // Dummy source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/mman.h.auto.html
  76  const (
  77  	PROT_NONE  = 0x00 // no permissions
  78  	PROT_READ  = 0x01 // pages can be read
  79  	PROT_WRITE = 0x02 // pages can be written
  80  	PROT_EXEC  = 0x04 // pages can be executed
  81  
  82  	MAP_SHARED  = 0x0001 // share changes
  83  	MAP_PRIVATE = 0x0002 // changes are private
  84  
  85  	MAP_FILE      = 0x0000 // map from file (default)
  86  	MAP_ANON      = 0x1000 // allocated from memory, swap space
  87  	MAP_ANONYMOUS = MAP_ANON
  88  )
  89  
  90  func Open(path string, mode int, perm uint32) (fd int, err error) {
  91  	return 0, ENOSYS
  92  }
  93  
  94  func Read(fd int, p []byte) (n int, err error) {
  95  	return 0, ENOSYS
  96  }
  97  
  98  func Seek(fd int, offset int64, whence int) (off int64, err error) {
  99  	return 0, ENOSYS
 100  }
 101  
 102  func Close(fd int) (err error) {
 103  	return ENOSYS
 104  }
 105  
 106  // Processes
 107  
 108  type WaitStatus uint32
 109  
 110  func (w WaitStatus) Exited() bool       { return false }
 111  func (w WaitStatus) ExitStatus() int    { return 0 }
 112  func (w WaitStatus) Signaled() bool     { return false }
 113  func (w WaitStatus) Signal() Signal     { return 0 }
 114  func (w WaitStatus) CoreDump() bool     { return false }
 115  func (w WaitStatus) Stopped() bool      { return false }
 116  func (w WaitStatus) Continued() bool    { return false }
 117  func (w WaitStatus) StopSignal() Signal { return 0 }
 118  func (w WaitStatus) TrapCause() int     { return 0 }
 119  
 120  // XXX made up
 121  type Rusage struct {
 122  	Utime Timeval
 123  	Stime Timeval
 124  }
 125  
 126  // XXX made up
 127  type ProcAttr struct {
 128  	Dir   string
 129  	Env   []string
 130  	Files []uintptr
 131  	Sys   *SysProcAttr
 132  }
 133  
 134  type SysProcAttr struct {
 135  }
 136  
 137  func Getgroups() ([]int, error)         { return []int{1}, nil }
 138  func Gettimeofday(tv *Timeval) error    { return ENOSYS }
 139  func Kill(pid int, signum Signal) error { return ENOSYS }
 140  func Pipe2(p []int, flags int) (err error) {
 141  	return ENOSYS // TODO
 142  }
 143  func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
 144  	return 0, ENOSYS
 145  }
 146  func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
 147  	return 0, 0, ENOSYS
 148  }
 149  func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
 150  	return 0, ENOSYS
 151  }
 152  
 153  func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
 154  	return nil, ENOSYS
 155  }
 156  
 157  func Munmap(b []byte) (err error) {
 158  	return ENOSYS
 159  }
 160  
 161  type Timeval struct {
 162  	Sec  int64
 163  	Usec int64
 164  }
 165  
 166  func Getpagesize() int {
 167  	// There is no right value to return here, but 4096 is a
 168  	// common assumption when pagesize is unknown
 169  	return 4096
 170  }
 171  
 172  type RawSockaddrInet4 struct {
 173  	// stub
 174  }
 175  
 176  type RawSockaddrInet6 struct {
 177  	// stub
 178  }
 179