X-Git-Url: http://git.joshuawise.com/netwatch.git/blobdiff_plain/6f9272bdabcda81425ec1aaecf26a160535d4749..db9fad13f192963786c7ac90d305467ac00bd145:/net/http/fs.c?ds=sidebyside diff --git a/net/http/fs.c b/net/http/fs.c index 9e6358d..4fe2c41 100644 --- a/net/http/fs.c +++ b/net/http/fs.c @@ -33,14 +33,18 @@ #include "fs.h" #include "fsdata.h" #include "fsdata.c" +#include +#include +#include +#include + +static char http_output_buffer[1024]; /*-----------------------------------------------------------------------------------*/ -void fill_regs(struct fs_file *file) +void handle_regs(struct fs_file *file) { - static unsigned char buf[2048]; - - sprintf(buf, + file->len = snprintf(http_output_buffer, sizeof(http_output_buffer), "Registers" "

At the time you requested this page, the system's registers were:

" "
"
@@ -60,10 +64,64 @@ void fill_regs(struct fs_file *file)
     *(unsigned long*)0xAFFF8,
     *(unsigned long*)0xAFFF0,
     *(unsigned long*)0xAFFF4);
-    
+  
+  file->data = http_output_buffer;
+}
+
+#define LEFT (sizeof(http_output_buffer) - len)
+
+void handle_backtrace(struct fs_file *file)
+{
+  int i = 10;
+  int len;
+  unsigned long *pebp, *peip;
+  unsigned long ebp;
+  unsigned long cr3;
+
+  char * buf = http_output_buffer;
+  
+  strcpy(buf, "Backtrace
");
+  len = strlen(buf);
+  ebp = *(unsigned long *)0xAFFE4;
+  cr3 = *(unsigned long *)0xAFFF8;
+  
+  len += snprintf(buf + len, LEFT, "0x%08x, from\n", *(unsigned long*)0xAFFF0);
+  
+  /* I never thought I'd do this again. */
+  while ((peip = demap(cr3, ebp+4)) != 0x0 && i--)
+  {
+    len += snprintf(buf + len, LEFT, "0x%08x, from\n", *peip);
+
+    pebp = demap(cr3, ebp);
+    if (!pebp)
+    {
+      len += snprintf(buf + len, LEFT, "<unreadable %ebp>\n");
+      break;
+    }
+    if (ebp >= *pebp && *pebp)
+    {
+      len += snprintf(buf + len, LEFT, "<recursive %ebp>\n");
+      break;
+    }
+    ebp = *pebp;
+  }
+
+  if (i == -1)
+    len += snprintf(buf + len, LEFT, "...\n");
+  else
+    len += snprintf(buf + len, LEFT, "<root>");
+
+  len += snprintf(buf + len, LEFT, "
"); file->data = buf; - file->len = strlen(buf); + file->len = len; +} + +void handle_reboot(struct fs_file *file) +{ + outb(0xCF9, 0x4); + file->data = "So long!"; + file->len = 8; } @@ -76,7 +134,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 +153,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; } }