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.
14 runtime_gotraceback(void)
18 p
= runtime_getenv("GOTRACEBACK");
19 if(p
== nil
|| p
[0] == '\0')
20 return 1; // default is on
21 return runtime_atoi(p
);
27 extern Slice os_Args
asm ("os.Args");
28 extern Slice syscall_Envs
asm ("syscall.Envs");
30 void (*runtime_sysargs
)(int32
, uint8
**);
33 runtime_args(int32 c
, byte
**v
)
37 if(runtime_sysargs
!= nil
)
38 runtime_sysargs(c
, v
);
44 return argc
== 0 ? nil
: argv
[0];
53 // for windows implementation see "os" package
57 s
= runtime_malloc(argc
*sizeof s
[0]);
59 s
[i
] = runtime_gostringnocopy((const byte
*)argv
[i
]);
60 os_Args
.__values
= (void*)s
;
61 os_Args
.__count
= argc
;
62 os_Args
.__capacity
= argc
;
66 runtime_goenvs_unix(void)
71 for(n
=0; argv
[argc
+1+n
] != 0; n
++)
74 s
= runtime_malloc(n
*sizeof s
[0]);
76 s
[i
] = runtime_gostringnocopy(argv
[argc
+1+i
]);
77 syscall_Envs
.__values
= (void*)s
;
78 syscall_Envs
.__count
= n
;
79 syscall_Envs
.__capacity
= n
;
83 runtime_getenv(const char *s
)
91 len
= runtime_findnull(bs
);
92 envv
= (String
*)syscall_Envs
.__values
;
93 envc
= syscall_Envs
.__count
;
94 for(i
=0; i
<envc
; i
++){
95 if(envv
[i
].len
<= len
)
97 v
= (const byte
*)envv
[i
].str
;
110 runtime_atoi(const byte
*p
)
115 while('0' <= *p
&& *p
<= '9')
116 n
= n
*10 + *p
++ - '0';
121 runtime_fastrand1(void)
135 static struct root_list runtime_roots
=
137 { { &syscall_Envs
, sizeof syscall_Envs
},
138 { &os_Args
, sizeof os_Args
},
145 __go_register_gc_roots(&runtime_roots
);
149 runtime_cputicks(void)
151 #if defined(__386__) || defined(__x86_64__)
153 asm("rdtsc" : "=a" (low
), "=d" (high
));
154 return (int64
)(((uint64
)high
<< 32) | (uint64
)low
);
156 // FIXME: implement for other processors.
162 runtime_showframe(const unsigned char *s
)
164 static int32 traceback
= -1;
167 traceback
= runtime_gotraceback();
168 return traceback
> 1 || (s
!= nil
&& __builtin_strchr((const char*)s
, '.') != nil
&& __builtin_memcmp(s
, "runtime.", 7) != 0);
171 static Lock ticksLock
;
175 runtime_tickspersecond(void)
177 int64 res
, t0
, t1
, c0
, c1
;
179 res
= (int64
)runtime_atomicload64((uint64
*)&ticks
);
182 runtime_lock(&ticksLock
);
185 t0
= runtime_nanotime();
186 c0
= runtime_cputicks();
187 runtime_usleep(100*1000);
188 t1
= runtime_nanotime();
189 c1
= runtime_cputicks();
192 res
= (c1
-c0
)*1000*1000*1000/(t1
-t0
);
195 runtime_atomicstore64((uint64
*)&ticks
, res
);
197 runtime_unlock(&ticksLock
);
201 int64
runtime_pprof_runtime_cyclesPerSecond(void)
202 asm("runtime_pprof.runtime_cyclesPerSecond");
205 runtime_pprof_runtime_cyclesPerSecond(void)
207 return runtime_tickspersecond();