4 ms·
Writing a dynamic x86_64 assembler in Scala
- TerryADavis 10y agoBrendan at http://www.osdev.net http://www.osdev.net is a CIA agent. Brendan would say you must plan all the modes and all the instructions. Brendan would try to make you do too big a chunk and give up. Brendan tries to make people fail by expanding their notions and belitteling small things.
- aiglon 10y agoIs the generated code really faster? Or what is the point of this?
- guillaumebort 10y agoWell for this specific `add` function, no it won't :) The hotspot compiler will generate the same code anyway (perhaps even more optimised if it is possible I don't know). Worse, this code would probably be inlined while the `native` version won't.
- aardvark179 10y agoNot only will the native version not be inlined, the JIT will also have to insert an annoying amount of stuff round it to handle calling conventions and other fun things.
- dkopi 10y agoWhile very(!) cool as a proof of concept, This type of solution should probably be avoided for security, stability and portability reasons. Allowing a string in your program to be dynamically converted to assembly code, copied to executable memory and be executed is a remote code execution security hole just waiting to happen. I'm wondering what the use cases for this were, and if they couldn't be achieved in another way.
- guillaumebort 10y agoI agree with you, doing this breaks almost all the advantages you have using a JVM in the first place. So you probably don't want to hack this way. There was no real use case for trying this. Just to see if it would be possible. As you say it is just a proof of concept.
- userbinator 10y agoSeriously? It says a lot about the direction computing is going when one of the first things someone says upon seeing one of the most powerful and amazing things you can do with a general-purpose computer is some fearmongering about a "remote code execution security hole". The "oppose anything that could possibly be used in some way someone doesn't like" attitude is why computers have become so user-hostile. :-(
- dkopi 10y agoProtecting the safety, security and privacy of users isn't "user-hostile". Leaving your users exposed to hackers, viruses, malware, malicious adware, ransomware, government espionage and bot networks is. I find it completely baffling than in 2016, people can still refer to writing secure code as "fearmongering". Being able to dynamically inject code into your process and run it is indeed very powerful. But i'll cliche quote spiderman about great power, and insist that if you're going to execute "mprotect" or "VirtualProtect", make sure the code you're about to execute is signed and verified. Not doing so, would be user-hostile.
- junke 10y agoSure, this is a valid concern, but in the context of a learning experiment like the one discussed here, this is not really important. "Hey kid, nice treehouse, but what about burglars?"
- dkopi 10y agoFrom the scasm readme.md: "Do not ask for the final goal of this: this is more a learning vehicle to abord several interesting topics." Isn't security one of those interesting topics?
- xaduha 10y agoQuick intro to x86_64 assembler, FOSDEM presentation: http://video.fosdem.org/2016/h2214/amd64-assembly-programming-for-perl-programmers.mp4 http://video.fosdem.org/2016/h2214/amd64-assembly-programmin... https://github.com/bdw/lab/tree/master/asm https://github.com/bdw/lab/tree/master/asm
- vans 10y agoI saw the talk. It was a nice hack !
- electrum 10y agoFor a more complete x86 and x86_64 assembler for JVM languages: https://github.com/jnr/jnr-x86asm https://github.com/jnr/jnr-x86asm