X-Git-Url: http://git.joshuawise.com/netwatch.git/blobdiff_plain/6f9272bdabcda81425ec1aaecf26a160535d4749..3368351a230f70d5daf36464b2a473e4a8c74c8a:/net/http/fs.c?ds=inline diff --git a/net/http/fs.c b/net/http/fs.c index 9e6358d..832d3dd 100644 --- a/net/http/fs.c +++ b/net/http/fs.c @@ -33,37 +33,106 @@ #include "fs.h" #include "fsdata.h" #include "fsdata.c" +#include +#include +#include +#include +#include +#include + +static char http_output_buffer[1280]; /*-----------------------------------------------------------------------------------*/ -void fill_regs(struct fs_file *file) +void handle_regs(struct fs_file *file) +{ + int i; + int len; + + len = snprintf(http_output_buffer, sizeof(http_output_buffer), "
");
+
+  for (i = 0; i < NUM_REGISTERS; i++) {
+    len += state_dump_reg(http_output_buffer + len, sizeof(http_output_buffer) - len, i);
+  }
+
+  file->len = len;
+  file->data = http_output_buffer;
+}
+
+#define LEFT (sizeof(http_output_buffer) - len)
+
+void handle_backtrace(struct fs_file *file)
 {
-  static unsigned char buf[2048];
+  int i = 10;
+  int len;
+  void *pebp, *peip;
+  uint64_t bp, next;
+
+  int longmode = (get_operating_mode() == LONG_64BIT);
+
+  char * buf = http_output_buffer;
+  
+  strcpy(buf, "Backtrace
");
+  len = strlen(buf);
+
+  bp = state_get_reg(STATE_REG_RIP);
+
+  if (longmode)
+    len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(bp >> 32), (uint32_t)bp);
+  else
+    len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)bp);
   
-  sprintf(buf,
-    "Registers"
-    "

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

" - "
"
-    "%%eax: 0x%08x    %%ebx: 0x%08x    %%ecx: 0x%08x    %%edx: 0x%08x\n"
-    "%%ebp: 0x%08x    %%esi: 0x%08x    %%edi: 0x%08x    %%esp: 0x%08x\n"
-    "%%cr0: 0x%08x    %%cr3: 0x%08x    %%eip: 0x%08x    %%eflags: 0x%08x\n"
-    "
", - *(unsigned long*)0xAFFD0, - *(unsigned long*)0xAFFDC, - *(unsigned long*)0xAFFD4, - *(unsigned long*)0xAFFD8, - *(unsigned long*)0xAFFE4, - *(unsigned long*)0xAFFE8, - *(unsigned long*)0xAFFEC, - *(unsigned long*)0xAFFE0, - *(unsigned long*)0xAFFFC, - *(unsigned long*)0xAFFF8, - *(unsigned long*)0xAFFF0, - *(unsigned long*)0xAFFF4); - + bp = state_get_reg(STATE_REG_RBP); + + /* I never thought I'd do this again. */ + while ((peip = demap(bp+(longmode?8:4))) != 0x0 && i--) + { + if (longmode) { + next = *(uint64_t *)peip; + len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(next >> 32), (uint32_t)next); + } else { + next = *(uint32_t *)peip; + len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)next); + } + + pebp = demap(bp); + + if (!pebp) + { + len += snprintf(buf + len, LEFT, "<unreadable frame>\n"); + break; + } + + if (longmode) + next = *(uint64_t *)pebp; + else + next = *(uint32_t *)pebp; + + if (bp >= next && next) + { + len += snprintf(buf + len, LEFT, "<recursive frame>\n"); + break; + } + + bp = next; + } + + 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 +145,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 +164,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; } }