且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

奇怪的语法

更新时间:2022-10-16 23:08:34

se*****@gmail.com 说:

大家好,

我在linux / kernel / signal.c中找到了一段代码:


int

send_sig (int sig,struct task_struct * p,int priv)

{

返回send_sig_info(sig,(void *)(long)(priv!= 0),p) ;

}


"(void *)(long)(priv!= 0)" ?



这意味着警告!狡猾的代码!修复我!


(priv!= 0)产生一个0或1的结果。

将此转换为(long)会产生一个值这是0L或1L。

转换为(void *)会产生一个值,该值不太可能是指向任何对象或函数的有效

指针。 />

愚蠢的愚蠢。


注意:即使当前内核中不存在此代码,它也是

在2.4.xx中是avlbl。



那么你所说的是,有人找到了他们的感觉并且b / b
将它撕掉了。好!


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件: -http:// WWW。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置&QUOT; - dmr 1999年7月29日


12月5日上午12:33,看到... @ gmail.com写道:

大家好,

我在linux / kernel / signal.c中找到了一段代码:


int

send_sig(int sig,struct task_struct * p,int priv)

{

return send_sig_info(sig,(void *)(long)(priv!= 0) ,p);


}


"(void *)(long)(priv!= 0)&quot是什么意思; ?


TIA



第二个参数的类型为struct siginfo *。 NULL(0)指针

这里表示用户kill sig。特殊保留指针(struct

siginfo *)1用于内核sigs。 (priv!= 0)如果priv为0,则值为0

,否则为1。强制转换将此int值强制转换为兼容的

指针。效果是权限级别0导致用户签名和

所有其他内核签名。我不清楚为什么(void *)(long)是用
而不是(struct siginfo *),但效果应该是

相同。


Richard Heathfield写道:
se ***** @ gmail.com 说:

>大家好,
我发现了一块linux / kernel / signal.c中的代码:

send_sig(int sig,struct task_struct * p,int priv)
{
return send_sig_info(sig) ,(void *)(long)(priv!= 0),p);
}

"(void *)(long)是什么意思(priv!= 0 )&QUOT; ?



这意味着警告!狡猾的代码!修复我!


(priv!= 0)产生一个0或1的结果。

将此转换为(long)会产生一个值这是0L或1L。

转换为(void *)会产生一个值,该值不太可能是指向任何对象或函数的有效

指针。 />

愚蠢的愚蠢。



公平地说,在linux / kernel / anything中找到的代码不太可能用便携式标准C写成

并且可能被允许利用实施 -

具体细节。 (演员看起来很奇怪,但据我们所知,它可以避免特定于实现的错误。)


如你所知,鲍勃,标准并不能阻止你依赖

的实施细节;它只是没有定义如果你是b $ b那么会发生什么。有时候这是件好事。


-

克里斯它只有/看起来/喜欢C Dollin


Hewlett-Packard Limited注册号:

注册办事处:Cain Road,Bracknell,Berks RG12 1HN 690597英格兰


Hi All,
I found a piece of code in linux/kernel/signal.c:

int
send_sig(int sig, struct task_struct *p, int priv)
{
return send_sig_info(sig, (void*)(long)(priv != 0), p);
}
What is the meaning of "(void*)(long)(priv != 0)" ?

TIA

Regards,
Seenu.

Note: Even though this code is not existing in the current kernel, it
was avlbl in 2.4.xx.

se*****@gmail.com said:
Hi All,
I found a piece of code in linux/kernel/signal.c:

int
send_sig(int sig, struct task_struct *p, int priv)
{
return send_sig_info(sig, (void*)(long)(priv != 0), p);
}
What is the meaning of "(void*)(long)(priv != 0)" ?

It means "warning! dodgy code! fix me!"

(priv != 0) yields a result that is either 0 or 1.
Casting this to (long) yields a value that is either 0L or 1L.
Casting to to (void *) yields a value that is very unlikely to be a valid
pointer to any object or function.

Stupid stupid stupid.

Note: Even though this code is not existing in the current kernel, it
was avlbl in 2.4.xx.

So what you''re saying, then, is that someone came to their senses and
ripped it out. Good!

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


On Dec 5, 12:33 am, seen...@gmail.com wrote:
Hi All,
I found a piece of code in linux/kernel/signal.c:

int
send_sig(int sig, struct task_struct *p, int priv)
{
return send_sig_info(sig, (void*)(long)(priv != 0), p);

}

What is the meaning of "(void*)(long)(priv != 0)" ?

TIA

The second parameter has the type struct siginfo*. A NULL (0) pointer
here means a user kill sig. The special reserved pointer (struct
siginfo*)1 is for kernel sigs. (priv != 0) has value 0 if priv is 0
and 1 otherwise. The casts coerce this int value to a compatible
pointer. The effect is that privilege level 0 causes a user sig and
all others a kernel sig. It''s not clear to me why (void*)(long) is
used instead of (struct siginfo*), but the effect ought to be the
same.


Richard Heathfield wrote:
se*****@gmail.com said:
>Hi All,
I found a piece of code in linux/kernel/signal.c:

int
send_sig(int sig, struct task_struct *p, int priv)
{
return send_sig_info(sig, (void*)(long)(priv != 0), p);
}
What is the meaning of "(void*)(long)(priv != 0)" ?


It means "warning! dodgy code! fix me!"

(priv != 0) yields a result that is either 0 or 1.
Casting this to (long) yields a value that is either 0L or 1L.
Casting to to (void *) yields a value that is very unlikely to be a valid
pointer to any object or function.

Stupid stupid stupid.

To be fair, code found in linux/kernel/anything is unlikely to be written
in portable standard C and may be permitted to exploit implementation-
specific details. (The casting looks bizarre, but for all we know, it
could be avoiding an implementation-specific bug.)

As you know, Bob, the standard doesn''t stop you from relying on
implementation details; it just doesn''t define what happens if you
do. Sometimes this is a Good Thing.

--
Chris "it only /looks/ like C" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England