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