4 ms·
I mean, yes, no, it depends on what you mean? You can write to null in C, your operating system rejects it. You can write past your allocated memory, your OS
by abofh 8y ago
I mean, yes, no, it depends on what you mean?
You can write to null in C, your operating system rejects it. You can write past your allocated memory, your OS rejects it. It's not like just because it's written in C it gets to read the kernel memory - it's just that you can try.
All memory access in userspace is mediated by the MMU, so nothing in C gets "direct" memory access - but it does allow you to screw up your own memory space pretty well... I'm not sure that's C's fault though
- pjmlp 8y agoMany C targets also run bare metal, there is nothing to reject there, unless the hardware has an MMU and the code bothered to configure it on boot.
- saagarjha 8y agoBut is there really any programming language that lets you write to arbitrary memory? This is a problem of privileges rather than how low level your language is: it's not like you can write assembly that will give you arbitrary access to kernel memory.
- nerdponx 8y agoThat's my whole point. C doesn't try to stop you from doing that. C tries to do exactly what you ask it to, and if the OS doesn't allow it it just crashes. To me that is about as low level as you can get without bypassing the OS.
- ryao 8y agoTry using atomic instructions or initializing various tables during system boot. You will find that there are things C cannot do, unless you write assembly and call to it from C.
- billfruit 8y agoIn writing h kernal modules in C for vxworks, I find people quite often write/read data from hard-coded memmory addresses.