--- valgrind-3.9.0/include/valgrind.h	2013-10-23 12:49:54.000000000 +0200
+++ valgrind-edupuis/include/valgrind.h	2014-08-08 15:25:53.695988496 +0200
@@ -4940,8 +4940,9 @@
    which use client requests.  DO NOT CHANGE THE ORDER OF THESE
    ENTRIES, NOR DELETE ANY -- add new ones at the end. */
 typedef
-   enum { VG_USERREQ__RUNNING_ON_VALGRIND  = 0x1001,
-          VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002,
+   enum { VG_USERREQ__RUNNING_ON_VALGRIND      = 0x1001,
+          VG_USERREQ__DISCARD_TRANSLATIONS     = 0x1002,
+          VG_USERREQ__VALGRIND_RUNNING_VERSION = 0x1003,
 
           /* These allow any function to be called from the simulated
              CPU but run on the real CPU.  Nb: the first arg passed to
@@ -5036,6 +5037,15 @@
                                     _qzz_addr, _qzz_len, 0, 0, 0)
 
 
+/* Returns the current Valgrind version this code is running under. 
+   Returns 0 if not running on Valgrind. Version number is expressed on
+   two bytes, i.e. 0x00000309 stands for Valgrind 3.9. */
+#define VALGRIND_RUNNING_VERSION                                           \
+    (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* if not */,              \
+                                    VG_USERREQ__VALGRIND_RUNNING_VERSION,  \
+                                    0, 0, 0, 0, 0)                         \
+
+
 /* These requests are for getting Valgrind itself to print something.
    Possibly with a backtrace.  This is a really ugly hack.  The return value
    is the number of characters printed, excluding the "**<pid>** " part at the
--- valgrind-3.9.0/coregrind/m_scheduler/scheduler.c	2013-10-23 12:50:12.000000000 +0200
+++ valgrind-edupuis/coregrind/m_scheduler/scheduler.c	2014-08-08 15:30:10.775988465 +0200
@@ -1780,6 +1780,10 @@
       case VG_USERREQ__RUNNING_ON_VALGRIND:
          SET_CLREQ_RETVAL(tid, RUNNING_ON_VALGRIND+1);
          break;
+         
+      case VG_USERREQ__VALGRIND_RUNNING_VERSION:
+         SET_CLREQ_RETVAL(tid, (__VALGRIND_MAJOR__ << 8) | (__VALGRIND_MINOR__));
+         break;
 
       case VG_USERREQ__PRINTF: {
          const HChar* format = (HChar *)arg[1];
--- valgrind-3.9.0/docs/xml/manual-core-adv.xml	2013-10-23 12:49:57.000000000 +0200
+++ valgrind-edupuis/docs/xml/manual-core-adv.xml	2014-08-08 15:32:26.007988449 +0200
@@ -114,6 +114,16 @@
   </varlistentry>
 
   <varlistentry>
+   <term><command><computeroutput>VALGRIND_RUNNING_VERSION</computeroutput></command>:</term>
+   <listitem>
+    <para>Returns current Valgrind version if running on Valgrind, 0 
+    otherwise. The version number is expressed on two bytes. For example
+    0x00000309 is returned for Valgrind 3.9.
+    </para>
+   </listitem>
+  </varlistentry>
+
+  <varlistentry>
    <term><command><computeroutput>VALGRIND_COUNT_ERRORS</computeroutput>:</command></term>
    <listitem>
     <para>Returns the number of errors found so far by Valgrind.  Can be
