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
76 extern Slice os_Args
asm ("libgo_os.os.Args");
77 extern Slice os_Envs
asm ("libgo_os.os.Envs");
80 runtime_args(int32 c
, byte
**v
)
92 // for windows implementation see "os" package
96 s
= runtime_malloc(argc
*sizeof s
[0]);
98 s
[i
] = runtime_gostringnocopy((byte
*)argv
[i
]);
99 os_Args
.__values
= (void*)s
;
100 os_Args
.__count
= argc
;
101 os_Args
.__capacity
= argc
;
110 for(n
=0; argv
[argc
+1+n
] != 0; n
++)
113 s
= runtime_malloc(n
*sizeof s
[0]);
115 s
[i
] = runtime_gostringnocopy(argv
[argc
+1+i
]);
116 os_Envs
.__values
= (void*)s
;
118 os_Envs
.__capacity
= n
;
122 runtime_getenv(const char *s
)
130 len
= runtime_findnull(bs
);
131 envv
= (String
*)os_Envs
.__values
;
132 envc
= os_Envs
.__count
;
133 for(i
=0; i
<envc
; i
++){
134 if(envv
[i
].__length
<= len
)
136 v
= (const byte
*)envv
[i
].__data
;
149 runtime_atoi(const byte
*p
)
154 while('0' <= *p
&& *p
<= '9')
155 n
= n
*10 + *p
++ - '0';
160 runtime_fastrand1(void)