难道这code破坏我的处理器? [英] Could this code damage my processor?

查看:120
本文介绍了难道这code破坏我的处理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个朋友给我发了code和声称,它可能会损坏处理器。是真的吗?

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"
        )
    }
}

是这样吗?

推荐答案

从用户空间code?不,它会导致特权例外,内核会终止你的程序。从内核code?我对此表示怀疑;你会被抛出异常,而你不得不手动设置故障处理程序返回到code的问题要继续做下去。还有一个像样的机会,你会导致三重故障如果CR3行动的一部分成功,因为它控制页表的地址,你可能会得到指令故障取,取处理,然后双故障处理程序读取。该CPU应该只是关停如果出现这种情况。

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.

检查系统编程的Intel或AMD手册,他们会写无效位控制寄存器时,告诉你哪些异常将被抛出。

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.

这篇关于难道这code破坏我的处理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆