]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: better checks for syscall.NewCallback parameter
authorAlex Brainman <alex.brainman@gmail.com>
Thu, 11 Aug 2011 02:23:55 +0000 (12:23 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 11 Aug 2011 02:23:55 +0000 (12:23 +1000)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4859042

src/pkg/runtime/windows/thread.c

index 4ab043e8874e9958ac1323e8466ad19980a3e36c..e08d1b6f0e077d2a73b935b183a252484668922c 100644 (file)
@@ -347,16 +347,26 @@ static    Callbacks       cbs;
 byte *
 runtime·compilecallback(Eface fn, bool cleanstack)
 {
-       Func *f;
-       int32 argsize, n;
+       FuncType *ft;
+       Type *t;
+       int32 argsize, i, n;
        byte *p;
        Callback *c;
 
-       if(fn.type->kind != KindFunc)
-               runtime·panicstring("not a function");
-       if((f = runtime·findfunc((uintptr)fn.data)) == nil)
-               runtime·throw("cannot find function");
-       argsize = (f->args-2) * 4;
+       if(fn.type == nil || fn.type->kind != KindFunc)
+               runtime·panicstring("compilecallback: not a function");
+       ft = (FuncType*)fn.type;
+       if(ft->out.len != 1)
+               runtime·panicstring("compilecallback: function must have one output parameter");
+       if(((Type**)ft->out.array)[0]->size != sizeof(uintptr))
+               runtime·panicstring("compilecallback: output parameter size is wrong");
+       argsize = 0;
+       for(i=0; i<ft->in.len; i++) {
+               t = ((Type**)ft->in.array)[i];
+               if(t->size != sizeof(uintptr))
+                       runtime·panicstring("compilecallback: input parameter size is wrong");
+               argsize += t->size;
+       }
 
        // compute size of new fn.
        // must match code laid out below.