459053
diff --git a/proc/sysinfo.c b/proc/sysinfo.c
459053
index 1435de1..1d2b8e2 100644
459053
--- a/proc/sysinfo.c
459053
+++ b/proc/sysinfo.c
459053
@@ -36,6 +36,9 @@
459053
 #include <netinet/in.h>  /* htons */
459053
 #endif
459053
 
459053
+#include <link.h>
459053
+#include <elf.h>
459053
+
459053
 long smp_num_cpus;     /* number of CPUs */
459053
 long page_bytes;       /* this architecture's page size */
459053
 
459053
@@ -249,15 +252,67 @@ static void old_Hertz_hack(void){
459053
 
459053
 extern char** environ;
459053
 
459053
-/* for ELF executables, notes are pushed before environment and args */
459053
-static unsigned long find_elf_note(unsigned long findme){
459053
+static unsigned long find_elf_note(unsigned long type)
459053
+{
459053
+  ElfW(auxv_t) auxv_struct;
459053
+  ElfW(auxv_t) *auxv_temp;
459053
+  FILE *fd;
459053
+  int i;
459053
+  static ElfW(auxv_t) *auxv = NULL;
459053
   unsigned long *ep = (unsigned long *)environ;
459053
-  while(*ep++);
459053
-  while(*ep){
459053
-    if(ep[0]==findme) return ep[1];
459053
-    ep+=2;
459053
+  unsigned long ret_val = NOTE_NOT_FOUND;
459053
+
459053
+
459053
+  if(!auxv) {
459053
+
459053
+    fd = fopen("/proc/self/auxv", "rb");
459053
+
459053
+    if(!fd) {  // can't open auxv? that could be caused by euid change
459053
+               // ... and we need to fall back to the old and unsafe
459053
+               // ... method that doesn't work when calling library
459053
+               // ... functions with dlopen -> FIXME :(
459053
+
459053
+      while(*ep++);  // for ELF executables, notes are pushed
459053
+      while(*ep){    // ... before environment and args
459053
+        if(ep[0]==type) return ep[1];
459053
+        ep+=2;
459053
+      }
459053
+      return NOTE_NOT_FOUND;
459053
+    }
459053
+
459053
+    auxv = (ElfW(auxv_t) *) malloc(getpagesize());
459053
+    if (!auxv) {
459053
+      perror("malloc");
459053
+      exit(EXIT_FAILURE);
459053
+    }
459053
+
459053
+    i = 0;
459053
+    do {
459053
+      fread(&auxv_struct, sizeof(ElfW(auxv_t)), 1, fd);
459053
+      auxv[i] = auxv_struct;
459053
+      i++;
459053
+    } while (auxv_struct.a_type != AT_NULL);
459053
+
459053
+    fclose(fd);
459053
+
459053
+  }
459053
+
459053
+  auxv_temp = auxv;
459053
+  i = 0;
459053
+  do {
459053
+    if(auxv_temp[i].a_type == type) {
459053
+      ret_val = (unsigned long)auxv_temp[i].a_un.a_val;
459053
+      break;
459053
+    }
459053
+    i++;
459053
+  } while (auxv_temp[i].a_type != AT_NULL);
459053
+
459053
+  if (auxv){
459053
+	  auxv_temp = NULL;
459053
+	  free(auxv);
459053
+	  auxv = NULL;
459053
   }
459053
-  return NOTE_NOT_FOUND;
459053
+  return ret_val;
459053
 }
459053
 
459053
 int have_privs;