2010-01-13 18:50:02 -07:00
|
|
|
// 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"
|
|
|
|
|
2010-09-07 07:57:22 -06:00
|
|
|
enum {
|
|
|
|
MEM_COMMIT = 0x1000,
|
|
|
|
MEM_RESERVE = 0x2000,
|
|
|
|
MEM_RELEASE = 0x8000,
|
|
|
|
|
|
|
|
PAGE_EXECUTE_READWRITE = 0x40,
|
|
|
|
};
|
|
|
|
|
2010-11-23 17:47:35 -07:00
|
|
|
static void
|
|
|
|
abort(int8 *name)
|
|
|
|
{
|
|
|
|
uintptr errno;
|
|
|
|
|
|
|
|
errno = (uintptr)runtime·stdcall(runtime·GetLastError, 0);
|
|
|
|
runtime·printf("%s failed with errno=%d\n", name, errno);
|
|
|
|
runtime·throw(name);
|
|
|
|
}
|
|
|
|
|
2010-12-07 13:28:33 -07:00
|
|
|
#pragma dynimport runtime·VirtualAlloc VirtualAlloc "kernel32.dll"
|
|
|
|
#pragma dynimport runtime·VirtualFree VirtualFree "kernel32.dll"
|
2010-12-12 22:41:02 -07:00
|
|
|
extern void *runtime·VirtualAlloc;
|
|
|
|
extern void *runtime·VirtualFree;
|
2010-12-07 13:28:33 -07:00
|
|
|
|
2010-01-13 18:50:02 -07:00
|
|
|
void*
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·SysAlloc(uintptr n)
|
2010-01-13 18:50:02 -07:00
|
|
|
{
|
2011-01-28 13:03:26 -07:00
|
|
|
mstats.sys += n;
|
2011-01-28 21:44:37 -07:00
|
|
|
return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
2010-01-13 18:50:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·SysUnused(void *v, uintptr n)
|
2010-01-13 18:50:02 -07:00
|
|
|
{
|
|
|
|
USED(v);
|
|
|
|
USED(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·SysFree(void *v, uintptr n)
|
2010-01-13 18:50:02 -07:00
|
|
|
{
|
2010-11-23 17:47:35 -07:00
|
|
|
uintptr r;
|
|
|
|
|
2011-01-28 13:03:26 -07:00
|
|
|
mstats.sys -= n;
|
2010-11-23 17:47:35 -07:00
|
|
|
r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, 0, MEM_RELEASE);
|
|
|
|
if(r == 0)
|
|
|
|
abort("VirtualFree");
|
2010-01-13 18:50:02 -07:00
|
|
|
}
|
2010-09-28 18:30:01 -06:00
|
|
|
|
2011-01-28 21:44:37 -07:00
|
|
|
void*
|
2011-01-28 13:03:26 -07:00
|
|
|
runtime·SysReserve(void *v, uintptr n)
|
2010-09-28 18:30:01 -06:00
|
|
|
{
|
2011-01-28 13:03:26 -07:00
|
|
|
return runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_RESERVE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·SysMap(void *v, uintptr n)
|
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
mstats.sys += n;
|
|
|
|
p = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
if(p != v)
|
|
|
|
runtime·throw("runtime: cannot map pages in arena address space");
|
2010-09-28 18:30:01 -06:00
|
|
|
}
|