]> Joshua Wise's Git repositories - netwatch.git/blobdiff - net/http/fs.c
some changes for gcc4
[netwatch.git] / net / http / fs.c
index 9e6358d627632bbef54410f5047402402164764a..0bf11cb9c97a2440a8e2a5ad85e357a3fa266774 100644 (file)
 #include "fs.h"
 #include "fsdata.h"
 #include "fsdata.c"
+#include <io.h>
+#include <minilib.h>
+#include <paging.h>
+#include <output.h>
 
 /*-----------------------------------------------------------------------------------*/
 
-void fill_regs(struct fs_file *file)
+void handle_regs(struct fs_file *file)
 {
-  static unsigned char buf[2048];
+  static char buf[2048];
   
   sprintf(buf,
     "<html><head><title>Registers</title></head><body>"
@@ -63,7 +67,58 @@ void fill_regs(struct fs_file *file)
     
   
   file->data = buf;
-  file->len = strlen(buf);
+  file->len = strlen(buf)-1;
+}
+
+void handle_backtrace(struct fs_file *file)
+{
+  static char buf[2048];
+  static char buf2[64];
+  int i = 10;
+  unsigned long *pebp, *peip;
+  unsigned long ebp;
+  unsigned long cr3;
+  
+  strcpy(buf, "<html><head><title>Backtrace</title></head><body><tt><pre>");
+  ebp = *(unsigned long *)0xAFFE4;
+  cr3 = *(unsigned long *)0xAFFF8;
+  
+  sprintf(buf2, "0x%08x, from\n", *(unsigned long*)0xAFFF0);
+  strcat(buf, buf2);
+  
+  /* I never thought I'd do this again. */
+  while ((peip = demap(cr3, ebp+4)) != 0x0 && i--)
+  {
+    sprintf(buf2, "0x%08x, from\n", *peip);
+    strcat(buf, buf2);
+    pebp = demap(cr3, ebp);
+    if (!pebp)
+    {
+      strcat(buf, "&lt;unreadable %ebp&gt;\n");
+      break;
+    }
+    if (ebp >= *pebp && *pebp)
+    {
+      strcat(buf, "&lt;recursive %ebp&gt;\n");
+      break;
+    }
+    ebp = *pebp;
+  }
+  if (i == -1)
+    strcat(buf, "...\n");
+  else
+    strcat(buf, "&lt;root&gt;");
+  strcat(buf, "</pre></tt></body></html>");
+  
+  file->data = buf;
+  file->len = strlen(buf)-1;
+}
+
+void handle_reboot(struct fs_file *file)
+{
+  outb(0xCF9, 0x4);
+  file->data = "So long!";
+  file->len = 8;
 }
 
 
@@ -76,7 +131,17 @@ fs_open(const char *name, struct fs_file *file)
   /* /registers.html is CGI */
   if (!strcmp(name, "/registers.html"))
   {
-    fill_regs(file);
+    handle_regs(file);
+    return 1;
+  }
+  if (!strcmp(name, "/backtrace.html"))
+  {
+    handle_backtrace(file);
+    return 1;
+  }
+  if (!strcmp(name, "/reboot"))
+  {
+    handle_reboot(file);
     return 1;
   }
 
@@ -85,7 +150,7 @@ fs_open(const char *name, struct fs_file *file)
       f = f->next) {
     if (!strcmp(name, (const char*)f->name)) {
       file->data = f->data;
-      file->len = f->len;
+      file->len = f->len-1;
       return 1;
     }
   }
This page took 0.025089 seconds and 4 git commands to generate.