A friend sent me that code and alleges that it could damage the processor. Is that true?
void damage_processor() {
while (true) {
// Assembly code that sets the five control registers bits to ones which causes a bunch of exceptions in the system and then damages the processor
Asm(
"mov cr0, 0xffffffff \n\t"
"mov cr1, 0xffffffff \n\t"
"mov cr2, 0xffffffff \n\t"
"mov cr3, 0xffffffff \n\t"
"mov cr4, 0xffffffff \n\t"
)
}
}
Is that true?
Fan failure causes your CPU to overheat and your computer to randomly power down, and can result in permanent processor damage. If the fan is bad and replacing it does not solve the problem, your processor most likely has incurred permanent damage.
It depends. A tiny program that runs a critical loop can benefit greatly from a faster CPU while a large linear program will see no difference whatsoever. It all comes down to loops. Even a pentium1 will run trough tens of thousands of lines a code in a second, but a loop can take ages depending on what it does.
You don't need a high-end processor for basic coding. However, if you are into game development or software development, a good CPU can do wonders. Because of this reason, you need to upgrade your PC and opt for a newer CPU with more core count and clock speed.
From userspace code? No. It'll cause a privilege exception and the kernel will terminate your program. From kernel code? I doubt it; you will be throwing exceptions, and you'd have to manually set up the fault handler to return to the code in question to keep doing it. There's also a decent chance you'll cause a triple fault if part of the CR3 move succeeds, since that controls the page table address and you'll probably get faults on instruction fetch, handler fetch, and then the double fault handler fetch. The CPU should just shut down if that happens.
Check the Intel or AMD manuals for Systems programming, they'll tell you which exceptions will be thrown when writing invalid bits to the control registers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With