IVT在地址0 [英] IVT at address 0

查看:124
本文介绍了IVT在地址0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




标准骑师的另一个问题......


假设我有一个位于地址0x0000的中断向量表(16位

从(你猜对了)0x0000开始。所以我会得到


struct iv_s * ivt =(struct iv_s *)0x0000;


这将产生一个可能不是的NULL指针dereferenced,以免

将导致未定义的行为。


问题:我如何得到这个?有没有可能没有复制表(在

汇编中以避免解除引用任何指针),因为当前的解决方案是
或者公然忽略任何UB而只是指望我的编译器不要介意呢

多吗?

Hi,

Just another question for the standards jockeys...

Suppose I have an Interrupt Vector Table located at address 0x0000 (16-bit
machine). I want to dump the context of the IVT, by treating it as an array
starting at (you guessed it) 0x0000. So I would have

struct iv_s* ivt = (struct iv_s *) 0x0000;

Which will yield a NULL pointer which may not be dereferenced, lest
undefined behavior would result.

Question: How do I get by this? Is it possible without copying the table (in
assembly to avoid dereferencing any pointers) as the current solution does
or blatantly ignore any UB and just count on my compiler not to mind too
much?

推荐答案

文章< 41 ******** ***************@dreader7.news.xs4all.nl>,

蒲公英< da ******* @ meadow.net>写道:
In article <41***********************@dreader7.news.xs4all.nl >,
dandelion <da*******@meadow.net> wrote:
假设我有一个中断向量表位于地址0x0000(16位
机器)。
Suppose I have an Interrupt Vector Table located at address 0x0000 (16-bit
machine).




如果没有超出标准C

定义的范围,你就无法访问这样的东西,所以你不应该担心地址0超过

如果它是地址123456.要么你的操作系统和编译器

使它工作,或者他们不是; C标准并没有进入它。


- Richard



You can''t access such a thing without going outside what standard C
defines, so you shouldn''t worry about it being address 0 any more than
if it was address 123456. Either your operating system and compiler
make it work, or they don''t; the C standard doesn''t come into it.

-- Richard




" ;理查德托宾 < RI ***** @ cogsci.ed.ac.uk>在消息中写道

news:co *********** @ pc-news.cogsci.ed.ac.uk ...

"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:co***********@pc-news.cogsci.ed.ac.uk...
在文章中< 41 *********************** @ dreader7.news.xs4all.nl>,
蒲公英< da ***** **@meadow.net>写道:
In article <41***********************@dreader7.news.xs4all.nl >,
dandelion <da*******@meadow.net> wrote:
假设我有一个中断向量表位于地址0x0000
(16位机器)。
Suppose I have an Interrupt Vector Table located at address 0x0000 (16-bitmachine).



你可以'在没有超出标准C
定义的范围之外访问这样的东西,所以如果它是地址123456你不应该担心它是地址0。你的操作系统和编译器<让它发挥作用,或者它们不会; C标准并没有进入它。



You can''t access such a thing without going outside what standard C
defines, so you shouldn''t worry about it being address 0 any more than
if it was address 123456. Either your operating system and compiler
make it work, or they don''t; the C standard doesn''t come into it.




这就是我的想法。谢谢。



That''s what I figured. Thanks.


"蒲公英" <哒******* @ meadow.net>写道:
"dandelion" <da*******@meadow.net> wrote:
假设我有一个位于地址0x0000(16位机器)的中断向量表。我想转储IVT的上下文,将其视为一个数组
从(你猜对了)0x0000开始。所以我会有结构iv_s * ivt =(struct iv_s *)0x0000;

这将产生一个可能无法解除引用的NULL指针,以免
取消定义行为会导致。
Suppose I have an Interrupt Vector Table located at address 0x0000 (16-bit
machine). I want to dump the context of the IVT, by treating it as an array
starting at (you guessed it) 0x0000. So I would have

struct iv_s* ivt = (struct iv_s *) 0x0000;

Which will yield a NULL pointer which may not be dereferenced, lest
undefined behavior would result.




首先,如果您的系统允许您从

地址0x0000读取和写入,那么处理这种UB情况的方法应该是

表现得好像你使用了一个有效的指针。

但是,要小心这个。对于所有其他整数值,我会

期望上面的行产生预期的指针。然而,文字0,<​​br />
是特殊的。正如你所说的那样(尽管使用错误的

大小写),它必须求值为空指针。并且空指针不需要

为零地址。所以,为了确保你确实得到零地址,我建议你使用


int i = 0;

struct iv_s * ivt =(struct iv_s *)i;


当然,这种转换产生的指针值在任何情况下都是system-

,所以即使这不是保证。然而,在

(不可否认的罕见)系统中,空指针并非所有内部零位

内部,我希望单行代码段失败,而

两行代码可能会在那里工作。


Richard



Well, first of all, if your system allows you to read and write from
address 0x0000 at all, its way to handle this case of UB should be to
behave as if you used a valid pointer.
However, beware of the snark. For all other integer values, I would
expect the above line to yield the expected pointer. A literal 0,
however, is special. It must, as you say (albeit using the wrong
capitalisation), evaluate to a null pointer. And a null pointer need not
be address zero. So, to make doubly sure that you do get address zero, I
suggest you use

int i=0;
struct iv_s *ivt=(struct iv_s *)i;

Of course, the pointer value resulting from such a conversion is system-
specific in any case, so even this is no guarantee. However, on the
(admittedly rare) systems where a null pointer is not all bits zero
internally, I would expect the one-line snippet to fail, whereas the
two-line code will probably work even there.

Richard


这篇关于IVT在地址0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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