[M3devel] checking function pointers for null?

Jay K jay.krell at cornell.edu
Mon Jun 21 19:47:48 CEST 2010


Neither backend would add these checks themself, it is m3cg, IR later.

> Subject: Re: [M3devel] checking function pointers for null?
> From: hosking at cs.purdue.edu
> Date: Mon, 21 Jun 2010 10:26:31 -0400
> CC: m3devel at elegosoft.com
> To: jay.krell at cornell.edu
> 
> Is this code from M3CG or the Windows native backend?
> 
> If from M3CG perhaps you can show us the M3CG IR code.
> 
> On 21 Jun 2010, at 03:55, Jay K wrote:
> 
> > 
> > This is code that calls a function pointer:
> > 
> > 
> >         testq   %rbx, %rbx ; test function pointer for null
> >         je      L6
> >         cmpq    $-1, (%rbx) ; check for closure marker
> >         jne     L6  ; if not a closure, goto L6
> >         movq    16(%rbx), %r13 ; r13=static chain (ought to use r10?) 
> >         movq    8(%rbx), %rax ; rax=actual function pointer
> >         jmp     L8
> > L6:
> >         movq    %rbx, %rax ; rax=actual function pointer
> > L8:
> >         movq    %r13, %r10 ; r10=static chain (it should have just used r10 in the first place? or is r13 otherwise the previous static chain?)
> >         call    *%rax
> > 
> > 
> > What is the point of the initial testq/je, if we are just going to jump to the address anyway?
> > Should we do something else if in fact the function pointer is null? Or just let a jump to null fail as it will?
> > You know -- it seems me we should do either more or less here.
> > More: report a null deref by calling m3_fault
> > Less: remove the null check 
> > 
> > 
> >  - Jay
> > 		 	   		  
> 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100621/13be0de5/attachment-0002.html>


More information about the M3devel mailing list