1 |
/** |
2 |
* memcheck.C: Invoke valgrind's memcheck while running. |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
10 |
* Rights to this code are as documented in doc/pod/gplicense.pod. |
11 |
* |
12 |
* $Id: memcheck.C,v 1.5 2007-09-16 18:54:44 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
|
18 |
#ifdef HAVE_VALGRIND_MEMCHECK_H |
19 |
#include <valgrind/memcheck.h> |
20 |
#endif |
21 |
|
22 |
static char const rcsid[] = "$Id: memcheck.C,v 1.5 2007-09-16 18:54:44 pippijn Exp $"; |
23 |
|
24 |
REGISTER_MODULE ("operserv/memcheck", false, "The Ermyth Team <http://ermyth.one09.net>"); |
25 |
|
26 |
#ifdef HAVE_VALGRIND_MEMCHECK_H |
27 |
static void |
28 |
os_cmd_memcheck (sourceinfo_t *si, int parc, char *parv[]) |
29 |
{ |
30 |
#ifdef __x86_64__ |
31 |
{ |
32 |
unsigned int _qzz_res; |
33 |
{ |
34 |
volatile unsigned long int _zzq_args[6]; |
35 |
volatile unsigned long int _zzq_result; |
36 |
_zzq_args[0] = (unsigned long int)(VG_USERREQ__DO_LEAK_CHECK); |
37 |
_zzq_args[1] = (unsigned long int)(0); |
38 |
_zzq_args[2] = (unsigned long int)(0); |
39 |
_zzq_args[3] = (unsigned long int)(0); |
40 |
_zzq_args[4] = (unsigned long int)(0); |
41 |
_zzq_args[5] = (unsigned long int)(0); |
42 |
__asm__ volatile ("rolq $3, %%rdi ; rolq $13, %%rdi\n\t" |
43 |
"rolq $61, %%rdi ; rolq $51, %%rdi\n\t" |
44 |
"xchgq %%rbx,%%rbx" |
45 |
: "=d" (_zzq_result) |
46 |
: "a" (&_zzq_args[0]), "0" (0) |
47 |
: "cc", "memory" ); |
48 |
_qzz_res = _zzq_result; |
49 |
} |
50 |
} |
51 |
#else |
52 |
VALGRIND_DO_LEAK_CHECK; |
53 |
#endif |
54 |
command_success_nodata (si, "Valgrind memcheck invoked."); |
55 |
return; |
56 |
} |
57 |
|
58 |
command_t const os_memcheck = { "MEMCHECK", N_("Invokes the valgrind memcheck."), AC_NONE, 0, os_cmd_memcheck }; |
59 |
|
60 |
E cmdvec os_cmdtree; |
61 |
E helpvec os_helptree; |
62 |
#endif |
63 |
|
64 |
bool |
65 |
_modinit (module *m) |
66 |
{ |
67 |
#ifdef HAVE_VALGRIND_MEMCHECK_H |
68 |
os_cmdtree << os_memcheck; |
69 |
help_addentry (os_helptree, "MEMCHECK", "help/operserv/memcheck", NULL); |
70 |
#endif |
71 |
|
72 |
return true; |
73 |
} |
74 |
|
75 |
void |
76 |
_moddeinit () |
77 |
{ |
78 |
#ifdef HAVE_VALGRIND_MEMCHECK_H |
79 |
os_cmdtree >> os_memcheck; |
80 |
help_delentry (os_helptree, "MEMCHECK"); |
81 |
#endif |
82 |
} |