]> Cypherpunks repositories - gostls13.git/commitdiff
runtime cleanup.
authorRuss Cox <rsc@golang.org>
Thu, 14 Jan 2010 01:50:02 +0000 (17:50 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 14 Jan 2010 01:50:02 +0000 (17:50 -0800)
  * 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

12 files changed:
src/pkg/runtime/Makefile
src/pkg/runtime/darwin/mem.c [new file with mode: 0644]
src/pkg/runtime/freebsd/mem.c [new file with mode: 0644]
src/pkg/runtime/linux/mem.c [new file with mode: 0644]
src/pkg/runtime/malloc.cgo
src/pkg/runtime/malloc.h
src/pkg/runtime/mem.c [deleted file]
src/pkg/runtime/mingw/mem.c [new file with mode: 0644]
src/pkg/runtime/mingw/os.h
src/pkg/runtime/mingw/thread.c
src/pkg/runtime/runtime1.cgo [new file with mode: 0644]
src/pkg/runtime/string.cgo

index 80bb521b31a22864533a536c812ce68beee12832..370a97309f6c568da520922e5a78180726f51762 100644 (file)
@@ -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
diff --git a/src/pkg/runtime/darwin/mem.c b/src/pkg/runtime/darwin/mem.c
new file mode 100644 (file)
index 0000000..52e351a
--- /dev/null
@@ -0,0 +1,28 @@
+#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
+}
+
diff --git a/src/pkg/runtime/freebsd/mem.c b/src/pkg/runtime/freebsd/mem.c
new file mode 100644 (file)
index 0000000..52e351a
--- /dev/null
@@ -0,0 +1,28 @@
+#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
+}
+
diff --git a/src/pkg/runtime/linux/mem.c b/src/pkg/runtime/linux/mem.c
new file mode 100644 (file)
index 0000000..7f837bd
--- /dev/null
@@ -0,0 +1,40 @@
+#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
+}
+
index a85c39d83d3f8fe4895ec906b9f8e7ab7681fbe7..6acbac2eb090cc8ac0b7d658b4a959f1cd3c2106 100644 (file)
@@ -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*
index b3fa8e0dfb2036d8a7bacc1410117352b9bc77e3..e07faf39f1859a99e3e4faeac5d6762f7580d13e 100644 (file)
@@ -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
diff --git a/src/pkg/runtime/mem.c b/src/pkg/runtime/mem.c
deleted file mode 100644 (file)
index f2796b7..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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"
-#include "defs.h"
-
-// Stubs for memory management.
-// In a separate file so they can be overridden during testing of gc.
-
-enum
-{
-       NHUNK           = 20<<20,
-};
-
-void
-runtimeĀ·mal(uint32 n, uint8 *ret)
-{
-       ret = mal(n);
-       FLUSH(&ret);
-}
diff --git a/src/pkg/runtime/mingw/mem.c b/src/pkg/runtime/mingw/mem.c
new file mode 100644 (file)
index 0000000..256ad9a
--- /dev/null
@@ -0,0 +1,29 @@
+// 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"
+
+void*
+SysAlloc(uintptr n)
+{
+       return stdcall(VirtualAlloc, nil, n, 0x3000, 0x40);
+}
+
+void
+SysUnused(void *v, uintptr n)
+{
+       USED(v);
+       USED(n);
+}
+
+void
+SysFree(void *v, uintptr n)
+{
+       USED(v);
+       USED(n);
+}
+
index 8470cc0e587bdc584da5209940431c8a21b92e45..3864dbf8f12058f95a900f9247e8063f3fa78028 100644 (file)
@@ -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);
 
index 979fd422473ec22d44aa0ba114473c2328528739..89f33f8a4a1b858640be5e6a1708cd0cc3b23c9e 100644 (file)
@@ -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)
 {
diff --git a/src/pkg/runtime/runtime1.cgo b/src/pkg/runtime/runtime1.cgo
new file mode 100644 (file)
index 0000000..7e5f323
--- /dev/null
@@ -0,0 +1,11 @@
+// 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);
+}
+
index 03b05618d81a52de29c3bc1b4f3c2cce045d8fbc..c615768f3c642b5d3587e7f3bf1575db7fb1f626 100644 (file)
@@ -31,7 +31,7 @@ findnullw(uint16 *s)
        return l;
 }
 
-int32 maxstring;
+int32 maxstring = 256;
 
 String
 gostringsize(int32 l)