75791bab05
Use the new -fgo-c-header option to build a header file for the Go runtime code in libgo/go/runtime, and use the new header file in the C runtime code in libgo/runtime. This will ensure that the Go code and C code share the same data structures as we convert the runtime from C to Go. The new file libgo/go/runtime/runtime2.go is copied from the Go 1.7 release, and then edited to remove unnecessary data structures and modify others for use with libgo. The new file libgo/go/runtime/mcache.go is an initial version of the same files in the Go 1.7 release, and will be replaced by the Go 1.7 file when we convert to the new memory allocator. The new file libgo/go/runtime/type.go describes the gccgo version of the reflection data structures, and replaces the Go 1.7 runtime file which describes the gc version of those structures. Using the new header file means changing a number of struct fields to use Go naming conventions (that is, no underscores) and to rename constants to have a leading underscore so that they are not exported from the Go package. These names were updated in the C code. The C code was also changed to drop the thread-local variable m, as was done some time ago in the gc sources. Now the m field is always accessed using g->m, where g is the single remaining thread-local variable. This in turn required some adjustments to set g->m correctly in all cases. Also pass the new -fgo-compiling-runtime option when compiling the runtime package, although that option doesn't do anything yet. Reviewed-on: https://go-review.googlesource.com/28051 From-SVN: r239872
177 lines
3.4 KiB
C
177 lines
3.4 KiB
C
// Copyright 2012 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "runtime.h"
|
|
#include "defs.h"
|
|
#include "signal_unix.h"
|
|
|
|
extern SigTab runtime_sigtab[];
|
|
|
|
void
|
|
runtime_initsig(bool preinit)
|
|
{
|
|
int32 i;
|
|
SigTab *t;
|
|
|
|
// For c-archive/c-shared this is called by go-libmain.c with
|
|
// preinit == true.
|
|
if(runtime_isarchive && !preinit)
|
|
return;
|
|
|
|
// First call: basic setup.
|
|
for(i = 0; runtime_sigtab[i].sig != -1; i++) {
|
|
t = &runtime_sigtab[i];
|
|
if((t->flags == 0) || (t->flags & _SigDefault))
|
|
continue;
|
|
|
|
t->fwdsig = runtime_getsig(i);
|
|
|
|
// For some signals, we respect an inherited SIG_IGN handler
|
|
// rather than insist on installing our own default handler.
|
|
// Even these signals can be fetched using the os/signal package.
|
|
switch(t->sig) {
|
|
case SIGHUP:
|
|
case SIGINT:
|
|
if(t->fwdsig == GO_SIG_IGN) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if(runtime_isarchive && (t->flags&_SigPanic) == 0)
|
|
continue;
|
|
|
|
t->flags |= _SigHandling;
|
|
runtime_setsig(i, runtime_sighandler, true);
|
|
}
|
|
}
|
|
|
|
void
|
|
runtime_sigenable(uint32 sig)
|
|
{
|
|
int32 i;
|
|
SigTab *t;
|
|
|
|
t = nil;
|
|
for(i = 0; runtime_sigtab[i].sig != -1; i++) {
|
|
if(runtime_sigtab[i].sig == (int32)sig) {
|
|
t = &runtime_sigtab[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(t == nil)
|
|
return;
|
|
|
|
if((t->flags & _SigNotify) && !(t->flags & _SigHandling)) {
|
|
t->flags |= _SigHandling;
|
|
t->fwdsig = runtime_getsig(i);
|
|
runtime_setsig(i, runtime_sighandler, true);
|
|
}
|
|
}
|
|
|
|
void
|
|
runtime_sigdisable(uint32 sig)
|
|
{
|
|
int32 i;
|
|
SigTab *t;
|
|
|
|
t = nil;
|
|
for(i = 0; runtime_sigtab[i].sig != -1; i++) {
|
|
if(runtime_sigtab[i].sig == (int32)sig) {
|
|
t = &runtime_sigtab[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(t == nil)
|
|
return;
|
|
|
|
if((sig == SIGHUP || sig == SIGINT) && t->fwdsig == GO_SIG_IGN) {
|
|
t->flags &= ~_SigHandling;
|
|
runtime_setsig(i, t->fwdsig, true);
|
|
}
|
|
}
|
|
|
|
void
|
|
runtime_sigignore(uint32 sig)
|
|
{
|
|
int32 i;
|
|
SigTab *t;
|
|
|
|
t = nil;
|
|
for(i = 0; runtime_sigtab[i].sig != -1; i++) {
|
|
if(runtime_sigtab[i].sig == (int32)sig) {
|
|
t = &runtime_sigtab[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(t == nil)
|
|
return;
|
|
|
|
if((t->flags & _SigNotify) != 0) {
|
|
t->flags &= ~_SigHandling;
|
|
runtime_setsig(i, GO_SIG_IGN, true);
|
|
}
|
|
}
|
|
|
|
void
|
|
runtime_resetcpuprofiler(int32 hz)
|
|
{
|
|
struct itimerval it;
|
|
|
|
runtime_memclr((byte*)&it, sizeof it);
|
|
if(hz == 0) {
|
|
runtime_setitimer(ITIMER_PROF, &it, nil);
|
|
} else {
|
|
it.it_interval.tv_sec = 0;
|
|
it.it_interval.tv_usec = 1000000 / hz;
|
|
it.it_value = it.it_interval;
|
|
runtime_setitimer(ITIMER_PROF, &it, nil);
|
|
}
|
|
runtime_m()->profilehz = hz;
|
|
}
|
|
|
|
void
|
|
runtime_unblocksignals(void)
|
|
{
|
|
sigset_t sigset_none;
|
|
sigemptyset(&sigset_none);
|
|
pthread_sigmask(SIG_SETMASK, &sigset_none, nil);
|
|
}
|
|
|
|
void
|
|
runtime_crash(void)
|
|
{
|
|
int32 i;
|
|
|
|
#ifdef GOOS_darwin
|
|
// OS X core dumps are linear dumps of the mapped memory,
|
|
// from the first virtual byte to the last, with zeros in the gaps.
|
|
// Because of the way we arrange the address space on 64-bit systems,
|
|
// this means the OS X core file will be >128 GB and even on a zippy
|
|
// workstation can take OS X well over an hour to write (uninterruptible).
|
|
// Save users from making that mistake.
|
|
if(sizeof(void*) == 8)
|
|
return;
|
|
#endif
|
|
|
|
runtime_unblocksignals();
|
|
for(i = 0; runtime_sigtab[i].sig != -1; i++)
|
|
if(runtime_sigtab[i].sig == SIGABRT)
|
|
break;
|
|
runtime_setsig(i, GO_SIG_DFL, false);
|
|
runtime_raise(SIGABRT);
|
|
}
|
|
|
|
void
|
|
runtime_raise(int32 sig)
|
|
{
|
|
raise(sig);
|
|
}
|