freenode/#sicl - IRC Chatlog
Search
10:07:24
heisig
Success! I can now execute arbitrary vectors of bytes as x86 assembler. It only took me two ours of reading manpages and tinkering with GDB.
10:08:49
heisig
I made one terrible mistake - I used C instead of Lisp, thinking it was more 'low level' and appropriate.
10:11:08
heisig
I will now switch back from C to Lisp. SBCL can't address bytes and call MMAP, too, and I won't have to deal with this humongous bullshit.
10:12:27
heisig
From the last two hours, I spend most of the time figuring out linker problems and casting pointers. What a mess.
10:13:34
heisig
I think it really doesn't matter that much how I generate the assembler instructions though. The snippets, callees and callers are all very short.
10:15:43
no-defun-allowed
From what I read, there is sb-alien:alien-funcall to call an alien function object, but I don't know how to make an alien function object. But NASM might be a better choice for writing assembler snippets.
10:16:54
heisig
After my recent encounter with C, NASM and x86 assembler might be downright soothing.
10:21:51
heisig
no-defun-allowed: sb-alien:alien-funcall might be just what I need. I will use NASM to generate the bytes, load them into a foreign array, and invoke the code with alien-funcall.
10:22:37
no-defun-allowed
Hm. Can you not generate an ELF file with NASM? Then you could use the usual CFFI machinery to load the foreign library and define the function.
10:24:04
heisig
I could. But I also want to print some things to stdout, measure the execution time, and occasionally change the snippet being jumped to.
10:25:15
no-defun-allowed
I guess it's likely CFFI will not let you overwrite the foreign code loaded, so using sb-alien might be the better choice.
10:26:00
heisig
The crucial part is that of atomically exchanging part of the code of the caller (the snippet address being jumped to). It will be interesting to see how modern CPUs cope with that.
10:56:10
heisig
shka_: That wouldn't be so bad. These addresses are only mutated when the callee is redefined.
11:12:47
heisig
shka_: I use mmap to allocate new pages that are both writable and executable, and I store my code there. So that should work.
11:13:20
no-defun-allowed
I think some operating systems don't allow WX pages, which makes modifying code a bit trickier.
11:14:07
no-defun-allowed
Not impossible, eg Java (I think) has some code to handle it on OpenBSD and macOS on AArch64 - it came up on #sbcl while porting some time ago.
11:39:58
no-defun-allowed
If you were a C programmer, I would say "that sounds like a _you_ problem..."