<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Try:<div><br></div><div><div>? (macroexpand '(#_getpid))</div><div>(%FF-CALL (%REFERENCE-EXTERNAL-ENTRY-POINT (LOAD-TIME-VALUE (EXTERNAL "getpid"))) :SIGNED-FULLWORD)</div><div><br></div><div>and then dig into that.</div><div><br></div><div><div>On Jun 21, 2019, at 9:09 AM, Jeremy Shoemaker <<a href="mailto:jeremy@codingkoi.com">jeremy@codingkoi.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Okay, I thought I had tried this already, but it definitely works with "printf" using both methods. I was using "getpid" because it's the first example in the documentation. I had already tried the underlying EXTERNAL-CALL approach with "getpid", it segfaults both ways.<br></div><div><br></div><div>I went back and tried the other examples there. "getpid" and "log2" both segfault, but the example with "write" works. I was thinking maybe there might be some connection between which library they're part of, but the first and last are both posix functions and "log2" is from libc.</div><div><br></div><div>Any ideas on how I can go about figuring out why some of them work and the others don't?<br></div><div><br></div><div>Thanks,</div><div>Jeremy<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 21, 2019 at 10:03 AM lsxvdqe <<a href="mailto:lsxvdqe@gmail.com">lsxvdqe@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Do other functions (like printf) segfault as well?<br>
What happens if you call some foreign function with EXTERNAL-CALL?<br>
#_getpid comes from the interface database, so try to FFI directly.<br>
You will have to do this anyway, if you want to make some bindings.<br>
<br>
On Thu, Jun 20, 2019 at 09:31:33AM -0500, Jeremy Shoemaker wrote:<br>
> I decided this morning to make sure everything on the device is sane, at<br>
> least as far as this particular function is concerned. Writing a C program<br>
> that just calls getpid and prints the result works fine with no segfaults.<br>
> It seems like it's definitely something on the CCL side of things.<br>
> <br>
> Jeremy<br>
> <br>
> On Wed, Jun 19, 2019 at 9:36 PM Jeremy Shoemaker <<a href="mailto:jeremy@codingkoi.com" target="_blank">jeremy@codingkoi.com</a>><br>
> wrote:<br>
> <br>
> > Okay, that was my thinking though I couldn't remember exactly how to get<br>
> > function pointers in C. After some fun setting up a cross-compiler, I got<br>
> > the test C program on the device, and then wrote the following Lisp code to<br>
> > try to duplicate the code.<br>
> ><br>
> > -----------------------------------------------------<br>
> > (defun peek-getpid-memory ()<br>
> > (let* ((addr (%ptr-to-int (foreign-symbol-address "getpid"))))<br>
> > (loop for offset from 0 to 15<br>
> > do<br>
> > (format t "~X " (%get-unsigned-long (%int-to-ptr (+ addr (* 4<br>
> > offset))))))))<br>
> > (peek-getpid-memory)<br>
> > -----------------------------------------------------<br>
> ><br>
> > I hope I did that right. I'm not terribly familiar with CCL's FFI yet.<br>
> > Given that I got the exact same output, I think it means I did.<br>
> ><br>
> > -----------------------------------------------------<br>
> > remarkable: ~/ ./test<br>
> > ee1d2f70 e52d7004 e5123454 e3530000 da000002 e1a00003 e49d7004 e12fff1e<br>
> > 1a000003 e5121458 e3510000 11a03001 1afffff7 e3a07014 ef000000 e3530000<br>
> > remarkable: ~/ ccl/armcl -l test.lisp<br>
> > EE1D2F70 E52D7004 E5123454 E3530000 DA000002 E1A00003 E49D7004 E12FFF1E<br>
> > 1A000003 E5121458 E3510000 11A03001 1AFFFFF7 E3A07014 EF000000 E3530000<br>
> > -----------------------------------------------------<br>
> ><br>
> > That seems to indicate it's pointing at the same place. Assuming that the<br>
> > address coming back from (foriegn-symbol-address "getpid") is the same<br>
> > thing that is invoked by the reader macro in (#_getpid), then it's<br>
> > confusing that I'm getting a segfault.<br>
> ><br>
> > Any other ideas?<br>
> ><br>
> > Jeremy<br>
> ><br>
> > On Wed, Jun 19, 2019 at 4:26 PM Ron Garret <<a href="mailto:ron@flownet.com" target="_blank">ron@flownet.com</a>> wrote:<br>
> ><br>
> >><br>
> >> On Jun 19, 2019, at 2:04 PM, Jeremy Shoemaker <<a href="mailto:jeremy@codingkoi.com" target="_blank">jeremy@codingkoi.com</a>><br>
> >> wrote:<br>
> >><br>
> >> > One suggestion: use %get-signed-long to read out a few bytes of memory<br>
> >> at the location reported by (external "getpid”) and then write a little C<br>
> >> program that does the same thing and see if you get the same result.<br>
> >><br>
> >> I'm not sure I entirely follow, at least the C program part. Are you<br>
> >> suggesting peeking at the memory pointed to by the `getpid` function in C?<br>
> >><br>
> >><br>
> >> Yes. Exactly.<br>
> >><br>
> >> I'm not quite sure how to do that, but my C is pretty rusty.<br>
> >><br>
> >><br>
> >> #include <unistd.h><br>
> >> #include <stdio.h><br>
> >><br>
> >> int main() {<br>
> >> unsigned int *p = (unsigned int *)getpid;<br>
> >> for (int i=0; i<16; i++) printf("%x ", *(p+i));<br>
> >> }<br>
> >><br>
> >><br>
<br>
> _______________________________________________<br>
> Openmcl-devel mailing list<br>
> <a href="mailto:Openmcl-devel@clozure.com" target="_blank">Openmcl-devel@clozure.com</a><br>
> <a href="https://lists.clozure.com/mailman/listinfo/openmcl-devel" rel="noreferrer" target="_blank">https://lists.clozure.com/mailman/listinfo/openmcl-devel</a><br>
<br>
</blockquote></div>
_______________________________________________<br>Openmcl-devel mailing list<br><a href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a><br>https://lists.clozure.com/mailman/listinfo/openmcl-devel<br></blockquote></div><br></div></body></html>