Parameter corruption in the FFI for PPC64?

Sebastián González <[email protected]> Thu, 21 Dec 2006 11:20:13 +0100
Newsgroups gmane.lisp.openmcl.bugs
Message-ID <[email protected]>
Hi,

I see no apparent reason for the following FFI code to fail.
It's about using the DNS Service Discovery API (i.e. Apple's Bonjour)  
in OpenMCL 1.0.

It works without problem on a PPC32 machine, but it fails on a PPC64  
machine.

#-----------------------------

(ccl:defcallback register-service-reply (:address sd-ref
                                          :unsigned-fullword flags
                                          :signed-fullword error-code
                                          (:* :char) name
                                          (:* :char) regtype
                                          (:* :char) domain
                                          (:* :void) context
                                          :void)
     (format t "registered!~%"))

(let* ((record-entry "path=/ide/")
        (record (format nil "~c~a" (length record-entry) record-entry)))
   (ccl:rlet ((cservice-ref :address))
     (ccl:with-cstrs ((cname "Test")
                      (ctype "_http._tcp")
                      (crecord record))
       (ccl:external-call "_DNSServiceRegister"
                          (:* :void) cservice-ref
                          (:unsigned 32) 0
                          (:unsigned 32) 0
                          (:* :char) cname
                          (:* :char) ctype
                          (:* :char) (ccl:%null-ptr)
                          (:* :char) (ccl:%null-ptr)
                          (:unsigned 16) 9001
                          (:unsigned 16) (length record)
                          (:* :void) crecord
                          (:* :void) register-service-reply
                          (:* :void) (ccl:%null-ptr)
                          (:signed 32)))))

#----------------------------

DNSServiceRegister returns the -65540 error code, which means "bad  
parameter".

(see http://developer.apple.com/documentation/Networking/Reference/ 
DNSServiceDiscovery_CRef/dns_sd/index.html)

I get the following in the log of the PPC64 machine:

 > tail /var/log/system.log
...
Dec 21 10:44:13 einstein mDNSResponder: ERROR:  
handle_regservice_request - service->type_as_string bad

 From the code of mDNSResponder at http://darwinsource.opendarwin.org/ 
10.4.2/mDNSResponder-107/mDNSShared/uds_daemon.c, one can see that  
the line printing this log entry is the following:

if (!*service->type_as_string || !MakeDomainNameFromDNSNameString 
(&service->type, service->type_as_string))
     	{ LogMsg("ERROR: handle_regservice_request - service- 
 >type_as_string bad %s", service->type_as_string); goto bad_param; }

It seems as if service->type_as_string was null in C, but I passed  
"_http._tcp" from Lisp.

I wrote a tiny test in C, and it works on the PPC64 machine. Hence,  
the problem doesn't seem to be located in libSystem.dylib (where  
DNSServiceRegister is defined). My next guess is that something is  
wrong with OpenMCL's FFI for PPC64, specially because PPC32 does not  
exhibit the same problem.