]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: correct mmap return value checking on netbsd/openbsd
authorJoel Sing <jsing@google.com>
Mon, 18 Mar 2013 01:18:49 +0000 (12:18 +1100)
committerJoel Sing <jsing@google.com>
Mon, 18 Mar 2013 01:18:49 +0000 (12:18 +1100)
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

src/pkg/runtime/mem_netbsd.c
src/pkg/runtime/mem_openbsd.c
src/pkg/runtime/sys_netbsd_386.s
src/pkg/runtime/sys_netbsd_amd64.s
src/pkg/runtime/sys_openbsd_386.s
src/pkg/runtime/sys_openbsd_amd64.s

index 77ce04c4eea9a768dead416520a738f2701ad958..63a57b94a3b86f49f1d2fbc30c8b49d8d8a95c40 100644 (file)
@@ -50,10 +50,9 @@ runtime·SysReserve(void *v, uintptr n)
                return v;
 
        p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
-       if (p == ((void *)-ENOMEM))
+       if(p == (void*)ENOMEM)
                return nil;
-       else
-               return p;
+       return p;
 }
 
 void
@@ -66,7 +65,7 @@ runtime·SysMap(void *v, uintptr n)
        // On 64-bit, we don't actually have v reserved, so tread carefully.
        if(sizeof(void*) == 8) {
                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");
                if(p != v) {
                        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);
-       if(p == (void*)-ENOMEM)
+       if(p == (void*)ENOMEM)
                runtime·throw("runtime: out of memory");
        if(p != v)
                runtime·throw("runtime: cannot map pages in arena address space");
index 77ce04c4eea9a768dead416520a738f2701ad958..63a57b94a3b86f49f1d2fbc30c8b49d8d8a95c40 100644 (file)
@@ -50,10 +50,9 @@ runtime·SysReserve(void *v, uintptr n)
                return v;
 
        p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
-       if (p == ((void *)-ENOMEM))
+       if(p == (void*)ENOMEM)
                return nil;
-       else
-               return p;
+       return p;
 }
 
 void
@@ -66,7 +65,7 @@ runtime·SysMap(void *v, uintptr n)
        // On 64-bit, we don't actually have v reserved, so tread carefully.
        if(sizeof(void*) == 8) {
                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");
                if(p != v) {
                        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);
-       if(p == (void*)-ENOMEM)
+       if(p == (void*)ENOMEM)
                runtime·throw("runtime: out of memory");
        if(p != v)
                runtime·throw("runtime: cannot map pages in arena address space");
index 61686e7de4ec08944fe1cc539bc364fa2803064e..992eba77dad3137eac0f662e88742b2e29c0084b 100644 (file)
@@ -88,8 +88,6 @@ TEXT runtime·mmap(SB),7,$36
        STOSL
        MOVL    $197, AX                // sys_mmap
        INT     $0x80
-       JCC     2(PC)
-       NEGL    AX
        RET
 
 TEXT runtime·munmap(SB),7,$-4
index 43399a5eee352b6185889a41deb656f977621edc..574d8a91b5d0d212d0a02c7d64cbbff1eefc5e40 100644 (file)
@@ -253,8 +253,6 @@ TEXT runtime·mmap(SB),7,$0
        MOVQ    $0, R9                  // arg 6 - pad
        MOVL    $197, AX                // sys_mmap
        SYSCALL
-       JCC     2(PC)
-       NEGQ    AX
        ADDQ    $16, SP
        RET
 
index a96e354ab74ea98649a3b067dd5c850fc6ddef24..37b6ff215a908e206509ddf95803217f30af7d7f 100644 (file)
@@ -89,8 +89,6 @@ TEXT runtime·mmap(SB),7,$36
        STOSL
        MOVL    $197, AX                // sys_mmap
        INT     $0x80
-       JCC     2(PC)
-       NEGL    AX
        RET
 
 TEXT runtime·munmap(SB),7,$-4
index 4d038a89e15b5b3e5bf6587010b5cad2f0532808..cbd2c2f7655a377ab72aec732691aead8b8c3982 100644 (file)
@@ -242,8 +242,6 @@ TEXT runtime·mmap(SB),7,$0
        MOVQ    $0, R9                  // arg 6 - pad
        MOVL    $197, AX
        SYSCALL
-       JCC     2(PC)
-       NEGQ    AX
        ADDQ    $16, SP
        RET