1 Star2 Stars3 Stars4 Stars5 Stars (还没有评分)
Loading...

DTrace tricks and tips (4) – copyin()函数不是跨clause安全的

Max Burning的这篇文章:《Bruning Questions: How To DTrace poll(2) System Calls》(http://www.joyent.com/blog/bruning-questions-how-to-dtrace-poll-2-system-calls)归根到底的结论就是:copyin()函数所返回的内存空间只在当前clause有效,不能跨clause使用(“copyin() data goes into scratch space which is not saved across clauses.”)。
所以针对下面的代码:

pid$target::foo:entry
{
    this->count = arg1;
    this->data = (Data*)copyin(arg2, sizeof(Data));
}

pid$target::foo:entry
/* this->count > 0 */
{
    this->count--;
    this->data = (Data*)copyin(arg2, sizeof(Data));
}

尽管是同一个probe,但是由于是两个clause,所以每次都要重新copyin。
这个问题在2009年的dtrace discussion mailing里就讨论过,有兴趣的同学可以参考这个链接:http://thr3ads.net/dtrace-discuss/2009/09/1131448-this-variables-being-overridden

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.