[M3devel] checking function pointers for null?

Tony Hosking hosking at cs.purdue.edu
Mon Jun 21 16:26:31 CEST 2010


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
> 		 	   		  




More information about the M3devel mailing list