4 ms·
Anything that doesn't require W+X would need an entire page allocated per closure, wouldn't it?
by rabidferret 7y ago
Anything that doesn't require W+X would need an entire page allocated per closure, wouldn't it?
- devit 7y agoNo, you can of course allocate W+X pages from the OS and put multiple closures in them using a standard userspace memory allocator. Or if the OS doesn't support W+X allocation at all, then you can have a bunch of tightly packed pregenerated trampolines in the binary.
- saagarjha 7y agoRight, this is how Objective-C's implementation works, except it keeps around one page of trampolines and remaps that around when necessary to be able to "create" more trampolines on the fly, I believe.
- a1369209993 7y agoNope! You'd do something to the effect of: clo_code: 4C8B1501100000 mov r10 [rel clo_code+0x1008] FF25F30F0000 jmp [rel clo_code+0x1000] 0F1F00 nop3 # one page away... struct clo_slot { void (*func)(void* _R10,...); void* data; }; Edit: to use r10 rather than rotating all the argument registers.