mirror of
https://github.com/golang/go
synced 2024-11-19 05:54:44 -07:00
runtime: add mmap of null page just in case
R=r, iant, robert.swiecki, rsc1 CC=golang-dev https://golang.org/cl/1904044
This commit is contained in:
parent
9499856488
commit
649aab835f
@ -10,6 +10,7 @@ enum {
|
||||
PROT_EXEC = 0x4,
|
||||
MAP_ANON = 0x1000,
|
||||
MAP_PRIVATE = 0x2,
|
||||
MAP_FIXED = 0x10,
|
||||
MACH_MSG_TYPE_MOVE_RECEIVE = 0x10,
|
||||
MACH_MSG_TYPE_MOVE_SEND = 0x11,
|
||||
MACH_MSG_TYPE_MOVE_SEND_ONCE = 0x12,
|
||||
|
@ -38,8 +38,6 @@ TEXT write(SB),7,$0
|
||||
TEXT ·mmap(SB),7,$0
|
||||
MOVL $197, AX
|
||||
INT $0x80
|
||||
JAE 2(PC)
|
||||
CALL notok(SB)
|
||||
RET
|
||||
|
||||
TEXT ·munmap(SB),7,$0
|
||||
|
@ -10,6 +10,7 @@ enum {
|
||||
PROT_EXEC = 0x4,
|
||||
MAP_ANON = 0x1000,
|
||||
MAP_PRIVATE = 0x2,
|
||||
MAP_FIXED = 0x10,
|
||||
MACH_MSG_TYPE_MOVE_RECEIVE = 0x10,
|
||||
MACH_MSG_TYPE_MOVE_SEND = 0x11,
|
||||
MACH_MSG_TYPE_MOVE_SEND_ONCE = 0x12,
|
||||
|
@ -103,8 +103,6 @@ TEXT ·mmap(SB),7,$0
|
||||
MOVL 36(SP), R9 // arg 6 offset
|
||||
MOVL $(0x2000000+197), AX // syscall entry
|
||||
SYSCALL
|
||||
JCC 2(PC)
|
||||
CALL notok(SB)
|
||||
RET
|
||||
|
||||
TEXT ·munmap(SB),7,$0
|
||||
|
@ -26,6 +26,7 @@ enum {
|
||||
|
||||
$MAP_ANON = MAP_ANON,
|
||||
$MAP_PRIVATE = MAP_PRIVATE,
|
||||
$MAP_FIXED = MAP_FIXED,
|
||||
|
||||
$MACH_MSG_TYPE_MOVE_RECEIVE = MACH_MSG_TYPE_MOVE_RECEIVE,
|
||||
$MACH_MSG_TYPE_MOVE_SEND = MACH_MSG_TYPE_MOVE_SEND,
|
||||
|
@ -6,8 +6,15 @@
|
||||
void*
|
||||
SysAlloc(uintptr n)
|
||||
{
|
||||
void *v;
|
||||
|
||||
mstats.sys += n;
|
||||
return runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||
v = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||
if(v < (void*)4096) {
|
||||
printf("mmap: errno=%p\n", v);
|
||||
throw("mmap");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
@ -25,3 +32,15 @@ SysFree(void *v, uintptr n)
|
||||
runtime_munmap(v, n);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SysMemInit(void)
|
||||
{
|
||||
// Code generators assume that references to addresses
|
||||
// on the first page will fault. Map the page explicitly with
|
||||
// no permissions, to head off possible bugs like the system
|
||||
// allocating that page as the virtual address space fills.
|
||||
// Ignore any error, since other systems might be smart
|
||||
// enough to never allow anything there.
|
||||
// runtime_mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ enum {
|
||||
PROT_EXEC = 0x4,
|
||||
MAP_ANON = 0x1000,
|
||||
MAP_PRIVATE = 0x2,
|
||||
MAP_FIXED = 0x10,
|
||||
SA_SIGINFO = 0x40,
|
||||
SA_RESTART = 0x2,
|
||||
SA_ONSTACK = 0x1,
|
||||
|
@ -80,8 +80,6 @@ TEXT ·mmap(SB),7,$32
|
||||
STOSL
|
||||
MOVL $477, AX
|
||||
INT $0x80
|
||||
JAE 2(PC)
|
||||
CALL notok(SB)
|
||||
RET
|
||||
|
||||
TEXT ·munmap(SB),7,$-4
|
||||
|
@ -10,6 +10,7 @@ enum {
|
||||
PROT_EXEC = 0x4,
|
||||
MAP_ANON = 0x1000,
|
||||
MAP_PRIVATE = 0x2,
|
||||
MAP_FIXED = 0x10,
|
||||
SA_SIGINFO = 0x40,
|
||||
SA_RESTART = 0x2,
|
||||
SA_ONSTACK = 0x1,
|
||||
|
@ -112,8 +112,6 @@ TEXT ·mmap(SB),7,$0
|
||||
MOVL 36(SP), R9 // arg 6 offset
|
||||
MOVL $477, AX
|
||||
SYSCALL
|
||||
JCC 2(PC)
|
||||
CALL notok(SB)
|
||||
RET
|
||||
|
||||
TEXT ·munmap(SB),7,$0
|
||||
|
@ -28,6 +28,7 @@ enum {
|
||||
|
||||
$MAP_ANON = MAP_ANON,
|
||||
$MAP_PRIVATE = MAP_PRIVATE,
|
||||
$MAP_FIXED = MAP_FIXED,
|
||||
|
||||
$SA_SIGINFO = SA_SIGINFO,
|
||||
$SA_RESTART = SA_RESTART,
|
||||
|
@ -6,8 +6,15 @@
|
||||
void*
|
||||
SysAlloc(uintptr n)
|
||||
{
|
||||
void *v;
|
||||
|
||||
mstats.sys += n;
|
||||
return runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||
v = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||
if(v < (void*)4096) {
|
||||
printf("mmap: errno=%p\n", p);
|
||||
throw("mmap");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
@ -25,3 +32,15 @@ SysFree(void *v, uintptr n)
|
||||
runtime_munmap(v, n);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SysMemInit(void)
|
||||
{
|
||||
// Code generators assume that references to addresses
|
||||
// on the first page will fault. Map the page explicitly with
|
||||
// no permissions, to head off possible bugs like the system
|
||||
// allocating that page as the virtual address space fills.
|
||||
// Ignore any error, since other systems might be smart
|
||||
// enough to never allow anything there.
|
||||
runtime_mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ enum {
|
||||
PROT_EXEC = 0x4,
|
||||
MAP_ANON = 0x20,
|
||||
MAP_PRIVATE = 0x2,
|
||||
MAP_FIXED = 0x10,
|
||||
SA_RESTART = 0x10000000,
|
||||
SA_ONSTACK = 0x8000000,
|
||||
SA_RESTORER = 0x4000000,
|
||||
|
@ -10,6 +10,7 @@ enum {
|
||||
PROT_EXEC = 0x4,
|
||||
MAP_ANON = 0x20,
|
||||
MAP_PRIVATE = 0x2,
|
||||
MAP_FIXED = 0x10,
|
||||
SA_RESTART = 0x10000000,
|
||||
SA_ONSTACK = 0x8000000,
|
||||
SA_RESTORER = 0x4000000,
|
||||
|
@ -10,6 +10,7 @@ enum {
|
||||
PROT_EXEC = 0x4,
|
||||
MAP_ANON = 0x20,
|
||||
MAP_PRIVATE = 0x2,
|
||||
MAP_FIXED = 0x10,
|
||||
SA_RESTART = 0x10000000,
|
||||
SA_ONSTACK = 0x8000000,
|
||||
SA_RESTORER = 0x4000000,
|
||||
|
@ -27,6 +27,7 @@ enum {
|
||||
|
||||
$MAP_ANON = MAP_ANONYMOUS,
|
||||
$MAP_PRIVATE = MAP_PRIVATE,
|
||||
$MAP_FIXED = MAP_FIXED,
|
||||
|
||||
$SA_RESTART = SA_RESTART,
|
||||
$SA_ONSTACK = SA_ONSTACK,
|
||||
|
@ -47,6 +47,7 @@ enum {
|
||||
|
||||
$MAP_ANON = MAP_ANONYMOUS,
|
||||
$MAP_PRIVATE = MAP_PRIVATE,
|
||||
$MAP_FIXED = MAP_FIXED,
|
||||
|
||||
$SA_RESTART = SA_RESTART,
|
||||
$SA_ONSTACK = SA_ONSTACK,
|
||||
|
@ -31,6 +31,7 @@ enum {
|
||||
|
||||
$MAP_ANON = MAP_ANONYMOUS,
|
||||
$MAP_PRIVATE = MAP_PRIVATE,
|
||||
$MAP_FIXED = MAP_FIXED,
|
||||
|
||||
$SA_RESTART = SA_RESTART,
|
||||
$SA_ONSTACK = SA_ONSTACK,
|
||||
|
@ -14,10 +14,10 @@ SysAlloc(uintptr n)
|
||||
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);
|
||||
}
|
||||
exit(2);
|
||||
printf("mmap: errno=%p\n", p);
|
||||
throw("mmap");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@ -37,3 +37,14 @@ SysFree(void *v, uintptr n)
|
||||
runtime_munmap(v, n);
|
||||
}
|
||||
|
||||
void
|
||||
SysMemInit(void)
|
||||
{
|
||||
// Code generators assume that references to addresses
|
||||
// on the first page will fault. Map the page explicitly with
|
||||
// no permissions, to head off possible bugs like the system
|
||||
// allocating that page as the virtual address space fills.
|
||||
// Ignore any error, since other systems might be smart
|
||||
// enough to never allow anything there.
|
||||
runtime_mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||
}
|
||||
|
@ -245,6 +245,7 @@ allocmcache(void)
|
||||
void
|
||||
mallocinit(void)
|
||||
{
|
||||
SysMemInit();
|
||||
InitSizes();
|
||||
MHeap_Init(&mheap, SysAlloc);
|
||||
m->mcache = allocmcache();
|
||||
|
@ -138,7 +138,7 @@ struct MLink
|
||||
void* SysAlloc(uintptr nbytes);
|
||||
void SysFree(void *v, uintptr nbytes);
|
||||
void SysUnused(void *v, uintptr nbytes);
|
||||
|
||||
void SysMemInit(void);
|
||||
|
||||
// FixAlloc is a simple free-list allocator for fixed size objects.
|
||||
// Malloc uses a FixAlloc wrapped around SysAlloc to manages its
|
||||
|
@ -31,3 +31,7 @@ SysFree(void *v, uintptr n)
|
||||
runtime_munmap(v, n);
|
||||
}
|
||||
|
||||
void
|
||||
SysMemInit(void)
|
||||
{
|
||||
}
|
||||
|
@ -44,3 +44,7 @@ SysUnused(void *v, uintptr n)
|
||||
USED(v, n);
|
||||
}
|
||||
|
||||
void
|
||||
SysMemInit(void)
|
||||
{
|
||||
}
|
||||
|
@ -33,3 +33,8 @@ SysFree(void *v, uintptr n)
|
||||
{
|
||||
stdcall(VirtualFree, 3, v, n, MEM_RELEASE);
|
||||
}
|
||||
|
||||
void
|
||||
SysMemInit(void)
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user