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.
10 #include "go-string.h"
12 uint32 runtime_panicking;
17 runtime_startpanic(void)
23 runtime_printf("panic during panic\n");
27 runtime_xadd(&runtime_panicking, 1);
28 runtime_lock(&paniclk);
32 runtime_dopanic(int32 unused __attribute__ ((unused)))
35 static bool didothers;
38 runtime_printf("[signal %x code=%p addr=%p pc=%p]\n",
39 g->sig, g->sigcode0, g->sigcode1, g->sigpc);
41 if(runtime_gotraceback()){
44 runtime_tracebackothers(g);
49 runtime_unlock(&paniclk);
50 if(runtime_xadd(&runtime_panicking, -1) != 0) {
51 // Some other m is panicking too.
52 // Let it print what it needs to print.
53 // Wait forever without chewing up cpu.
54 // It will exit when it's done.
56 runtime_lock(&deadlock);
57 runtime_lock(&deadlock);
64 runtime_throw(const char *s)
67 runtime_printf("throw: %s\n", s);
69 *(int32*)0 = 0; // not reached
70 runtime_exit(1); // even more not reached
74 runtime_panicstring(const char *s)
78 if(runtime_m()->gcing) {
79 runtime_printf("panic: %s\n", s);
80 runtime_throw("panic during gc");
82 runtime_newErrorString(runtime_gostringnocopy((const byte*)s), &err);
89 extern Slice os_Args asm ("libgo_os.os.Args");
90 extern Slice os_Envs asm ("libgo_os.os.Envs");
93 runtime_args(int32 c, byte **v)
105 // for windows implementation see "os" package
109 s = runtime_malloc(argc*sizeof s[0]);
110 for(i=0; i<argc; i++)
111 s[i] = runtime_gostringnocopy((const byte*)argv[i]);
112 os_Args.__values = (void*)s;
113 os_Args.__count = argc;
114 os_Args.__capacity = argc;
123 for(n=0; argv[argc+1+n] != 0; n++)
126 s = runtime_malloc(n*sizeof s[0]);
128 s[i] = runtime_gostringnocopy(argv[argc+1+i]);
129 os_Envs.__values = (void*)s;
131 os_Envs.__capacity = n;
135 runtime_getenv(const char *s)
143 len = runtime_findnull(bs);
144 envv = (String*)os_Envs.__values;
145 envc = os_Envs.__count;
146 for(i=0; i<envc; i++){
147 if(envv[i].__length <= len)
149 v = (const byte*)envv[i].__data;
162 runtime_atoi(const byte *p)
167 while('0' <= *p && *p <= '9')
168 n = n*10 + *p++ - '0';
173 runtime_fastrand1(void)