1
0
mirror of https://github.com/golang/go synced 2024-10-04 18:31:22 -06:00
go/src/runtime/runtime.c

112 lines
1.6 KiB
C
Raw Normal View History

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;
/*BUG: move traceback code to architecture-dependent runtime */
2008-06-16 18:04:30 -06:00
void
sys·panicl(int32 lno)
2008-06-16 18:04:30 -06:00
{
uint8 *sp;
2008-06-16 18:04:30 -06:00
prints("\npanic on line ");
sys·printint(lno);
2008-06-16 18:04:30 -06:00
prints(" ");
sys·printpc(&lno);
2008-06-16 18:04:30 -06:00
prints("\n");
sp = (uint8*)&lno;
traceback(sys·getcallerpc(&lno), sp, getu());
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");
*(int32*)0 = 0;
sys·exit(1);
2008-06-05 20:38:39 -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);
sys·memclr(v, n);
2008-06-05 20:38:39 -06:00
nmmap += n;
return v;
}
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
sys·mal(uint32 n, uint8 *ret)
2008-06-05 20:38:39 -06:00
{
ret = mal(n);
FLUSH(&ret);
}