summaryrefslogtreecommitdiff
path: root/community/gsoc/project_ideas/valgrind.mdwn
blob: 76675796caa858fe525832a590d9e02fc3a68398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
[[!meta copyright="Copyright © 2009, 2010, 2011 Free Software Foundation,
Inc."]]

[[!meta license="""[[!toggle id="license" text="GFDL 1.2+"]][[!toggleable
id="license" text="Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no Invariant
Sections, no Front-Cover Texts, and no Back-Cover Texts.  A copy of the license
is included in the section entitled [[GNU Free Documentation
License|/fdl]]."]]"""]]

[[!meta title="Porting Valgrind to the Hurd"]]

[[!tag open_issue_gnumach open_issue_hurd]]

[Valgrind](http://valgrind.org/) is an extremely useful debugging tool for memory errors.
(And some other kinds of hard-to-find errors too.)
Aside from being useful for program development in general,
a Hurd port will help finding out why certain programs segfault on the Hurd,
although they work on Linux.
Even more importantly, it will help finding bugs in the Hurd servers themselfs.

To keep track of memory use,
Valgrind however needs to know how each [[system call]] affects the validity of memory regions.
This knowledge is highly kernel-specific,
and thus Valgrind needs to be explicitely ported for every system.

Such a port involves two major steps:
making Valgrind understand how kernel traps work in general on the system in question;
and how all the individual kernel calls affect memory.
The latter step is where most of the work is,
as the behaviour of each single [[system call]] needs to be described.

Compared to Linux,
[[microkernel/Mach]] (the microkernel used by the Hurd) has very few kernel traps.
Almost all [[system call]]s are implemented as [[RPC]]s instead --
either handled by Mach itself, or by the various [[Hurd servers|hurd/translator]].
All RPCs use a pair of `mach_msg()` invocations:
one to send a request message, and one to receive a reply.
However, while all RPCs use the same `mach_msg()` trap,
the actual effect of the call varies greatly depending on which RPC is invoked --
similar to the `ioctl()` call on Linux.
Each request thus must be handled individually.

Unlike `ioctl()`,
the RPC invocations have explicit type information for the parameters though,
which can be retrieved from the message header.
By analyzing the parameters of the RPC reply message,
Valgrind can know exactly which memory regions are affected by that call,
even without specific knowledge of the RPC in question.
Thus implementing a general parser for the reply messages
will already give Valgrind a fairly good approximation of memory validity --
without having to specify the exact semantic of each RPC by hand.

While this should make Valgrind quite usable on the Hurd already, it's not perfect:
some RPCs might return a buffer that is only partially filled with valid data;
or some reply parameters might be optional,
and only contain valid data under certain conditions.
Such specific semantics can't be deduced from the message headers alone.
Thus for a complete port,
it will still be necessary to go through the list of all known RPCs,
and implement special handling in Valgrind for those RPCs that need it.
Reading the source code of the rpctrace tool would probably be useful to
understand how the RPC message can be parsed.

The goal of this task is at minimum to make Valgrind grok Mach traps,
and to implement the generic RPC handler.
Ideally, specific handling for RPCs needing it should also be implemented.

Completing this project will require digging into Valgrind's handling of [[system call]]s,
and into Hurd RPCs.
It is not an easy task, but a fairly predictable one --
there shouldn't be any unexpected difficulties,
and no major design work is necessary.
It doesn't require any specific previous knowledge:
only good programming skills in general.
On the other hand,
the student will obtain a good understanding of Hurd RPCs while working on this task,
and thus perfect qualifications for Hurd development in general :-)

Possible mentors: Samuel Thibault (youpi)

Exercise: As a starter,
students can try to teach valgrind a couple of Linux ioctls,
as this will make them learn how to use the read/write primitives of valgrind.