by kepler471 on 5/25/25, 5:00 PM with 38 comments
by ivanjermakov on 5/25/25, 8:09 PM
by iamcreasy on 6/7/25, 2:28 AM
by Cloudef on 5/26/25, 11:17 AM
by DrZhvago on 5/26/25, 5:53 PM
Also, I spent a moderately successful internship at Microsoft working on dynamic assemblies. I never got deep enough into that to fully understand when and how customers where actually using it.
https://learn.microsoft.com/en-us/dotnet/fundamentals/reflec...
by pfdietz on 5/26/25, 11:56 AM
by alcover on 5/25/25, 7:41 PM
by xixixao on 5/26/25, 6:04 AM
The only way to do this now on macOS is remapping whole pages as JIT. This makes it quite a challenge but still it might work…
by oxcabe on 5/25/25, 8:06 PM
by belter on 5/25/25, 6:31 PM
by Someone on 5/26/25, 6:01 AM
- assumes x86_64
- makes the invalid assumption that functions get compiled into a contiguous range of bytes (I’m not aware of any compiler that violates that, but especially with profile-guided optimization or compilers that try to minimize program size, that may not be true, and there is nothing in the standard that guarantees it)
- assumes (as the article acknowledges) that “to determine the length of foo(), we added an empty function, bar(), that immediately follows foo(). By subtracting the address of bar() from foo() we can determine the length in bytes of foo().”. Even simple “all functions align at cache lines” slightly violates that, and I can see a compiler or a linker move the otherwise unused bar away from foo for various reasons.
- makes assumptions about the OS it is running on.
- makes assumptions about the instructions that its source code gets compiled into. For example, in the original example, a sufficiently smart compiler could compile
void foo(void) {
int i=0;
i++;
printf("i: %d\n", i);
}
as void foo(void) {
printf("1\n");
}
or maybe even void foo(void) {
puts("1");
}
Changing compiler flags can already break this program.Also, why does this example work without flushing the instruction cache after modifying the code?