int main () { /* Test whether the OS handles some faults by itself. */ if (open (null_pointer, O_RDONLY) != -1 || errno != EFAULT) { fprintf (stderr, "EFAULT not detected alone.\n"); exit (1); } /* Install the SIGSEGV handler. */ if (sigsegv_install_handler (&handler) < 0) exit (2); /* Test that the library does not interfere with OS faults. */ if (open (null_pointer, O_RDONLY) != -1 || errno != EFAULT) { fprintf (stderr, "EFAULT not detected with handler.\n"); exit (1); } /* Test passed! */ printf ("Test passed.\n"); return 0; }
int main(int argc, char *argv[]) { int ret; ret = stackoverflow_install_handler(overflow_handler, alternate_signal_stack.buffer, sizeof alternate_signal_stack.buffer); if (ret) err("stackoverflow_install_handler() failed"); ret = sigsegv_install_handler(segv_handler); if (ret) err("sigsegv_install_handler() failed"); WRITE("starting overflow ... "); recursive(argc); return 0; }
int main(int argc, void* argv) { sigset_t emptyset; // sigsegv_init(&ss_dispatcher); sigsegv_install_handler(ss_handler); /* Save the current signal mask. */ sigemptyset (&emptyset); sigprocmask (SIG_BLOCK, &emptyset, &mainsigset); enable_memory_block(&Vm_image_start, &Vm_image_end); process_opts(argc,argv); install_exception_handler(kernel_exception_handler); if ( opts.image_file != 0 ) load_image(opts.image_file); run_repl(); return 0; }
//volatile void *thread_stacks[THREAD_STACKS]; //volatile int void _init_thread_context(unsigned int id, struct hashtable *h){ memset(&_thread_key,0,sizeof(struct _ThreadKey)); // create hashtable if there is not one specified /* if(!h) { // main thread int i; for(i=0;i< THREAD_STACKS;i++) { thread_stacks[i] = 0; } }*/ _thread_key.h = h?h:create_hashtable(25); _thread_key.tid = id; // install stack overflow handler /* if(stackoverflow_install_handler (&_exn_stackoverflow_handler, __backup__stack,BACKUP_STK_SZ) < 0) errquit("Could not install stack handler");*/ // instacl seg fault handler sigsegv_install_handler(&_exn_segv_handler); }
int main(int argc, char **argv) { char str[256]; int16 i16; HANDLE rom_fh; const char *rom_path; uint32 rom_size; DWORD actual; uint8 *rom_tmp; // Initialize variables RAMBase = 0; // Print some info printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR); printf(" %s\n", GetString(STR_ABOUT_TEXT2)); // Read preferences PrefsInit(NULL, argc, argv); // Parse command line arguments for (int i=1; i<argc; i++) { if (strcmp(argv[i], "--help") == 0) { usage(argv[0]); } else if (argv[i][0] == '-') { fprintf(stderr, "Unrecognized option '%s'\n", argv[i]); usage(argv[0]); } } // Check we are using a Windows NT kernel >= 4.0 OSVERSIONINFO osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx(&osvi)) { ErrorAlert("Could not determine OS type"); QuitEmulator(); } win_os = osvi.dwPlatformId; win_os_major = osvi.dwMajorVersion; if (win_os != VER_PLATFORM_WIN32_NT || win_os_major < 4) { ErrorAlert(GetString(STR_NO_WIN32_NT_4)); QuitEmulator(); } // Check that drivers are installed if (!check_drivers()) QuitEmulator(); // Load win32 libraries KernelInit(); // FIXME: default to DIB driver if (getenv("SDL_VIDEODRIVER") == NULL) putenv("SDL_VIDEODRIVER=windib"); // Initialize SDL system int sdl_flags = 0; #ifdef USE_SDL_VIDEO sdl_flags |= SDL_INIT_VIDEO; #endif #ifdef USE_SDL_AUDIO sdl_flags |= SDL_INIT_AUDIO; #endif assert(sdl_flags != 0); if (SDL_Init(sdl_flags) == -1) { char str[256]; sprintf(str, "Could not initialize SDL: %s.\n", SDL_GetError()); ErrorAlert(str); goto quit; } atexit(SDL_Quit); #ifdef ENABLE_MON // Initialize mon mon_init(); #endif // Install SIGSEGV handler for CPU emulator if (!sigsegv_install_handler(sigsegv_handler)) { sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); ErrorAlert(str); goto quit; } // Initialize VM system vm_init(); // Get system info PVR = 0x00040000; // Default: 604 CPUClockSpeed = 100000000; // Default: 100MHz BusClockSpeed = 100000000; // Default: 100MHz TimebaseSpeed = 25000000; // Default: 25MHz PVR = 0x000c0000; // Default: 7400 (with AltiVec) D(bug("PVR: %08x (assumed)\n", PVR)); // Init system routines SysInit(); // Show preferences editor if (!PrefsFindBool("nogui")) if (!PrefsEditor()) goto quit; // Create areas for Kernel Data if (!kernel_data_init()) goto quit; kernel_data = (KernelData *)Mac2HostAddr(KERNEL_DATA_BASE); emulator_data = &kernel_data->ed; KernelDataAddr = KERNEL_DATA_BASE; D(bug("Kernel Data at %p (%08x)\n", kernel_data, KERNEL_DATA_BASE)); D(bug("Emulator Data at %p (%08x)\n", emulator_data, KERNEL_DATA_BASE + offsetof(KernelData, ed))); // Create area for DR Cache if (vm_mac_acquire(DR_EMULATOR_BASE, DR_EMULATOR_SIZE) < 0) { sprintf(str, GetString(STR_DR_EMULATOR_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } dr_emulator_area_mapped = true; if (vm_mac_acquire(DR_CACHE_BASE, DR_CACHE_SIZE) < 0) { sprintf(str, GetString(STR_DR_CACHE_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } dr_cache_area_mapped = true; DRCacheAddr = (uint32)Mac2HostAddr(DR_CACHE_BASE); D(bug("DR Cache at %p (%08x)\n", DRCacheAddr, DR_CACHE_BASE)); // Create area for SheepShaver data if (!SheepMem::Init()) { sprintf(str, GetString(STR_SHEEP_MEM_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } // Create area for Mac ROM if (vm_mac_acquire(ROM_BASE, ROM_AREA_SIZE) < 0) { sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } ROMBase = ROM_BASE; ROMBaseHost = Mac2HostAddr(ROMBase); rom_area_mapped = true; D(bug("ROM area at %p (%08x)\n", ROMBaseHost, ROMBase)); // Create area for Mac RAM RAMSize = PrefsFindInt32("ramsize"); if (RAMSize < 8*1024*1024) { WarningAlert(GetString(STR_SMALL_RAM_WARN)); RAMSize = 8*1024*1024; } RAMBase = 0; if (vm_mac_acquire(RAMBase, RAMSize) < 0) { sprintf(str, GetString(STR_RAM_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } RAMBaseHost = Mac2HostAddr(RAMBase); ram_area_mapped = true; D(bug("RAM area at %p (%08x)\n", RAMBaseHost, RAMBase)); if (RAMBase > ROMBase) { ErrorAlert(GetString(STR_RAM_HIGHER_THAN_ROM_ERR)); goto quit; } // Load Mac ROM rom_path = PrefsFindString("rom"); rom_fh = CreateFile(rom_path && *rom_path ? rom_path : ROM_FILE_NAME, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (rom_fh == INVALID_HANDLE_VALUE) { rom_fh = CreateFile(ROM_FILE_NAME2, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (rom_fh == INVALID_HANDLE_VALUE) { ErrorAlert(GetString(STR_NO_ROM_FILE_ERR)); goto quit; } } printf(GetString(STR_READING_ROM_FILE)); rom_size = GetFileSize(rom_fh, NULL); rom_tmp = new uint8[ROM_SIZE]; ReadFile(rom_fh, (void *)rom_tmp, ROM_SIZE, &actual, NULL); CloseHandle(rom_fh); // Decode Mac ROM if (!DecodeROM(rom_tmp, actual)) { if (rom_size != 4*1024*1024) { ErrorAlert(GetString(STR_ROM_SIZE_ERR)); goto quit; } else { ErrorAlert(GetString(STR_ROM_FILE_READ_ERR)); goto quit; } } delete[] rom_tmp; // Initialize native timers timer_init(); // Initialize everything if (!InitAll(NULL)) goto quit; D(bug("Initialization complete\n")); // Write protect ROM vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ); // Start 60Hz thread tick_thread_cancel = false; tick_thread_active = ((tick_thread = create_thread(tick_func)) != NULL); SetThreadPriority(tick_thread, THREAD_PRIORITY_ABOVE_NORMAL); D(bug("Tick thread installed (%ld)\n", tick_thread)); // Start NVRAM watchdog thread memcpy(last_xpram, XPRAM, XPRAM_SIZE); nvram_thread_cancel = false; nvram_thread_active = ((nvram_thread = create_thread(nvram_func, NULL)) != NULL); SetThreadPriority(nvram_thread, THREAD_PRIORITY_BELOW_NORMAL); D(bug("NVRAM thread installed (%ld)\n", nvram_thread)); // Get my thread ID and jump to ROM boot routine emul_thread = GetCurrentThread(); D(bug("Jumping to ROM\n")); #ifdef _MSC_VER __try { #endif jump_to_rom(ROMBase + 0x310000); #ifdef _MSC_VER } __except (main_exception_filter(GetExceptionInformation())) {} #endif D(bug("Returned from ROM\n")); quit: Quit(); return 0; }
int main(int argc, char **argv) { /* * The + on the front tells GNU getopt not to rearrange argv. */ const char *optlist = "+F:f:v:W;m:bcCd::D::e:E:gh:i:l:L:nNo::Op::MPrStVY"; bool stopped_early = false; int old_optind; int i; int c; char *scan, *src; char *extra_stack; int have_srcfile = 0; SRCFILE *s; /* do these checks early */ if (getenv("TIDYMEM") != NULL) do_flags |= DO_TIDY_MEM; #ifdef HAVE_MCHECK_H #ifdef HAVE_MTRACE if (do_tidy_mem) mtrace(); #endif /* HAVE_MTRACE */ #endif /* HAVE_MCHECK_H */ #if defined(LC_CTYPE) setlocale(LC_CTYPE, ""); #endif #if defined(LC_COLLATE) setlocale(LC_COLLATE, ""); #endif #if defined(LC_MESSAGES) setlocale(LC_MESSAGES, ""); #endif #if defined(LC_NUMERIC) && defined(HAVE_LOCALE_H) /* * Force the issue here. According to POSIX 2001, decimal * point is used for parsing source code and for command-line * assignments and the locale value for processing input, * number to string conversion, and printing output. * * 10/2005 --- see below also; we now only use the locale's * decimal point if do_posix in effect. * * 9/2007: * This is a mess. We need to get the locale's numeric info for * the thousands separator for the %'d flag. */ setlocale(LC_NUMERIC, ""); init_locale(& loc); setlocale(LC_NUMERIC, "C"); #endif #if defined(LC_TIME) setlocale(LC_TIME, ""); #endif #if MBS_SUPPORT /* * In glibc, MB_CUR_MAX is actually a function. This value is * tested *a lot* in many speed-critical places in gawk. Caching * this value once makes a speed difference. */ gawk_mb_cur_max = MB_CUR_MAX; /* Without MBS_SUPPORT, gawk_mb_cur_max is 1. */ /* init the cache for checking bytes if they're characters */ init_btowc_cache(); #endif (void) bindtextdomain(PACKAGE, LOCALEDIR); (void) textdomain(PACKAGE); (void) signal(SIGFPE, catchsig); #ifdef SIGBUS (void) signal(SIGBUS, catchsig); #endif (void) sigsegv_install_handler(catchsegv); #define STACK_SIZE (16*1024) emalloc(extra_stack, char *, STACK_SIZE, "main"); (void) stackoverflow_install_handler(catchstackoverflow, extra_stack, STACK_SIZE); #undef STACK_SIZE myname = gawk_name(argv[0]); os_arg_fixup(&argc, &argv); /* emulate redirection, expand wildcards */ if (argc < 2) usage(EXIT_FAILURE, stderr); /* initialize the null string */ Nnull_string = make_string("", 0); /* Robustness: check that file descriptors 0, 1, 2 are open */ init_fds(); /* init array handling. */ array_init(); /* init the symbol tables */ init_symbol_table(); output_fp = stdout; /* we do error messages ourselves on invalid options */ opterr = false; /* copy argv before getopt gets to it; used to restart the debugger */ save_argv(argc, argv); /* initialize global (main) execution context */ push_context(new_context()); /* option processing. ready, set, go! */ for (optopt = 0, old_optind = 1; (c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF; optopt = 0, old_optind = optind) { if (do_posix) opterr = true; switch (c) { case 'F': add_preassign(PRE_ASSIGN_FS, optarg); break; case 'E': disallow_var_assigns = true; /* fall through */ case 'f': /* * Allow multiple -f options. * This makes function libraries real easy. * Most of the magic is in the scanner. * * The following is to allow for whitespace at the end * of a #! /bin/gawk line in an executable file */ scan = optarg; if (argv[optind-1] != optarg) while (isspace((unsigned char) *scan)) scan++; src = (*scan == '\0' ? argv[optind++] : optarg); (void) add_srcfile((src && src[0] == '-' && src[1] == '\0') ? SRC_STDIN : SRC_FILE, src, srcfiles, NULL, NULL); break; case 'v': add_preassign(PRE_ASSIGN, optarg); break; case 'm': /* * BWK awk extension. * -mf nnn set # fields, gawk ignores * -mr nnn set record length, ditto * * As of at least 10/2007, BWK awk also ignores it. */ if (do_lint) lintwarn(_("`-m[fr]' option irrelevant in gawk")); if (optarg[0] != 'r' && optarg[0] != 'f') warning(_("-m option usage: `-m[fr] nnn'")); break; case 'b': do_binary = true; break; case 'c': do_flags |= DO_TRADITIONAL; break; case 'C': copyleft(); break; case 'd': do_flags |= DO_DUMP_VARS; if (optarg != NULL && optarg[0] != '\0') varfile = optarg; break; case 'D': do_flags |= DO_DEBUG; if (optarg != NULL && optarg[0] != '\0') command_file = optarg; break; case 'e': if (optarg[0] == '\0') warning(_("empty argument to `-e/--source' ignored")); else (void) add_srcfile(SRC_CMDLINE, optarg, srcfiles, NULL, NULL); break; case 'g': do_flags |= DO_INTL; break; case 'h': /* write usage to stdout, per GNU coding stds */ usage(EXIT_SUCCESS, stdout); break; case 'i': (void) add_srcfile(SRC_INC, optarg, srcfiles, NULL, NULL); break; case 'l': (void) add_srcfile(SRC_EXTLIB, optarg, srcfiles, NULL, NULL); break; case 'L': #ifndef NO_LINT do_flags |= DO_LINT_ALL; if (optarg != NULL) { if (strcmp(optarg, "fatal") == 0) lintfunc = r_fatal; else if (strcmp(optarg, "invalid") == 0) { do_flags &= ~DO_LINT_ALL; do_flags |= DO_LINT_INVALID; } } break; case 't': do_flags |= DO_LINT_OLD; break; #else case 'L': case 't': break; #endif case 'n': do_flags |= DO_NON_DEC_DATA; break; case 'N': use_lc_numeric = true; break; case 'O': do_optimize++; break; case 'p': do_flags |= DO_PROFILE; /* fall through */ case 'o': do_flags |= DO_PRETTY_PRINT; if (optarg != NULL) set_prof_file(optarg); else set_prof_file(DEFAULT_PROFILE); break; case 'M': #ifdef HAVE_MPFR do_flags |= DO_MPFR; #endif break; case 'P': do_flags |= DO_POSIX; break; case 'r': do_flags |= DO_INTERVALS; break; case 'S': do_flags |= DO_SANDBOX; break; case 'V': do_version = true; break; case 'W': /* gawk specific options - now in getopt_long */ fprintf(stderr, _("%s: option `-W %s' unrecognized, ignored\n"), argv[0], optarg); break; case 0: /* * getopt_long found an option that sets a variable * instead of returning a letter. Do nothing, just * cycle around for the next one. */ break; case 'Y': #if defined(YYDEBUG) || defined(GAWKDEBUG) if (c == 'Y') { yydebug = 2; break; } #endif /* if not debugging, fall through */ case '?': default: /* * If not posix, an unrecognized option stops argument * processing so that it can go into ARGV for the awk * program to see. This makes use of ``#! /bin/gawk -f'' * easier. * * However, it's never simple. If optopt is set, * an option that requires an argument didn't get the * argument. We care because if opterr is 0, then * getopt_long won't print the error message for us. */ if (! do_posix && (optopt == '\0' || strchr(optlist, optopt) == NULL)) { /* * can't just do optind--. In case of an * option with >= 2 letters, getopt_long * won't have incremented optind. */ optind = old_optind; stopped_early = true; goto out; } else if (optopt != '\0') { /* Use POSIX required message format */ fprintf(stderr, _("%s: option requires an argument -- %c\n"), myname, optopt); usage(EXIT_FAILURE, stderr); } /* else let getopt print error message for us */ break; } if (c == 'E') /* --exec ends option processing */ break; } out: if (do_nostalgia) nostalgia(); /* check for POSIXLY_CORRECT environment variable */ if (! do_posix && getenv("POSIXLY_CORRECT") != NULL) { do_flags |= DO_POSIX; if (do_lint) lintwarn( _("environment variable `POSIXLY_CORRECT' set: turning on `--posix'")); } if (do_posix) { use_lc_numeric = true; if (do_traditional) /* both on command line */ warning(_("`--posix' overrides `--traditional'")); else do_flags |= DO_TRADITIONAL; /* * POSIX compliance also implies * no GNU extensions either. */ } if (do_traditional && do_non_decimal_data) { do_flags &= ~DO_NON_DEC_DATA; warning(_("`--posix'/`--traditional' overrides `--non-decimal-data'")); } if (do_lint && os_is_setuid()) warning(_("running %s setuid root may be a security problem"), myname); #if MBS_SUPPORT if (do_binary) { if (do_posix) warning(_("`--posix' overrides `--characters-as-bytes'")); else gawk_mb_cur_max = 1; /* hands off my data! */ #if defined(LC_ALL) setlocale(LC_ALL, "C"); #endif } #endif if (do_debug) /* Need to register the debugger pre-exec hook before any other */ init_debug(); #ifdef HAVE_MPFR /* Set up MPFR defaults, and register pre-exec hook to process arithmetic opcodes */ if (do_mpfr) init_mpfr(DEFAULT_PREC, DEFAULT_ROUNDMODE); #endif /* load group set */ init_groupset(); #ifdef HAVE_MPFR if (do_mpfr) { mpz_init(Nnull_string->mpg_i); Nnull_string->flags = (MALLOC|STRCUR|STRING|MPZN|NUMCUR|NUMBER); } else #endif { Nnull_string->numbr = 0.0; Nnull_string->flags = (MALLOC|STRCUR|STRING|NUMCUR|NUMBER); } /* * Tell the regex routines how they should work. * Do this before initializing variables, since * they could want to do a regexp compile. */ resetup(); /* Set up the special variables */ init_vars(); /* Set up the field variables */ init_fields(); /* Now process the pre-assignments */ for (i = 0; i <= numassigns; i++) { if (preassigns[i].type == PRE_ASSIGN) (void) arg_assign(preassigns[i].val, true); else /* PRE_ASSIGN_FS */ cmdline_fs(preassigns[i].val); efree(preassigns[i].val); } if (preassigns != NULL) efree(preassigns); if ((BINMODE & 1) != 0) if (os_setbinmode(fileno(stdin), O_BINARY) == -1) fatal(_("can't set binary mode on stdin (%s)"), strerror(errno)); if ((BINMODE & 2) != 0) { if (os_setbinmode(fileno(stdout), O_BINARY) == -1) fatal(_("can't set binary mode on stdout (%s)"), strerror(errno)); if (os_setbinmode(fileno(stderr), O_BINARY) == -1) fatal(_("can't set binary mode on stderr (%s)"), strerror(errno)); } #ifdef GAWKDEBUG setbuf(stdout, (char *) NULL); /* make debugging easier */ #endif if (os_isatty(fileno(stdout))) output_is_tty = true; /* initialize API before loading extension libraries */ init_ext_api(); /* load extension libs */ for (s = srcfiles->next; s != srcfiles; s = s->next) { if (s->stype == SRC_EXTLIB) load_ext(s->fullpath); else if (s->stype != SRC_INC) have_srcfile++; } /* do version check after extensions are loaded to get extension info */ if (do_version) version(); /* No -f or --source options, use next arg */ if (! have_srcfile) { if (optind > argc - 1 || stopped_early) /* no args left or no program */ usage(EXIT_FAILURE, stderr); (void) add_srcfile(SRC_CMDLINE, argv[optind], srcfiles, NULL, NULL); optind++; } /* Select the interpreter routine */ init_interpret(); init_args(optind, argc, do_posix ? argv[0] : myname, argv); #if defined(LC_NUMERIC) /* * FRAGILE! CAREFUL! * Pre-initing the variables with arg_assign() can change the * locale. Force it to C before parsing the program. */ setlocale(LC_NUMERIC, "C"); #endif /* Read in the program */ if (parse_program(& code_block) != 0) exit(EXIT_FAILURE); if (do_intl) exit(EXIT_SUCCESS); if (do_lint) shadow_funcs(); if (do_lint && code_block->nexti->opcode == Op_atexit) lintwarn(_("no program text at all!")); load_symbols(); if (do_profile) init_profiling_signals(); #if defined(LC_NUMERIC) /* * See comment above about using locale's decimal point. * * 10/2005: * Bitter experience teaches us that most people the world over * use period as the decimal point, not whatever their locale * uses. Thus, only use the locale's decimal point if being * posixly anal-retentive. * * 7/2007: * Be a little bit kinder. Allow the --use-lc-numeric option * to also use the local decimal point. This avoids the draconian * strictness of POSIX mode if someone just wants to parse their * data using the local decimal point. */ if (use_lc_numeric) setlocale(LC_NUMERIC, ""); #endif init_io(); output_fp = stdout; if (do_debug) debug_prog(code_block); else interpret(code_block); if (do_pretty_print) { dump_prog(code_block); dump_funcs(); } if (do_dump_vars) dump_vars(varfile); if (do_tidy_mem) release_all_vars(); /* keep valgrind happier */ if (extra_stack) efree(extra_stack); final_exit(exit_val); return exit_val; /* to suppress warnings */ }
int main () { void *p; unsigned long area1; unsigned long area2; unsigned long area3; /* Preparations. */ #if !HAVE_MMAP_ANON && !HAVE_MMAP_ANONYMOUS && HAVE_MMAP_DEVZERO zero_fd = open ("/dev/zero", O_RDONLY, 0644); #endif sigsegv_init (&dispatcher); sigsegv_install_handler (&handler); /* Setup some mmaped memory. */ p = mmap_zeromap ((void *) 0x12340000, 0x4000); if (p == (void *)(-1)) { fprintf (stderr, "mmap_zeromap failed.\n"); exit (2); } area1 = (unsigned long) p; sigsegv_register (&dispatcher, (void *) area1, 0x4000, &area_handler, &area1); if (mprotect ((void *) area1, 0x4000, PROT_NONE) < 0) { fprintf (stderr, "mprotect failed.\n"); exit (2); } p = mmap_zeromap ((void *) 0x0BEE0000, 0x4000); if (p == (void *)(-1)) { fprintf (stderr, "mmap_zeromap failed.\n"); exit (2); } area2 = (unsigned long) p; sigsegv_register (&dispatcher, (void *) area2, 0x4000, &area_handler, &area2); if (mprotect ((void *) area2, 0x4000, PROT_READ) < 0) { fprintf (stderr, "mprotect failed.\n"); exit (2); } if (mprotect ((void *) area2, 0x4000, PROT_READ_WRITE) < 0 || mprotect ((void *) area2, 0x4000, PROT_READ) < 0) { fprintf (stderr, "mprotect failed.\n"); exit (2); } p = mmap_zeromap ((void *) 0x06990000, 0x4000); if (p == (void *)(-1)) { fprintf (stderr, "mmap_zeromap failed.\n"); exit (2); } area3 = (unsigned long) p; sigsegv_register (&dispatcher, (void *) area3, 0x4000, &area_handler, &area3); mprotect ((void *) area3, 0x4000, PROT_READ); /* This access should call the handler. */ ((volatile int *)area2)[230] = 22; /* This access should call the handler. */ ((volatile int *)area3)[412] = 33; /* This access should not give a signal. */ ((volatile int *)area2)[135] = 22; /* This access should call the handler. */ ((volatile int *)area1)[612] = 11; barrier(); /* Check that the handler was called three times. */ if (logcount != 3) exit (1); if (!(logdata[0] == area2 && logdata[1] == area3 && logdata[2] == area1)) exit (1); printf ("Test passed.\n"); return 0; }