0xDEADBEEF 等效于 64 位开发吗? [英] 0xDEADBEEF equivalent for 64-bit development?

查看:27
本文介绍了0xDEADBEEF 等效于 64 位开发吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 32 位系统的 C++ 开发(无论是 Linux,Mac OS 或Windows、PowerPC 或 x86) 我已经初始化了指针否则将是未定义的(例如,他们不能立即得到一个合适的值)像这样:

For C++ development for 32-bit systems (be it Linux, Mac OS or Windows, PowerPC or x86) I have initialised pointers that would otherwise be undefined (e.g. they can not immediately get a proper value) like so:

int *pInt = reinterpret_cast<int *>(0xDEADBEEF);

(为了节省打字和成为 DRY 右侧通常会保持不变,例如BAD_PTR.)

(To save typing and being DRY the right-hand side would normally be in a constant, e.g. BAD_PTR.)

如果 pInt 在获得正确值之前被取消引用,则它会在大多数系统上立即崩溃(而不是当某些内存被覆盖或消失时,会在很晚之后崩溃进入一个很长的循环).

If pInt is dereferenced before it gets a proper value then it will crash immediately on most systems (instead of crashing much later when some memory is overwritten or going into a very long loop).

当然行为取决于底层硬件(从奇数中获取 4 字节整数来自用户进程的地址 0xDEADBEEF 可能是完美的有效),但对于所有的崩溃都是 100% 可靠的到目前为止我开发的系统(Mac OS 68xxx,Mac OSPowerPC、Linux Redhat Pentium、Windows GUI Pentium、Windows控制台奔腾).例如在 PowerPC 上它是非法的(总线错误)从一个奇数地址获取一个 4 字节的整数.

Of course the behavior is dependent on the underlying hardware (getting a 4 byte integer from the odd address 0xDEADBEEF from a user process may be perfectly valid), but the crashing has been 100% reliable for all the systems I have developed for so far (Mac OS 68xxx, Mac OS PowerPC, Linux Redhat Pentium, Windows GUI Pentium, Windows console Pentium). For instance on PowerPC it is illegal (bus fault) to fetch a 4 byte integer from an odd address.

这在 64 位系统上有什么好处?

What is a good value for this on 64-bit systems?

推荐答案

一般来说具体你写什么模式并不重要,重要的是你能识别模式以确定问题在哪里正在发生.碰巧的是,在 Linux 内核中,通常会选择这些地址,以便在取消引用地址时可以捕获它们.

Generally it doesn't matter exactly what pattern you write, it matters that you can identify the pattern in order to determine where problems are occurring. It just so happens that in the Linux kernel these are often chosen so that they can be trapped if the addresses are dereferenced.

include/linux/poison.h.该文件包含许多不同内核子系统的不同毒值.没有一种毒值是合适的.

Have a look in the Linux kernel at include/linux/poison.h. This file contains different poison values for many different kernel subsystems. There is no one poison value that is appropriate.

此外,您可以检查 Linux 内核源代码树中的每个架构包含文件,以获取有关特定架构上使用的内容的信息.

Also, you might check per-architecture include files in the Linux kernel source tree for info on what is used on specific architectures.

这篇关于0xDEADBEEF 等效于 64 位开发吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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