2008-06-05 20:38:39 -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"
|
|
|
|
|
|
|
|
int32 debug = 0;
|
|
|
|
|
2008-06-20 11:55:53 -06:00
|
|
|
/*BUG: move traceback code to architecture-dependent runtime */
|
2008-06-16 18:04:30 -06:00
|
|
|
void
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·panicl(int32 lno)
|
2008-06-16 18:04:30 -06:00
|
|
|
{
|
2008-06-19 00:17:39 -06:00
|
|
|
uint8 *sp;
|
|
|
|
|
2008-06-16 18:04:30 -06:00
|
|
|
prints("\npanic on line ");
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·printint(lno);
|
2008-06-16 18:04:30 -06:00
|
|
|
prints(" ");
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·printpc(&lno);
|
2008-06-16 18:04:30 -06:00
|
|
|
prints("\n");
|
2008-06-19 00:17:39 -06:00
|
|
|
sp = (uint8*)&lno;
|
2008-06-30 15:39:47 -06:00
|
|
|
traceback(sys·getcallerpc(&lno), sp, getu());
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·breakpoint();
|
|
|
|
sys·exit(2);
|
2008-06-16 18:04:30 -06:00
|
|
|
}
|
|
|
|
|
2008-06-05 20:38:39 -06:00
|
|
|
static uint8* hunk;
|
|
|
|
static uint32 nhunk;
|
|
|
|
static uint64 nmmap;
|
|
|
|
static uint64 nmal;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NHUNK = 20<<20,
|
|
|
|
|
|
|
|
PROT_NONE = 0x00,
|
|
|
|
PROT_READ = 0x01,
|
|
|
|
PROT_WRITE = 0x02,
|
|
|
|
PROT_EXEC = 0x04,
|
|
|
|
|
|
|
|
MAP_FILE = 0x0000,
|
|
|
|
MAP_SHARED = 0x0001,
|
|
|
|
MAP_PRIVATE = 0x0002,
|
|
|
|
MAP_FIXED = 0x0010,
|
|
|
|
MAP_ANON = 0x1000,
|
|
|
|
};
|
|
|
|
|
2008-06-16 23:34:50 -06:00
|
|
|
void
|
2008-06-05 20:38:39 -06:00
|
|
|
throw(int8 *s)
|
|
|
|
{
|
|
|
|
prints("throw: ");
|
|
|
|
prints(s);
|
|
|
|
prints("\n");
|
2008-06-24 18:16:06 -06:00
|
|
|
*(int32*)0 = 0;
|
|
|
|
sys·exit(1);
|
2008-06-05 20:38:39 -06:00
|
|
|
}
|
|
|
|
|
2008-06-15 21:24:30 -06:00
|
|
|
void
|
2008-06-05 20:38:39 -06:00
|
|
|
mcpy(byte *t, byte *f, uint32 n)
|
|
|
|
{
|
|
|
|
while(n > 0) {
|
|
|
|
*t = *f;
|
|
|
|
t++;
|
|
|
|
f++;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static byte*
|
|
|
|
brk(uint32 n)
|
|
|
|
{
|
|
|
|
byte* v;
|
|
|
|
|
2008-06-29 21:40:08 -06:00
|
|
|
v = sys·mmap(nil, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, 0, 0);
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·memclr(v, n);
|
2008-06-05 20:38:39 -06:00
|
|
|
nmmap += n;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-06-15 21:24:30 -06:00
|
|
|
void*
|
2008-06-05 20:38:39 -06:00
|
|
|
mal(uint32 n)
|
|
|
|
{
|
|
|
|
byte* v;
|
|
|
|
|
2008-06-29 21:40:08 -06:00
|
|
|
// round to keep everything 64-bit aligned
|
|
|
|
n = (n+7) & ~7;
|
2008-06-05 20:38:39 -06:00
|
|
|
nmal += n;
|
|
|
|
|
|
|
|
// do we have enough in contiguous hunk
|
|
|
|
if(n > nhunk) {
|
|
|
|
|
|
|
|
// if it is big allocate it separately
|
|
|
|
if(n > NHUNK)
|
|
|
|
return brk(n);
|
|
|
|
|
|
|
|
// allocate a new contiguous hunk
|
|
|
|
hunk = brk(NHUNK);
|
|
|
|
nhunk = NHUNK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate from the contiguous hunk
|
|
|
|
v = hunk;
|
|
|
|
hunk += n;
|
|
|
|
nhunk -= n;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·mal(uint32 n, uint8 *ret)
|
2008-06-05 20:38:39 -06:00
|
|
|
{
|
|
|
|
ret = mal(n);
|
|
|
|
FLUSH(&ret);
|
|
|
|
}
|