1 // Copyright 2009 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.
16 maxround
= sizeof(uintptr
),
19 extern volatile intgo runtime_MemProfileRate
20 __asm__ (GOSYM_PREFIX
"runtime.MemProfileRate");
22 struct gotraceback_ret
{
27 extern struct gotraceback_ret
gotraceback(void)
28 __asm__ (GOSYM_PREFIX
"runtime.gotraceback");
30 // runtime_gotraceback is the C interface to runtime.gotraceback.
32 runtime_gotraceback(bool *crash
)
34 struct gotraceback_ret r
;
43 runtime_atoi(const byte
*p
, intgo len
)
48 while(len
> 0 && '0' <= *p
&& *p
<= '9') {
49 n
= n
*10 + *p
++ - '0';
56 runtime_fastrand1(void)
71 runtime_cputicks(void)
73 #if defined(__386__) || defined(__x86_64__)
75 asm("rdtsc" : "=a" (low
), "=d" (high
));
76 return (int64
)(((uint64
)high
<< 32) | (uint64
)low
);
77 #elif defined (__s390__) || defined (__s390x__)
79 /* stckf may not write the return variable in case of a clock error, so make
80 it read-write to prevent that the initialisation is optimised out.
81 Note: Targets below z9-109 will crash when executing store clock fast, i.e.
82 we don't support Go for machines older than that. */
83 asm volatile(".insn s,0xb27c0000,%0" /* stckf */ : "+Q" (clock
) : : "cc" );
86 // Currently cputicks() is used in blocking profiler and to seed runtime·fastrand1().
87 // runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
88 // TODO: need more entropy to better seed fastrand1.
89 return runtime_nanotime();
94 runtime_showframe(String s
, bool current
)
96 static int32 traceback
= -1;
98 if(current
&& runtime_m()->throwing
> 0)
101 traceback
= runtime_gotraceback(nil
);
102 return traceback
> 1 || (__builtin_memchr(s
.str
, '.', s
.len
) != nil
&& __builtin_memcmp(s
.str
, "runtime.", 7) != 0);
105 // Called to initialize a new m (including the bootstrap m).
106 // Called on the parent thread (main thread in case of bootstrap), can allocate memory.
108 runtime_mpreinit(M
*mp
)
110 int32 stacksize
= 32 * 1024; // OS X wants >=8K, Linux >=2K
113 if(stacksize
< SIGSTKSZ
)
114 stacksize
= SIGSTKSZ
;
117 mp
->gsignal
= runtime_malg(stacksize
, (byte
**)&mp
->gsignalstack
, &mp
->gsignalstacksize
);
121 // Called to initialize a new m (including the bootstrap m).
122 // Called on the new thread, can not allocate memory.
129 // Initialize signal handling.
131 runtime_signalstack(m
->gsignalstack
, m
->gsignalstacksize
);
132 if (sigemptyset(&sigs
) != 0)
133 runtime_throw("sigemptyset");
134 pthread_sigmask(SIG_SETMASK
, &sigs
, nil
);
137 // Called from dropm to undo the effect of an minit.
139 runtime_unminit(void)
141 runtime_signalstack(nil
, 0);
146 runtime_signalstack(byte
*p
, int32 n
)
154 st
.ss_flags
= SS_DISABLE
;
155 if(sigaltstack(&st
, nil
) < 0)
159 struct debugVars runtime_debug
;
162 runtime_setdebug(struct debugVars
* d
) {
166 // Setting the max stack size doesn't really do anything for gccgo.
168 uintptr runtime_maxstacksize
= 1<<20; // enough until runtime.main sets it for real
170 void memclrBytes(Slice
)
171 __asm__ (GOSYM_PREFIX
"runtime.memclrBytes");
176 runtime_memclr(s
.__values
, s
.__count
);
179 int32
go_open(char *, int32
, int32
)
180 __asm__ (GOSYM_PREFIX
"runtime.open");
183 go_open(char *name
, int32 mode
, int32 perm
)
185 return runtime_open(name
, mode
, perm
);
188 int32
go_read(int32
, void *, int32
)
189 __asm__ (GOSYM_PREFIX
"runtime.read");
192 go_read(int32 fd
, void *p
, int32 n
)
194 return runtime_read(fd
, p
, n
);
197 int32
go_write(uintptr
, void *, int32
)
198 __asm__ (GOSYM_PREFIX
"runtime.write");
201 go_write(uintptr fd
, void *p
, int32 n
)
203 return runtime_write(fd
, p
, n
);
206 int32
go_closefd(int32
)
207 __asm__ (GOSYM_PREFIX
"runtime.closefd");
212 return runtime_close(fd
);
216 __asm__ (GOSYM_PREFIX
"runtime.errno");