Crash.cc

Go to the documentation of this file.
00001 //
00002 // Copyright 2002,2003 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 
00012 #include <iostream>
00013 using std::cin;
00014 using std::cout;
00015 #include <OPENR/OSyslog.h>
00016 #include "Crash.h"
00017 
00018 void access_null_data_pointer()
00019 {
00020     int *a = 0;
00021     OSYSPRINT(("*a is %d\n", *a)); // !!! EXCEPTION !!!
00022 }
00023 
00024 void access_null_text_pointer()
00025 {
00026     void (*null_func_pointer)(void) = 0;
00027     null_func_pointer(); // !!! EXCEPTION !!!
00028 }
00029 
00030 void destroy_stack()
00031 {
00032     char array_in_stack[10];
00033     strcpy(array_in_stack, "Length of this string is longer than 10.");
00034     return; // !!! EXCEPTION !!!
00035 }
00036 
00037 struct sample_struct {
00038     short a;
00039     char b[4];
00040 };
00041 
00042 void cause_address_miss_alignment()
00043 {
00044     sample_struct ss;
00045     char data[] = "123";
00046     ss.a = 1;
00047     *(unsigned int *)ss.b = *(unsigned int *)data; // !!! EXCEPTION !!!
00048     OSYSPRINT(("ss.a is %d, ss.b is %s\n", ss.a, ss.b));
00049 }
00050 
00051 void use_unusable_coprocessor()
00052 {
00053     asm("mfc0 $2, $12");
00054 }
00055 
00056 static uint32 broken_text[] = {
00057     0x00000000, // nop
00058     0x0000003d,
00059     0x03e00008, // jr r31
00060     0x00000000, // nop
00061 };
00062 
00063 void jump_to_broken_text()
00064 {
00065     void (*func_pointer)() = (void (*)())broken_text;
00066     func_pointer(); // !!! EXCEPTION !!!
00067 }
00068 
00069 void cause_tlb_modification_error()
00070 {
00071     MemoryRegionID memid;
00072     unsigned char *addr;
00073     sError ans;
00074     ans = NewSharedMemoryRegion(4096, MEMPROTINFO_R, &memid, (void**)&addr);
00075     if (ans != sSUCCESS) {
00076         printf("test failed!\n");
00077         return;
00078     }
00079     *addr = 0x1; // !!! EXCEPTION !!!
00080     DeleteSharedMemoryRegion(memid);
00081 }
00082 
00083 void overflow_on_convert()
00084 {
00085     float a = (float) 0xffffffff;
00086     for (int i = 0; i < 20; i++) {
00087         a *= 2.0;
00088         OSYSPRINT(("a is %ud\n", (unsigned int) a)); // !!! EXCEPTION !!!
00089     }
00090 }
00091 
00092 void not_a_number_source()
00093 {
00094     float a = 0.0 / 0.0;
00095     for (int i = 0; i < 20; i++) {
00096         a *= 3.0; // !!! EXCEPTION !!!
00097         OSYSPRINT(("a is %f\n", a));
00098     }
00099 }
00100 
00101 float denormalized_number_source_body(float a)
00102 {
00103     return a * 3.0;
00104 }
00105 
00106 void denormalized_number_source()
00107 {
00108     float a = 1.0e-37 / 100.0;
00109     float b = denormalized_number_source_body(a); // !!! EXCEPTION !!!
00110     OSYSPRINT(("a * 3.0: %e\n", b));
00111 }
00112 
00113 struct crash_func_entry {
00114     void (*func)();
00115     const char *help;
00116 };
00117 
00118 crash_func_entry crash_func_table[] = {
00119     { access_null_data_pointer, "access null data pointer" },
00120     { access_null_text_pointer, "access null text pointer" },
00121     { destroy_stack, "destroy stack" },
00122     { cause_address_miss_alignment, "cause address miss alignment" },
00123     { use_unusable_coprocessor, "use unusable coprocessor" },
00124     { jump_to_broken_text, "jump to broken text" },
00125     { cause_tlb_modification_error,
00126       "cause TLB modification error (memprot only)" },
00127     { overflow_on_convert, "overflow on convert" },
00128     { not_a_number_source, "use not-a-number source" },
00129     { denormalized_number_source, "use denormalized number source" },
00130 };
00131 
00132 Crash::Crash ()
00133 {
00134 }
00135 
00136 OStatus
00137 Crash::DoInit(const OSystemEvent& event)
00138 {
00139     return oSUCCESS;
00140 }
00141 
00142 OStatus
00143 Crash::DoStart(const OSystemEvent& event)
00144 {
00145     OSYSPRINT(("\n=== Crash Menu ===\n"));
00146     uint32 crash_func_table_max =
00147         sizeof(crash_func_table) / sizeof(crash_func_entry);
00148     uint32 i;
00149     for (;;) {
00150         for (int j = 0; j < crash_func_table_max; j++) {
00151             OSYSPRINT((" %d. %s\n", j, crash_func_table[j].help));
00152         }
00153         cout << "\nselect: ";
00154         cin >> i;
00155         if (i < crash_func_table_max) {
00156             break;
00157         }
00158     }
00159     OSYSPRINT(("Crash ...\n"));
00160     crash_func_table[i].func();
00161 
00162     return oSUCCESS;
00163 }    
00164 
00165 OStatus
00166 Crash::DoStop(const OSystemEvent& event)
00167 {
00168     return oSUCCESS;
00169 }
00170 
00171 OStatus
00172 Crash::DoDestroy(const OSystemEvent& event)
00173 {
00174     return oSUCCESS;
00175 }

Generated on Sun Dec 2 23:04:28 2007 for openSDK by  doxygen 1.3.9.1