5. README_MISSING_SYSCALL_OR_IOCTL
Dealing with missing system call or ioctl wrappers in Valgrind
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You’re probably reading this because Valgrind bombed out whilst
running your program, and advised you to read this file.
The good
news is that, in general, it’s easy to write the missing syscall or
ioctl wrappers you need, so that you can continue your debugging.
If
you send the resulting patches to me, then you’ll be doing a favour to
all future Valgrind users too.
Note that an "ioctl" is just a special kind of system call, really; so
there’s not a lot of need to distinguish them (at least conceptually)
in the discussion that follows.
All this machinery is in coregrind/m_syswrap.
What are syscall/ioctl wrappers?
What do they do?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Valgrind does what it does, in part, by keeping track of everything your
program does.
When a system call happens, for example a request to read
part of a file, control passes to the Linux kernel, which fulfills the
request, and returns control to your program.
The problem is that the
kernel will often change the status of some part of your program’s memory
as a result, and tools (instrumentation plug-ins) may need to know about
this.
Syscall and ioctl wrappers have two jobs:
1. Tell a tool what’s about to happen, before the syscall takes place.
A
tool could perform checks beforehand, eg. if memory about to be written
is actually writeable.
This part is useful, but not strictly
essential.
2. Tell a tool what just happened, after a syscall takes place.
This is
so it can update its view of the program’s state, eg. that memory has
just been written to.
This step is essential.
The "happenings" mostly involve reading/writing of memory.
So, let’s look at an example of a wrapper for a system call which
should be familiar to many Unix programmers.
The syscall wrapper for time()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The wrapper for the time system call looks like this:
PRE(sys_time)
{
76
Содержание Software
Страница 176: ...Valgrind FAQ Release 3 8 0 10 August 2012 Copyright 2000 2012 Valgrind Developers Email valgrind valgrind org ...
Страница 177: ...Valgrind FAQ Table of Contents Valgrind Frequently Asked Questions 1 ii ...
Страница 302: ...README mips based on newer GCC versions if possible 95 ...
Страница 303: ...GNU Licenses ...
Страница 304: ...GNU Licenses Table of Contents 1 The GNU General Public License 1 2 The GNU Free Documentation License 8 ii ...