github.com/rafaeltorres324/go/src@v0.0.0-20210519164414-9fdf653a9838/runtime/os_js.go (about)

     1  // Copyright 2018 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.
     4  
     5  // +build js,wasm
     6  
     7  package runtime
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  func exit(code int32)
    14  
    15  func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
    16  	if fd > 2 {
    17  		throw("runtime.write to fd > 2 is unsupported")
    18  	}
    19  	wasmWrite(fd, p, n)
    20  	return n
    21  }
    22  
    23  // Stubs so tests can link correctly. These should never be called.
    24  func open(name *byte, mode, perm int32) int32        { panic("not implemented") }
    25  func closefd(fd int32) int32                         { panic("not implemented") }
    26  func read(fd int32, p unsafe.Pointer, n int32) int32 { panic("not implemented") }
    27  
    28  //go:noescape
    29  func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
    30  
    31  func usleep(usec uint32)
    32  
    33  func exitThread(wait *uint32)
    34  
    35  type mOS struct{}
    36  
    37  func osyield()
    38  
    39  const _SIGSEGV = 0xb
    40  
    41  func sigpanic() {
    42  	g := getg()
    43  	if !canpanic(g) {
    44  		throw("unexpected signal during runtime execution")
    45  	}
    46  
    47  	// js only invokes the exception handler for memory faults.
    48  	g.sig = _SIGSEGV
    49  	panicmem()
    50  }
    51  
    52  type sigset struct{}
    53  
    54  // Called to initialize a new m (including the bootstrap m).
    55  // Called on the parent thread (main thread in case of bootstrap), can allocate memory.
    56  func mpreinit(mp *m) {
    57  	mp.gsignal = malg(32 * 1024)
    58  	mp.gsignal.m = mp
    59  }
    60  
    61  //go:nosplit
    62  func sigsave(p *sigset) {
    63  }
    64  
    65  //go:nosplit
    66  func msigrestore(sigmask sigset) {
    67  }
    68  
    69  //go:nosplit
    70  //go:nowritebarrierrec
    71  func clearSignalHandlers() {
    72  }
    73  
    74  //go:nosplit
    75  func sigblock(exiting bool) {
    76  }
    77  
    78  // Called to initialize a new m (including the bootstrap m).
    79  // Called on the new thread, cannot allocate memory.
    80  func minit() {
    81  }
    82  
    83  // Called from dropm to undo the effect of an minit.
    84  func unminit() {
    85  }
    86  
    87  // Called from exitm, but not from drop, to undo the effect of thread-owned
    88  // resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
    89  func mdestroy(mp *m) {
    90  }
    91  
    92  func osinit() {
    93  	ncpu = 1
    94  	getg().m.procid = 2
    95  	physPageSize = 64 * 1024
    96  }
    97  
    98  // wasm has no signals
    99  const _NSIG = 0
   100  
   101  func signame(sig uint32) string {
   102  	return ""
   103  }
   104  
   105  func crash() {
   106  	*(*int32)(nil) = 0
   107  }
   108  
   109  func getRandomData(r []byte)
   110  
   111  func goenvs() {
   112  	goenvs_unix()
   113  }
   114  
   115  func initsig(preinit bool) {
   116  }
   117  
   118  // May run with m.p==nil, so write barriers are not allowed.
   119  //go:nowritebarrier
   120  func newosproc(mp *m) {
   121  	panic("newosproc: not implemented")
   122  }
   123  
   124  func setProcessCPUProfiler(hz int32) {}
   125  func setThreadCPUProfiler(hz int32)  {}
   126  func sigdisable(uint32)              {}
   127  func sigenable(uint32)               {}
   128  func sigignore(uint32)               {}
   129  
   130  //go:linkname os_sigpipe os.sigpipe
   131  func os_sigpipe() {
   132  	throw("too many writes on closed pipe")
   133  }
   134  
   135  //go:nosplit
   136  func cputicks() int64 {
   137  	// Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
   138  	// runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
   139  	return nanotime()
   140  }
   141  
   142  //go:linkname syscall_now syscall.now
   143  func syscall_now() (sec int64, nsec int32) {
   144  	sec, nsec, _ = time_now()
   145  	return
   146  }
   147  
   148  // gsignalStack is unused on js.
   149  type gsignalStack struct{}
   150  
   151  const preemptMSupported = false
   152  
   153  func preemptM(mp *m) {
   154  	// No threads, so nothing to do.
   155  }