[M3devel] checking function pointers for null?

Jay K jay.krell at cornell.edu
Mon Jun 21 09:55:19 CEST 2010


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