Commit 12518e44 authored by Russ Cox's avatar Russ Cox

runtime cleanup.

  * move memory code into $GOOS-specific directory.
  * allow printing of static strings < 256 bytes.
    (dynamic strings will bump maxstring as they are allocated.)
  * use cgo2c for runtime.mal.

R=r, dho
CC=golang-dev
https://golang.org/cl/186143
parent 3fddcd6e
......@@ -62,6 +62,7 @@ OFILES=\
reflect.$O\
rune.$O\
runtime.$O\
runtime1.$O\
rt0.$O\
sema.$O\
signal.$O\
......@@ -73,6 +74,7 @@ OFILES=\
thread.$O\
traceback.$O\
$(OFILES_$(GOARCH))\
$(OFILES_$(GOOS))\
HFILES=\
cgocall.h\
......@@ -84,6 +86,8 @@ HFILES=\
$(GOOS)/signals.h\
$(GOOS)/$(GOARCH)/defs.h\
GOFILES+=$(GOFILES_$(GOOS))
include ../../Make.pkg
clean: clean-local
......
#include "runtime.h"
#include "defs.h"
#include "os.h"
#include "malloc.h"
void*
SysAlloc(uintptr n)
{
mstats.sys += n;
return runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
}
void
SysUnused(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call madvise MADV_DONTNEED
}
void
SysFree(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call munmap
}
#include "runtime.h"
#include "defs.h"
#include "os.h"
#include "malloc.h"
void*
SysAlloc(uintptr n)
{
mstats.sys += n;
return runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
}
void
SysUnused(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call madvise MADV_DONTNEED
}
void
SysFree(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call munmap
}
#include "runtime.h"
#include "defs.h"
#include "os.h"
#include "malloc.h"
void*
SysAlloc(uintptr n)
{
void *p;
mstats.sys += n;
p = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
if(p < (void*)4096) {
if(p == (void*)EACCES) {
printf("mmap: access denied\n");
printf("If you're running SELinux, enable execmem for this process.\n");
} else {
printf("mmap: errno=%p\n", p);
}
exit(2);
}
return p;
}
void
SysUnused(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call madvise MADV_DONTNEED
}
void
SysFree(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call munmap
}
......@@ -205,41 +205,6 @@ mallocinit(void)
free(malloc(1));
}
void*
SysAlloc(uintptr n)
{
void *p;
mstats.sys += n;
p = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
if(p < (void*)4096) {
if(p == (void*)EACCES) {
printf("mmap: access denied\n");
printf("If you're running SELinux, enable execmem for this process.\n");
} else {
printf("mmap: errno=%p\n", p);
}
exit(2);
}
return p;
}
void
SysUnused(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call madvise MADV_DONTNEED
}
void
SysFree(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call munmap
}
// Runtime stubs.
void*
......
......@@ -303,6 +303,10 @@ void* mallocgc(uintptr size, uint32 flag, int32 dogc);
int32 mlookup(void *v, byte **base, uintptr *size, uint32 **ref);
void gc(int32 force);
void* SysAlloc(uintptr);
void SysUnused(void*, uintptr);
void SysFree(void*, uintptr);
enum
{
RefcountOverhead = 4, // one uint32 per object
......
// Copyright 2009 The Go Authors. All rights reserved.
// Copyright 2010 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"
#include "os.h"
#include "defs.h"
#include "malloc.h"
// Stubs for memory management.
// In a separate file so they can be overridden during testing of gc.
void*
SysAlloc(uintptr n)
{
return stdcall(VirtualAlloc, nil, n, 0x3000, 0x40);
}
enum
void
SysUnused(void *v, uintptr n)
{
NHUNK = 20<<20,
};
USED(v);
USED(n);
}
void
runtime·mal(uint32 n, uint8 *ret)
SysFree(void *v, uintptr n)
{
ret = mal(n);
FLUSH(&ret);
USED(v);
USED(n);
}
......@@ -11,6 +11,8 @@ void *get_proc_addr(void *library, void *name);
void *stdcall(void *fn, ...);
void *stdcall_raw(void *fn, ...);
extern void *VirtualAlloc;
#define goargs mingw_goargs
void mingw_goargs(void);
......
......@@ -15,13 +15,13 @@ void *ExitProcess;
void *GetStdHandle;
void *SetEvent;
void *WriteFile;
void *VirtualAlloc;
static void *CreateEvent;
static void *CreateThread;
static void *GetModuleHandle;
static void *GetProcAddress;
static void *LoadLibraryEx;
static void *VirtualAlloc;
static void *WaitForSingleObject;
static void*
......@@ -148,14 +148,6 @@ write(int32 fd, void *buf, int32 n)
return written;
}
uint8*
runtime_mmap(byte *addr, uint32 len, int32 prot,
int32 flags, int32 fd, uint32 off)
{
USED(prot, flags, fd, off);
return stdcall(VirtualAlloc, addr, len, 0x3000, 0x40);
}
void*
get_symdat_addr(void)
{
......
// Copyright 2010 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.
package runtime
#include "runtime.h"
func mal(n uint32) (ret *uint8) {
ret = mal(n);
}
......@@ -31,7 +31,7 @@ findnullw(uint16 *s)
return l;
}
int32 maxstring;
int32 maxstring = 256;
String
gostringsize(int32 l)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment