2008-06-21 16:36:23 -06:00
|
|
|
// Copyright 2009 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.
|
|
|
|
|
|
|
|
#include "runtime.h"
|
2009-03-24 14:17:10 -06:00
|
|
|
#include "defs.h"
|
2009-03-24 16:04:18 -06:00
|
|
|
#include "os.h"
|
2008-09-18 16:56:46 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
extern SigTab runtime·sigtab[];
|
2010-04-08 19:15:30 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// Linux futex.
|
2008-08-04 17:43:49 -06:00
|
|
|
//
|
2008-08-05 15:18:47 -06:00
|
|
|
// futexsleep(uint32 *addr, uint32 val)
|
|
|
|
// futexwakeup(uint32 *addr)
|
2008-08-04 17:43:49 -06:00
|
|
|
//
|
2008-08-05 15:18:47 -06:00
|
|
|
// Futexsleep atomically checks if *addr == val and if so, sleeps on addr.
|
|
|
|
// Futexwakeup wakes up one thread sleeping on addr.
|
|
|
|
// Futexsleep is allowed to wake up spuriously.
|
2008-08-04 17:43:49 -06:00
|
|
|
|
|
|
|
enum
|
2008-08-05 15:21:42 -06:00
|
|
|
{
|
2008-08-04 17:43:49 -06:00
|
|
|
FUTEX_WAIT = 0,
|
|
|
|
FUTEX_WAKE = 1,
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
EINTR = 4,
|
|
|
|
EAGAIN = 11,
|
|
|
|
};
|
|
|
|
|
2009-03-24 16:04:18 -06:00
|
|
|
// TODO(rsc): I tried using 1<<40 here but futex woke up (-ETIMEDOUT).
|
2008-08-04 17:43:49 -06:00
|
|
|
// I wonder if the timespec that gets to the kernel
|
2009-03-24 16:04:18 -06:00
|
|
|
// actually has two 32-bit numbers in it, so that
|
2008-08-05 15:18:47 -06:00
|
|
|
// a 64-bit 1<<40 ends up being 0 seconds,
|
2008-08-04 17:43:49 -06:00
|
|
|
// 1<<8 nanoseconds.
|
2009-03-24 16:04:18 -06:00
|
|
|
static Timespec longtime =
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
|
|
|
1<<30, // 34 years
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// Atomically,
|
|
|
|
// if(*addr == val) sleep
|
|
|
|
// Might be woken up spuriously; that's allowed.
|
2008-08-04 17:43:49 -06:00
|
|
|
static void
|
2008-08-05 15:18:47 -06:00
|
|
|
futexsleep(uint32 *addr, uint32 val)
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
2010-02-22 21:45:36 -07:00
|
|
|
// Some Linux kernels have a bug where futex of
|
|
|
|
// FUTEX_WAIT returns an internal error code
|
|
|
|
// as an errno. Libpthread ignores the return value
|
|
|
|
// here, and so can we: as it says a few lines up,
|
|
|
|
// spurious wakeups are allowed.
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·futex(addr, FUTEX_WAIT, val, &longtime, nil, 0);
|
2008-08-05 15:18:47 -06:00
|
|
|
}
|
2008-08-04 17:43:49 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// If any procs are sleeping on addr, wake up at least one.
|
|
|
|
static void
|
|
|
|
futexwakeup(uint32 *addr)
|
|
|
|
{
|
|
|
|
int64 ret;
|
2008-08-05 15:21:42 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
ret = runtime·futex(addr, FUTEX_WAKE, 1, nil, nil, 0);
|
2008-08-04 17:43:49 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
if(ret >= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// I don't know that futex wakeup can return
|
2008-08-05 15:21:42 -06:00
|
|
|
// EAGAIN or EINTR, but if it does, it would be
|
2008-08-05 15:18:47 -06:00
|
|
|
// safe to loop and call futex again.
|
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·prints("futexwakeup addr=");
|
|
|
|
runtime·printpointer(addr);
|
|
|
|
runtime·prints(" returned ");
|
|
|
|
runtime·printint(ret);
|
|
|
|
runtime·prints("\n");
|
2008-08-05 15:18:47 -06:00
|
|
|
*(int32*)0x1006 = 0x1006;
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
|
|
|
|
// Lock and unlock.
|
|
|
|
//
|
|
|
|
// The lock state is a single 32-bit word that holds
|
|
|
|
// a 31-bit count of threads waiting for the lock
|
|
|
|
// and a single bit (the low bit) saying whether the lock is held.
|
|
|
|
// The uncontended case runs entirely in user space.
|
|
|
|
// When contention is detected, we defer to the kernel (futex).
|
|
|
|
//
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
// A reminder: compare-and-swap runtime·cas(addr, old, new) does
|
2008-08-05 15:18:47 -06:00
|
|
|
// if(*addr == old) { *addr = new; return 1; }
|
2009-10-03 11:37:12 -06:00
|
|
|
// else return 0;
|
2008-08-05 15:18:47 -06:00
|
|
|
// but atomically.
|
2008-08-04 17:43:49 -06:00
|
|
|
|
2009-01-27 15:01:20 -07:00
|
|
|
static void
|
|
|
|
futexlock(Lock *l)
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
|
|
|
uint32 v;
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
again:
|
|
|
|
v = l->key;
|
|
|
|
if((v&1) == 0){
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(runtime·cas(&l->key, v, v|1)){
|
2008-08-05 15:18:47 -06:00
|
|
|
// Lock wasn't held; we grabbed it.
|
2008-08-04 17:43:49 -06:00
|
|
|
return;
|
2008-08-05 15:18:47 -06:00
|
|
|
}
|
|
|
|
goto again;
|
|
|
|
}
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// Lock was held; try to add ourselves to the waiter count.
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(!runtime·cas(&l->key, v, v+2))
|
2008-08-05 15:18:47 -06:00
|
|
|
goto again;
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// We're accounted for, now sleep in the kernel.
|
|
|
|
//
|
|
|
|
// We avoid the obvious lock/unlock race because
|
|
|
|
// the kernel won't put us to sleep if l->key has
|
|
|
|
// changed underfoot and is no longer v+2.
|
|
|
|
//
|
|
|
|
// We only really care that (v&1) == 1 (the lock is held),
|
|
|
|
// and in fact there is a futex variant that could
|
|
|
|
// accomodate that check, but let's not get carried away.)
|
|
|
|
futexsleep(&l->key, v+2);
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// We're awake: remove ourselves from the count.
|
|
|
|
for(;;){
|
|
|
|
v = l->key;
|
|
|
|
if(v < 2)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("bad lock key");
|
|
|
|
if(runtime·cas(&l->key, v, v-2))
|
2008-08-05 15:18:47 -06:00
|
|
|
break;
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// Try for the lock again.
|
|
|
|
goto again;
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
|
|
|
|
2009-01-27 15:01:20 -07:00
|
|
|
static void
|
|
|
|
futexunlock(Lock *l)
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
|
|
|
uint32 v;
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// Atomically get value and clear lock bit.
|
|
|
|
again:
|
|
|
|
v = l->key;
|
|
|
|
if((v&1) == 0)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("unlock of unlocked lock");
|
|
|
|
if(!runtime·cas(&l->key, v, v&~1))
|
2008-08-05 15:18:47 -06:00
|
|
|
goto again;
|
|
|
|
|
|
|
|
// If there were waiters, wake one.
|
|
|
|
if(v & ~1)
|
|
|
|
futexwakeup(&l->key);
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
|
|
|
|
2009-01-27 15:01:20 -07:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·lock(Lock *l)
|
2009-01-27 15:01:20 -07:00
|
|
|
{
|
|
|
|
if(m->locks < 0)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("lock count");
|
2009-01-27 15:01:20 -07:00
|
|
|
m->locks++;
|
|
|
|
futexlock(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·unlock(Lock *l)
|
2009-01-27 15:01:20 -07:00
|
|
|
{
|
|
|
|
m->locks--;
|
|
|
|
if(m->locks < 0)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("lock count");
|
2009-01-27 15:01:20 -07:00
|
|
|
futexunlock(l);
|
|
|
|
}
|
|
|
|
|
2010-02-08 22:41:54 -07:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·destroylock(Lock*)
|
2010-02-08 22:41:54 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
|
|
|
|
// One-time notifications.
|
|
|
|
//
|
|
|
|
// Since the lock/unlock implementation already
|
|
|
|
// takes care of sleeping in the kernel, we just reuse it.
|
|
|
|
// (But it's a weird use, so it gets its own interface.)
|
|
|
|
//
|
|
|
|
// We use a lock to represent the event:
|
|
|
|
// unlocked == event has happened.
|
|
|
|
// Thus the lock starts out locked, and to wait for the
|
|
|
|
// event you try to lock the lock. To signal the event,
|
|
|
|
// you unlock the lock.
|
2008-08-04 17:43:49 -06:00
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·noteclear(Note *n)
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
2008-08-05 15:18:47 -06:00
|
|
|
n->lock.key = 0; // memset(n, 0, sizeof *n)
|
2009-01-27 15:01:20 -07:00
|
|
|
futexlock(&n->lock);
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·notewakeup(Note *n)
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
2009-01-27 15:01:20 -07:00
|
|
|
futexunlock(&n->lock);
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·notesleep(Note *n)
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
2009-01-27 15:01:20 -07:00
|
|
|
futexlock(&n->lock);
|
|
|
|
futexunlock(&n->lock); // Let other sleepers find out too.
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
|
|
|
|
// Clone, the Linux rfork.
|
2008-08-04 17:43:49 -06:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CLONE_VM = 0x100,
|
|
|
|
CLONE_FS = 0x200,
|
|
|
|
CLONE_FILES = 0x400,
|
|
|
|
CLONE_SIGHAND = 0x800,
|
|
|
|
CLONE_PTRACE = 0x2000,
|
|
|
|
CLONE_VFORK = 0x4000,
|
|
|
|
CLONE_PARENT = 0x8000,
|
|
|
|
CLONE_THREAD = 0x10000,
|
|
|
|
CLONE_NEWNS = 0x20000,
|
|
|
|
CLONE_SYSVSEM = 0x40000,
|
|
|
|
CLONE_SETTLS = 0x80000,
|
|
|
|
CLONE_PARENT_SETTID = 0x100000,
|
|
|
|
CLONE_CHILD_CLEARTID = 0x200000,
|
|
|
|
CLONE_UNTRACED = 0x800000,
|
|
|
|
CLONE_CHILD_SETTID = 0x1000000,
|
|
|
|
CLONE_STOPPED = 0x2000000,
|
|
|
|
CLONE_NEWUTS = 0x4000000,
|
|
|
|
CLONE_NEWIPC = 0x8000000,
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
2009-06-17 16:15:55 -06:00
|
|
|
int32 ret;
|
2008-08-04 17:43:49 -06:00
|
|
|
int32 flags;
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2009-04-29 19:54:44 -06:00
|
|
|
/*
|
|
|
|
* note: strace gets confused if we use CLONE_PTRACE here.
|
|
|
|
*/
|
2011-01-20 11:36:00 -07:00
|
|
|
flags = CLONE_VM /* share memory */
|
2008-08-04 17:43:49 -06:00
|
|
|
| CLONE_FS /* share cwd, etc */
|
|
|
|
| CLONE_FILES /* share fd table */
|
|
|
|
| CLONE_SIGHAND /* share sig handler table */
|
|
|
|
| CLONE_THREAD /* revisit - okay for now */
|
|
|
|
;
|
|
|
|
|
2009-06-17 16:15:55 -06:00
|
|
|
m->tls[0] = m->id; // so 386 asm can find it
|
2008-08-04 17:43:49 -06:00
|
|
|
if(0){
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p clone=%p id=%d/%d ostk=%p\n",
|
|
|
|
stk, m, g, fn, runtime·clone, m->id, m->tls[0], &m);
|
2008-08-04 17:43:49 -06:00
|
|
|
}
|
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
ret = runtime·clone(flags, stk, m, g, fn);
|
2009-06-17 16:15:55 -06:00
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
if(ret < 0)
|
|
|
|
*(int32*)123 = 123;
|
|
|
|
}
|
|
|
|
|
2008-09-09 12:50:14 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·osinit(void)
|
2008-09-09 12:50:14 -06:00
|
|
|
{
|
|
|
|
}
|
2008-09-18 16:56:46 -06:00
|
|
|
|
2011-01-11 17:48:15 -07:00
|
|
|
void
|
|
|
|
runtime·goenvs(void)
|
|
|
|
{
|
|
|
|
runtime·goenvs_unix();
|
|
|
|
}
|
|
|
|
|
2008-09-18 16:56:46 -06:00
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·minit(void)
|
2008-09-18 16:56:46 -06:00
|
|
|
{
|
|
|
|
// Initialize signal handling.
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
m->gsignal = runtime·malg(32*1024); // OS X wants >=8K, Linux >=2K
|
|
|
|
runtime·signalstack(m->gsignal->stackguard, 32*1024);
|
2008-09-18 16:56:46 -06:00
|
|
|
}
|
2010-04-08 19:15:30 -06:00
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·sigpanic(void)
|
2010-04-08 19:15:30 -06:00
|
|
|
{
|
|
|
|
switch(g->sig) {
|
|
|
|
case SIGBUS:
|
|
|
|
if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("invalid memory address or nil pointer dereference");
|
|
|
|
runtime·printf("unexpected fault address %p\n", g->sigcode1);
|
|
|
|
runtime·throw("fault");
|
2010-04-08 19:15:30 -06:00
|
|
|
case SIGSEGV:
|
2010-09-28 18:50:00 -06:00
|
|
|
if((g->sigcode0 == 0 || g->sigcode0 == SEGV_MAPERR || g->sigcode0 == SEGV_ACCERR) && g->sigcode1 < 0x1000)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("invalid memory address or nil pointer dereference");
|
|
|
|
runtime·printf("unexpected fault address %p\n", g->sigcode1);
|
|
|
|
runtime·throw("fault");
|
2010-04-08 19:15:30 -06:00
|
|
|
case SIGFPE:
|
|
|
|
switch(g->sigcode0) {
|
|
|
|
case FPE_INTDIV:
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("integer divide by zero");
|
2010-04-08 19:15:30 -06:00
|
|
|
case FPE_INTOVF:
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("integer overflow");
|
2010-04-08 19:15:30 -06:00
|
|
|
}
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("floating point error");
|
2010-04-08 19:15:30 -06:00
|
|
|
}
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring(runtime·sigtab[g->sig].name);
|
2010-04-08 19:15:30 -06:00
|
|
|
}
|