<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Oct 14, 2018 at 1:03 PM Alistair Grant <<a href="mailto:akgrant0710@gmail.com" target="_blank">akgrant0710@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> <br>
Hi All,<br>
<br>
Just in case there aren't automatic notifications of submissions to<br>
VMMakerInbox...<br>
<br>
I've submitted the following changes (more information after the descriptions):<br>
<br>
Name: VMMaker.oscog-AlistairGrant.2455<br>
Author: AlistairGrant<br>
Time: 14 October 2018, 8:59:01.383815 pm<br>
UUID: 9e8e4134-b30b-4734-9477-95d556650155<br>
Ancestors: VMMaker.oscog-eem.2454<br>
<br>
VMClass strlen, strncpy and getenv<br>
<br>
Pharo stores UTF8 encoded strings in ByteArrays (ByteString, strictly<br>
speaking, expects to only store characters that can be represented as<br>
a single byte in UTF8, e.g. ascii).  ByteArrays are also used within<br>
the simulator to represent buffers allocated by the simulator.  As<br>
such, the strings may either be the length of the ByteArray or less<br>
than the ByteArray size and null terminated.<br>
<br>
These changes extend strlen: and strncpy:_:_: to handle ByteArrays and<br>
add some tests (tests for strings in the object memory are todo).<br>
<br>
InterpreterPrimitives>>primitiveGetenv: returned nil rather than 0 in<br>
the simulator when a variable that isn't defined is requested.<br>
<br>
<br>
Name: VMMaker.oscog-AlistairGrant.2456<br>
Author: AlistairGrant<br>
Time: 14 October 2018, 9:25:11.249348 pm<br>
UUID: 47b0319d-df10-4ece-84fc-324d0d35fe1d<br>
Ancestors: VMMaker.oscog-AlistairGrant.2455<br>
<br>
FakeStdinStream and FilePluginSimulator do double duty with the #atEnd<br>
flag to allow #sqFile:Read:Into:At: to break out of its loop.  This is<br>
brittle as a additional calls to #atEnd breaks the simulation - which<br>
is what Pharo does.<br>
<br>
Instead of doing double duty with #atEnd, do the same as the actual<br>
plugin (sqFileReadIntoAt() in sqFilePluginBasicPrims.c) and ignore the<br>
number of bytes to read when input is from stdin (FakeStdinStream) and<br>
only ever read a single byte (fixes the problem and is closer to the<br>
real plugin behaviour).<br>
<br>
<br>
Background:<br>
<br>
I've successfully got a Pharo 7 image (with FileAttributesPlugin)<br>
running StdioListener in the VM simulator, but have made a few changes<br>
at each level:<br>
<br>
- Created a modified Pharo image that avoids FFI:<br>
-- It doesn't load FreeType fonts or Iceberg to avoid FFI callouts.<br>
-- Uses UnixOSProcessPlugin>>primitiveGetCurrentWorkingDirectory<br>
instead of an FFI callout.<br>
- StdioListener has changes to work with Zinc streams<br>
- VMMaker has changes (in addition to the patches above):<br>
-- Added UnixOSProcessPluginSimulator so that<br>
primitiveGetCurrentWorkingDirectory can be used instead of FFI.<br>
<br>
Can someone tell me whether FFI is expected to work within the simulator?<br></blockquote><div><br></div><div>As yet no.  But in theory it may be possible.  If you look at the way in which primitives are dispatched in the simulator (dispatchFunctionPointer:) that could be used to implement FFI calls (although not particularly safely).  I have written ThreadedFFIPlugin>>dispatchFunctionPointer:[with:with:with:with:[with:with:]] in such a way that the call could be simulated (when I added support for PrimErrFFIException).  Simulating ThreadedFFIPlugin>>dispatchFunctionPointer:[with:with:with:with:[with:with:]] would require invoking an FFI call itself (i.e. via ExternalFunction>>invokeWithArguments:) to do the actual call-out.  But too do that we would need a derived pointer type, so that e.g. an address in the heap (SpurMemoryManager/ObjectMemory memory inst var) could be passed as an argument; such an address is an offset to the memory ByteArray.  So we're close, but still need some infrastructure (and derived pointers are generally useful anyway).</div><div><br></div><div>Clearly such an implementation is unsafe; but increasingly we will need to simulate FFI calls if the simulator is to continue being useful.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Thanks,<br>
Alistair<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-2492303041439179705gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div></div></div></div>