This source file includes following definitions.
- runtime·mpreinit
- runtime·minit
- runtime·unminit
- runtime·osinit
- runtime·crash
- runtime·get_random_data
- runtime·goenvs
- runtime·initsig
- runtime·usleep
- runtime·newosproc
- runtime·semacreate
- runtime·semasleep
- runtime·semawakeup
- os·sigpipe
- runtime·memlimit
- runtime·badsignal2
- runtime·madvise
- runtime·munmap
- runtime·resetcpuprofiler
- runtime·sigdisable
- runtime·sigenable
- runtime·closeonexec
- runtime·sigpanic
#include "runtime.h"
#include "defs_GOOS_GOARCH.h"
#include "os_GOOS.h"
#include "arch_GOARCH.h"
#include "../../cmd/ld/textflag.h"
#include "stack.h"
int8 *goos = "nacl";
extern SigTab runtime·sigtab[];
void runtime·sigtramp(void);
void
runtime·mpreinit(M *mp)
{
mp->gsignal = runtime·malg(32*1024);
}
void
runtime·minit(void)
{
int32 ret;
ret = runtime·nacl_exception_stack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
if(ret < 0)
runtime·printf("runtime: nacl_exception_stack: error %d\n", -ret);
ret = runtime·nacl_exception_handler(runtime·sigtramp, nil);
if(ret < 0)
runtime·printf("runtime: nacl_exception_handler: error %d\n", -ret);
}
void
runtime·unminit(void)
{
}
int8 runtime·sigtrampf[] = "runtime: signal at PC=%X AX=%X CX=%X DX=%X BX=%X DI=%X R15=%X *SP=%X\n";
int8 runtime·sigtrampp[] = "runtime: sigtramp";
extern byte runtime·tls0[];
void
runtime·osinit(void)
{
runtime·ncpu = 1;
m->procid = 2;
}
void
runtime·crash(void)
{
*(int32*)0 = 0;
}
void
runtime·get_random_data(byte **rnd, int32 *rnd_len)
{
*rnd = nil;
*rnd_len = 0;
}
void
runtime·goenvs(void)
{
runtime·goenvs_unix();
}
void
runtime·initsig(void)
{
}
#pragma textflag NOSPLIT
void
runtime·usleep(uint32 us)
{
Timespec ts;
ts.tv_sec = us/1000000;
ts.tv_nsec = (us%1000000)*1000;
runtime·nacl_nanosleep(&ts, nil);
}
void runtime·mstart_nacl(void);
void
runtime·newosproc(M *mp, void *stk)
{
int32 ret;
void **tls;
tls = (void**)mp->tls;
tls[0] = mp->g0;
tls[1] = mp;
ret = runtime·nacl_thread_create(runtime·mstart_nacl, stk, tls+2, 0);
if(ret < 0) {
runtime·printf("nacl_thread_create: error %d\n", -ret);
runtime·throw("newosproc");
}
}
uintptr
runtime·semacreate(void)
{
int32 mu, cond;
mu = runtime·nacl_mutex_create(0);
if(mu < 0) {
runtime·printf("nacl_mutex_create: error %d\n", -mu);
runtime·throw("semacreate");
}
cond = runtime·nacl_cond_create(0);
if(cond < 0) {
runtime·printf("nacl_cond_create: error %d\n", -cond);
runtime·throw("semacreate");
}
m->waitsemalock = mu;
return cond;
}
#pragma textflag NOSPLIT
int32
runtime·semasleep(int64 ns)
{
int32 ret;
ret = runtime·nacl_mutex_lock(m->waitsemalock);
if(ret < 0) {
runtime·throw("semasleep");
}
if(m->waitsemacount > 0) {
m->waitsemacount = 0;
runtime·nacl_mutex_unlock(m->waitsemalock);
return 0;
}
while(m->waitsemacount == 0) {
if(ns < 0) {
ret = runtime·nacl_cond_wait(m->waitsema, m->waitsemalock);
if(ret < 0) {
runtime·throw("semasleep");
}
} else {
Timespec ts;
ns += runtime·nanotime();
ts.tv_sec = runtime·timediv(ns, 1000000000, (int32*)&ts.tv_nsec);
ret = runtime·nacl_cond_timed_wait_abs(m->waitsema, m->waitsemalock, &ts);
if(ret == -ETIMEDOUT) {
runtime·nacl_mutex_unlock(m->waitsemalock);
return -1;
}
if(ret < 0) {
runtime·throw("semasleep");
}
}
}
m->waitsemacount = 0;
runtime·nacl_mutex_unlock(m->waitsemalock);
return 0;
}
void
runtime·semawakeup(M *mp)
{
int32 ret;
ret = runtime·nacl_mutex_lock(mp->waitsemalock);
if(ret < 0) {
runtime·throw("semawakeup");
}
if(mp->waitsemacount != 0) {
runtime·throw("semawakeup");
}
mp->waitsemacount = 1;
runtime·nacl_cond_signal(mp->waitsema);
runtime·nacl_mutex_unlock(mp->waitsemalock);
}
void
os·sigpipe(void)
{
runtime·throw("too many writes on closed pipe");
}
uintptr
runtime·memlimit(void)
{
runtime·printf("memlimit\n");
return 0;
}
#pragma dataflag NOPTR
static int8 badsignal[] = "runtime: signal received on thread not created by Go.\n";
#pragma textflag NOSPLIT
void
runtime·badsignal2(void)
{
runtime·write(2, badsignal, sizeof badsignal - 1);
runtime·exit(2);
}
void runtime·madvise(byte*, uintptr, int32) { }
void runtime·munmap(byte*, uintptr) {}
void
runtime·resetcpuprofiler(int32 hz)
{
USED(hz);
}
void
runtime·sigdisable(uint32)
{
}
void
runtime·sigenable(uint32)
{
}
void
runtime·closeonexec(int32)
{
}
void
runtime·sigpanic(void)
{
if(!runtime·canpanic(g))
runtime·throw("unexpected signal during runtime execution");
g->sig = SIGSEGV;
if(g->sigpc == 0)
runtime·panicstring("call of nil func value");
runtime·panicstring("invalid memory address or nil pointer dereference");
}
uint32 runtime·writelock;