<body><div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
Writing into executable memory becomes harder and harder these days ;o)<div class="mb_sig"></div><blockquote class='history_container' type='cite' style='border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;'>
<p style='color: #AAAAAA; margin-top: 10px;'>Am 19.04.2022 11:25:40 schrieb commits@source.squeak.org <commits@source.squeak.org>:</p><div style='font-family:Arial,Helvetica,sans-serif'>Marcel Taeumel uploaded a new version of FFI-Callbacks to project FFI:<br>http://source.squeak.org/FFI/FFI-Callbacks-mt.30.mcz<br><br>==================== Summary ====================<br><br>Name: FFI-Callbacks-mt.30<br>Author: mt<br>Time: 19 April 2022, 11:25:30.789004 am<br>UUID: 0278f498-8447-4e48-84db-9c5bf5cae4d3<br>Ancestors: FFI-Callbacks-mt.29<br><br>Fixes callbacks "Bus error" on (macOS) ARM64 platforms.<br><br>=============== Diff against FFI-Callbacks-mt.29 ===============<br><br>Item was changed:<br> ----- Method: FFICallback class>>allocateExecutableBlock (in category 'executable pages') -----<br> allocateExecutableBlock<br> <br>+ | blockSize newBlock |<br>- | blockSize |<br> blockSize := MaxThunkSize.<br>- ExecutablePagesAccessProtect critical:<br>- [ExecutablePages do:<br>- [:page |<br>- 1 to: page size - blockSize by: blockSize do:<br>- [:i|<br>- (page at: i) = 0 ifTrue:<br>- [page at: i put: 1.<br>- ^ page from: i to: i + blockSize - 1]]]].<br> ExecutablePagesAccessProtect critical: [<br>+ ExecutablePages do: [:page |<br>+ 1 to: page size - blockSize by: blockSize do: [:i |<br>+ (page at: i) = 0 ifTrue: [<br>+ newBlock := page from: i to: i + blockSize - 1.<br>+ self markExecutableBlock: newBlock.<br>+ ^ newBlock]]]].<br>+ ExecutablePagesAccessProtect critical: [<br> | newPage |<br> newPage := ExecutablePages add: self allocateExecutablePage.<br>+ newBlock := newPage from: 1 to: blockSize.<br>+ self markExecutableBlock: newBlock.<br>+ ^ newBlock]!<br>- ^ (newPage from: 1 to: blockSize)<br>- at: 1 put: 1; "Mark as allocated."<br>- yourself]!<br><br>Item was changed:<br> ----- Method: FFICallback class>>allocateExternal (in category 'instance creation') -----<br> allocateExternal<br> "Overwritten for custom management of executable pages. Assure compatibility with Alien."<br> <br> | instance |<br>+ instance := self fromHandle: self allocateExecutableBlock getHandle.<br>- instance := self fromHandle: self allocateExecutableBlock getHandle.<br> AlienStub isAlienLoaded ifTrue: [instance addToAlienThunkTable].<br> ^ instance!<br><br>Item was added:<br>+ ----- Method: FFICallback class>>markExecutableBlock: (in category 'executable pages') -----<br>+ markExecutableBlock: externalData<br>+ "Mark the block of executable memory that is represented by externalData as being used. We do this to allow several subsequent calls to #allocateExecutableBlock without actually writing a thunk in it. NOTE THAT we must use a special primitive to write into executable memory on ARM64 platforms."<br>+ <br>+ FFIPlatformDescription current abi == #ARM64<br>+ ifTrue: [self writeExecutableBlockAt: externalData getHandle bytes: #[1]]<br>+ ifFalse: [externalData at: 1 put: 1].!<br><br>Item was added:<br>+ ----- Method: FFICallback class>>zeroExecutableBlock: (in category 'executable pages') -----<br>+ zeroExecutableBlock: externalObject "< ExternalData | FFICallback>"<br>+ "Variation of #zeroMemory to handle writing into executable memory on ARM64 platforms."<br>+ <br>+ FFIPlatformDescription current abi == #ARM64<br>+ ifTrue: [self writeExecutableBlockAt: externalObject getHandle bytes: (ByteArray new: externalObject byteSize)]<br>+ ifFalse: [externalObject getHandle zeroMemory: externalObject byteSize].!<br><br>Item was changed:<br> ----- Method: FFICallback>>zeroMemory (in category 'initialize-release') -----<br> zeroMemory<br> <br> ExecutablePagesAccessProtect critical: [<br>+ self class zeroExecutableBlock: self].!<br>- super zeroMemory].!<br><br><br></div></blockquote>
</div></body>