OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "defs_GOOS_GOARCH.h" | 6 #include "defs_GOOS_GOARCH.h" |
7 #include "os_GOOS.h" | 7 #include "os_GOOS.h" |
8 #include "stack.h" | 8 #include "stack.h" |
9 | 9 |
10 extern SigTab runtime·sigtab[]; | 10 extern SigTab runtime·sigtab[]; |
11 | 11 |
12 int32 runtime·open(uint8*, int32, int32); | |
13 int32 runtime·close(int32); | |
14 int32 runtime·read(int32, void*, int32); | |
15 | |
16 static Sigset sigset_none; | 12 static Sigset sigset_none; |
17 static Sigset sigset_all = { ~(uint32)0, ~(uint32)0 }; | 13 static Sigset sigset_all = { ~(uint32)0, ~(uint32)0 }; |
18 | 14 |
19 // Linux futex. | 15 // Linux futex. |
20 // | 16 // |
21 // futexsleep(uint32 *addr, uint32 val) | 17 // futexsleep(uint32 *addr, uint32 val) |
22 // futexwakeup(uint32 *addr) | 18 // futexwakeup(uint32 *addr) |
23 // | 19 // |
24 // Futexsleep atomically checks if *addr == val and if so, sleeps on addr. | 20 // Futexsleep atomically checks if *addr == val and if so, sleeps on addr. |
25 // Futexwakeup wakes up threads sleeping on addr. | 21 // Futexwakeup wakes up threads sleeping on addr. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 if(ret < 0) { | 151 if(ret < 0) { |
156 runtime·printf("runtime: failed to create new OS thread (have %d
already; errno=%d)\n", runtime·mcount(), -ret); | 152 runtime·printf("runtime: failed to create new OS thread (have %d
already; errno=%d)\n", runtime·mcount(), -ret); |
157 runtime·throw("runtime.newosproc"); | 153 runtime·throw("runtime.newosproc"); |
158 } | 154 } |
159 } | 155 } |
160 | 156 |
161 void | 157 void |
162 runtime·osinit(void) | 158 runtime·osinit(void) |
163 { | 159 { |
164 runtime·ncpu = getproccount(); | 160 runtime·ncpu = getproccount(); |
| 161 |
| 162 if (runtime·startup_random_data == nil) { |
| 163 static byte urandom_data[HashRandomBytes]; |
| 164 int32 fd = runtime·open((uint8*)"/dev/urandom", 0 /* O_RDONLY */
, 0); |
| 165 if (runtime·read(fd, urandom_data, HashRandomBytes) == HashRando
mBytes) { |
| 166 runtime·startup_random_data = urandom_data; |
| 167 runtime·startup_random_data_len = HashRandomBytes; |
| 168 } |
| 169 runtime·close(fd); |
| 170 } |
165 } | 171 } |
166 | 172 |
167 void | 173 void |
168 runtime·goenvs(void) | 174 runtime·goenvs(void) |
169 { | 175 { |
170 runtime·goenvs_unix(); | 176 runtime·goenvs_unix(); |
171 } | 177 } |
172 | 178 |
173 // Called to initialize a new m (including the bootstrap m). | 179 // Called to initialize a new m (including the bootstrap m). |
174 // Called on the parent thread (main thread in case of bootstrap), can allocate
memory. | 180 // Called on the parent thread (main thread in case of bootstrap), can allocate
memory. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 289 } |
284 runtime·write(2, badsignal, sizeof badsignal - 1); | 290 runtime·write(2, badsignal, sizeof badsignal - 1); |
285 if (0 <= sig && sig < NSIG) { | 291 if (0 <= sig && sig < NSIG) { |
286 // Call runtime·findnull dynamically to circumvent static stack
size check. | 292 // Call runtime·findnull dynamically to circumvent static stack
size check. |
287 static int32 (*findnull)(byte*) = runtime·findnull; | 293 static int32 (*findnull)(byte*) = runtime·findnull; |
288 runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runti
me·sigtab[sig].name)); | 294 runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runti
me·sigtab[sig].name)); |
289 } | 295 } |
290 runtime·write(2, "\n", 1); | 296 runtime·write(2, "\n", 1); |
291 runtime·exit(1); | 297 runtime·exit(1); |
292 } | 298 } |
OLD | NEW |