开发者

Does valgrind track memory initialization through drivers?

开发者 https://www.devze.com 2023-01-07 13:27 出处:网络
valgrind is reporting uninitialized memory errors from code like this: unsigned char buf[100]; struct driver_command cmd;

valgrind is reporting uninitialized memory errors from code like this:

unsigned char buf[100];
struct driver_command cmd;
cmd.len = sizeof(buf);
cmd.buf = buf;
ioctl(my_driver_fd, READ, &cmd);

for(i = 0; i < sizeof(buf); i++)
{
    foo(buf[i]); /* <<--- uninit use error from valgrind */
}

If I memset() the buf before the driver call, the error goes away.

Can valgrind detect whether the linux driver is properly writing to the buffer? (I looked at the driver code, and it seems to be correct, but maybe I'm missing something.)

Or does it j开发者_运维技巧ust pass the driver call through and has no way of knowing that the buffer has been written inside the kernel?

Thanks.


Valgrind obviously can't trace execution into the kernel, but it does know the visible semantics of most system calls. But ioctl is too unpredictable. If you had coded your driver so that that was a read call, it would get it right. That's better practice anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消