Commit 94955f9b authored by Jan Ziak's avatar Jan Ziak Committed by Russ Cox

runtime: check the value returned by runtime·SysAlloc

R=golang-dev, rsc
CC=golang-dev, minux.ma
https://golang.org/cl/7424047
parent df60c0a3
...@@ -519,6 +519,8 @@ runtime·settype_flush(M *mp, bool sysalloc) ...@@ -519,6 +519,8 @@ runtime·settype_flush(M *mp, bool sysalloc)
data3 = runtime·mallocgc(nbytes3, FlagNoPointers, 0, 1); data3 = runtime·mallocgc(nbytes3, FlagNoPointers, 0, 1);
} else { } else {
data3 = runtime·SysAlloc(nbytes3); data3 = runtime·SysAlloc(nbytes3);
if(data3 == nil)
runtime·throw("runtime: cannot allocate memory");
if(0) runtime·printf("settype(0->3): SysAlloc(%x) --> %p\n", (uint32)nbytes3, data3); if(0) runtime·printf("settype(0->3): SysAlloc(%x) --> %p\n", (uint32)nbytes3, data3);
} }
...@@ -555,6 +557,8 @@ runtime·settype_flush(M *mp, bool sysalloc) ...@@ -555,6 +557,8 @@ runtime·settype_flush(M *mp, bool sysalloc)
data2 = runtime·mallocgc(nbytes2, FlagNoPointers, 0, 1); data2 = runtime·mallocgc(nbytes2, FlagNoPointers, 0, 1);
} else { } else {
data2 = runtime·SysAlloc(nbytes2); data2 = runtime·SysAlloc(nbytes2);
if(data2 == nil)
runtime·throw("runtime: cannot allocate memory");
if(0) runtime·printf("settype.(3->2): SysAlloc(%x) --> %p\n", (uint32)nbytes2, data2); if(0) runtime·printf("settype.(3->2): SysAlloc(%x) --> %p\n", (uint32)nbytes2, data2);
} }
......
...@@ -585,6 +585,8 @@ scanblock(Workbuf *wbuf, Obj *wp, uintptr nobj, bool keepworking) ...@@ -585,6 +585,8 @@ scanblock(Workbuf *wbuf, Obj *wp, uintptr nobj, bool keepworking)
if(bufferList == nil) { if(bufferList == nil) {
bufferList = runtime·SysAlloc(sizeof(*bufferList)); bufferList = runtime·SysAlloc(sizeof(*bufferList));
if(bufferList == nil)
runtime·throw("runtime: cannot allocate memory");
bufferList->next = nil; bufferList->next = nil;
} }
scanbuffers = bufferList; scanbuffers = bufferList;
...@@ -1147,6 +1149,8 @@ getempty(Workbuf *b) ...@@ -1147,6 +1149,8 @@ getempty(Workbuf *b)
if(work.nchunk < sizeof *b) { if(work.nchunk < sizeof *b) {
work.nchunk = 1<<20; work.nchunk = 1<<20;
work.chunk = runtime·SysAlloc(work.nchunk); work.chunk = runtime·SysAlloc(work.nchunk);
if(work.chunk == nil)
runtime·throw("runtime: cannot allocate memory");
} }
b = (Workbuf*)work.chunk; b = (Workbuf*)work.chunk;
work.chunk += sizeof *b; work.chunk += sizeof *b;
...@@ -1230,6 +1234,8 @@ addroot(Obj obj) ...@@ -1230,6 +1234,8 @@ addroot(Obj obj)
if(cap < 2*work.rootcap) if(cap < 2*work.rootcap)
cap = 2*work.rootcap; cap = 2*work.rootcap;
new = (Obj*)runtime·SysAlloc(cap*sizeof(Obj)); new = (Obj*)runtime·SysAlloc(cap*sizeof(Obj));
if(new == nil)
runtime·throw("runtime: cannot allocate memory");
if(work.roots != nil) { if(work.roots != nil) {
runtime·memmove(new, work.roots, work.rootcap*sizeof(Obj)); runtime·memmove(new, work.roots, work.rootcap*sizeof(Obj));
runtime·SysFree(work.roots, work.rootcap*sizeof(Obj)); runtime·SysFree(work.roots, work.rootcap*sizeof(Obj));
...@@ -1381,6 +1387,8 @@ handlespecial(byte *p, uintptr size) ...@@ -1381,6 +1387,8 @@ handlespecial(byte *p, uintptr size)
if(finq == nil || finq->cnt == finq->cap) { if(finq == nil || finq->cnt == finq->cap) {
if(finc == nil) { if(finc == nil) {
finc = runtime·SysAlloc(PageSize); finc = runtime·SysAlloc(PageSize);
if(finc == nil)
runtime·throw("runtime: cannot allocate memory");
finc->cap = (PageSize - sizeof(FinBlock)) / sizeof(Finalizer) + 1; finc->cap = (PageSize - sizeof(FinBlock)) / sizeof(Finalizer) + 1;
finc->alllink = allfin; finc->alllink = allfin;
allfin = finc; allfin = finc;
......
...@@ -37,6 +37,8 @@ RecordSpan(void *vh, byte *p) ...@@ -37,6 +37,8 @@ RecordSpan(void *vh, byte *p)
if(cap < h->nspancap*3/2) if(cap < h->nspancap*3/2)
cap = h->nspancap*3/2; cap = h->nspancap*3/2;
all = (MSpan**)runtime·SysAlloc(cap*sizeof(all[0])); all = (MSpan**)runtime·SysAlloc(cap*sizeof(all[0]));
if(all == nil)
runtime·throw("runtime: cannot allocate memory");
if(h->allspans) { if(h->allspans) {
runtime·memmove(all, h->allspans, h->nspancap*sizeof(all[0])); runtime·memmove(all, h->allspans, h->nspancap*sizeof(all[0]));
runtime·SysFree(h->allspans, h->nspancap*sizeof(all[0])); runtime·SysFree(h->allspans, h->nspancap*sizeof(all[0]));
......
...@@ -40,6 +40,8 @@ allocate(uintptr size) ...@@ -40,6 +40,8 @@ allocate(uintptr size)
runtime·lock(&alloclock); runtime·lock(&alloclock);
if(size > poolfree) { if(size > poolfree) {
pool = runtime·SysAlloc(Chunk); pool = runtime·SysAlloc(Chunk);
if(pool == nil)
runtime·throw("runtime: cannot allocate memory");
poolfree = Chunk; poolfree = Chunk;
} }
v = pool; v = pool;
...@@ -100,6 +102,8 @@ stkbucket(int32 typ, uintptr *stk, int32 nstk, bool alloc) ...@@ -100,6 +102,8 @@ stkbucket(int32 typ, uintptr *stk, int32 nstk, bool alloc)
if(buckhash == nil) { if(buckhash == nil) {
buckhash = runtime·SysAlloc(BuckHashSize*sizeof buckhash[0]); buckhash = runtime·SysAlloc(BuckHashSize*sizeof buckhash[0]);
if(buckhash == nil)
runtime·throw("runtime: cannot allocate memory");
mstats.buckhash_sys += BuckHashSize*sizeof buckhash[0]; mstats.buckhash_sys += BuckHashSize*sizeof buckhash[0];
} }
...@@ -123,6 +127,8 @@ stkbucket(int32 typ, uintptr *stk, int32 nstk, bool alloc) ...@@ -123,6 +127,8 @@ stkbucket(int32 typ, uintptr *stk, int32 nstk, bool alloc)
return nil; return nil;
b = allocate(sizeof *b + nstk*sizeof stk[0]); b = allocate(sizeof *b + nstk*sizeof stk[0]);
if(b == nil)
runtime·throw("runtime: cannot allocate memory");
bucketmem += sizeof *b + nstk*sizeof stk[0]; bucketmem += sizeof *b + nstk*sizeof stk[0];
runtime·memmove(b->stk, stk, nstk*sizeof stk[0]); runtime·memmove(b->stk, stk, nstk*sizeof stk[0]);
b->typ = typ; b->typ = typ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment