mirror of
https://github.com/golang/go
synced 2024-11-12 08:10:21 -07:00
runtime: correct mmap return value checking on netbsd/openbsd
The current SysAlloc implementation suffers from a signed vs unsigned comparision bug. Since the error code from mmap is negated, the unsigned comparision of v < 4096 is always false on error. Fix this by switching to the darwin/freebsd/linux mmap model and leave the mmap return value unmodified. R=golang-dev, r CC=golang-dev https://golang.org/cl/7870044
This commit is contained in:
parent
b7b4783622
commit
7f50c23e2d
@ -50,10 +50,9 @@ runtime·SysReserve(void *v, uintptr n)
|
|||||||
return v;
|
return v;
|
||||||
|
|
||||||
p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||||
if (p == ((void *)-ENOMEM))
|
if(p == (void*)ENOMEM)
|
||||||
return nil;
|
return nil;
|
||||||
else
|
return p;
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -66,7 +65,7 @@ runtime·SysMap(void *v, uintptr n)
|
|||||||
// On 64-bit, we don't actually have v reserved, so tread carefully.
|
// On 64-bit, we don't actually have v reserved, so tread carefully.
|
||||||
if(sizeof(void*) == 8) {
|
if(sizeof(void*) == 8) {
|
||||||
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||||
if(p == (void*)-ENOMEM)
|
if(p == (void*)ENOMEM)
|
||||||
runtime·throw("runtime: out of memory");
|
runtime·throw("runtime: out of memory");
|
||||||
if(p != v) {
|
if(p != v) {
|
||||||
runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p);
|
runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p);
|
||||||
@ -76,7 +75,7 @@ runtime·SysMap(void *v, uintptr n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
|
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
|
||||||
if(p == (void*)-ENOMEM)
|
if(p == (void*)ENOMEM)
|
||||||
runtime·throw("runtime: out of memory");
|
runtime·throw("runtime: out of memory");
|
||||||
if(p != v)
|
if(p != v)
|
||||||
runtime·throw("runtime: cannot map pages in arena address space");
|
runtime·throw("runtime: cannot map pages in arena address space");
|
||||||
|
@ -50,10 +50,9 @@ runtime·SysReserve(void *v, uintptr n)
|
|||||||
return v;
|
return v;
|
||||||
|
|
||||||
p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||||
if (p == ((void *)-ENOMEM))
|
if(p == (void*)ENOMEM)
|
||||||
return nil;
|
return nil;
|
||||||
else
|
return p;
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -66,7 +65,7 @@ runtime·SysMap(void *v, uintptr n)
|
|||||||
// On 64-bit, we don't actually have v reserved, so tread carefully.
|
// On 64-bit, we don't actually have v reserved, so tread carefully.
|
||||||
if(sizeof(void*) == 8) {
|
if(sizeof(void*) == 8) {
|
||||||
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
|
||||||
if(p == (void*)-ENOMEM)
|
if(p == (void*)ENOMEM)
|
||||||
runtime·throw("runtime: out of memory");
|
runtime·throw("runtime: out of memory");
|
||||||
if(p != v) {
|
if(p != v) {
|
||||||
runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p);
|
runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p);
|
||||||
@ -76,7 +75,7 @@ runtime·SysMap(void *v, uintptr n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
|
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
|
||||||
if(p == (void*)-ENOMEM)
|
if(p == (void*)ENOMEM)
|
||||||
runtime·throw("runtime: out of memory");
|
runtime·throw("runtime: out of memory");
|
||||||
if(p != v)
|
if(p != v)
|
||||||
runtime·throw("runtime: cannot map pages in arena address space");
|
runtime·throw("runtime: cannot map pages in arena address space");
|
||||||
|
@ -88,8 +88,6 @@ TEXT runtime·mmap(SB),7,$36
|
|||||||
STOSL
|
STOSL
|
||||||
MOVL $197, AX // sys_mmap
|
MOVL $197, AX // sys_mmap
|
||||||
INT $0x80
|
INT $0x80
|
||||||
JCC 2(PC)
|
|
||||||
NEGL AX
|
|
||||||
RET
|
RET
|
||||||
|
|
||||||
TEXT runtime·munmap(SB),7,$-4
|
TEXT runtime·munmap(SB),7,$-4
|
||||||
|
@ -253,8 +253,6 @@ TEXT runtime·mmap(SB),7,$0
|
|||||||
MOVQ $0, R9 // arg 6 - pad
|
MOVQ $0, R9 // arg 6 - pad
|
||||||
MOVL $197, AX // sys_mmap
|
MOVL $197, AX // sys_mmap
|
||||||
SYSCALL
|
SYSCALL
|
||||||
JCC 2(PC)
|
|
||||||
NEGQ AX
|
|
||||||
ADDQ $16, SP
|
ADDQ $16, SP
|
||||||
RET
|
RET
|
||||||
|
|
||||||
|
@ -89,8 +89,6 @@ TEXT runtime·mmap(SB),7,$36
|
|||||||
STOSL
|
STOSL
|
||||||
MOVL $197, AX // sys_mmap
|
MOVL $197, AX // sys_mmap
|
||||||
INT $0x80
|
INT $0x80
|
||||||
JCC 2(PC)
|
|
||||||
NEGL AX
|
|
||||||
RET
|
RET
|
||||||
|
|
||||||
TEXT runtime·munmap(SB),7,$-4
|
TEXT runtime·munmap(SB),7,$-4
|
||||||
|
@ -242,8 +242,6 @@ TEXT runtime·mmap(SB),7,$0
|
|||||||
MOVQ $0, R9 // arg 6 - pad
|
MOVQ $0, R9 // arg 6 - pad
|
||||||
MOVL $197, AX
|
MOVL $197, AX
|
||||||
SYSCALL
|
SYSCALL
|
||||||
JCC 2(PC)
|
|
||||||
NEGQ AX
|
|
||||||
ADDQ $16, SP
|
ADDQ $16, SP
|
||||||
RET
|
RET
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user