Changeset 6526
- Timestamp:
- May 9, 2007, 1:59:10 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/lisp-kernel/x86-exceptions.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/lisp-kernel/x86-exceptions.c
r6275 r6526 78 78 if (newlimit > (natural) (a->high)) { 79 79 if (extend) { 80 if (! resize_dynamic_heap(a->active, (newlimit-oldlimit)+lisp_heap_gc_threshold)) { 81 return false; 82 } 80 natural extend_by = lisp_heap_gc_threshold; 81 do { 82 if (resize_dynamic_heap(a->active, (newlimit-oldlimit)+extend_by)) { 83 break; 84 } 85 extend_by = align_to_power_of_2(extend_by>>1,log2_allocation_quantum); 86 if (extend_by < 4<<20) { 87 return false; 88 } 89 } while (1); 83 90 } else { 84 91 return false; … … 316 323 tra = xpGPR(xp,Ira0); 317 324 if (tag_of(tra) == tag_tra) { 318 tra_f = tra - ((int *)tra)[-1]; 325 if ((*((unsigned short *)tra) == RECOVER_FN_FROM_RIP_WORD0) && 326 (*((unsigned char *)(tra+2)) == RECOVER_FN_FROM_RIP_BYTE2)) { 327 int sdisp = (*(int *) (tra+3)); 328 tra_f = RECOVER_FN_FROM_RIP_LENGTH+tra+sdisp; 329 } 319 330 if (fulltag_of(tra_f) != fulltag_function) { 320 331 tra_f = 0; … … 566 577 567 578 Boolean 568 handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info )579 handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info, int old_valence) 569 580 { 570 581 #ifdef FREEBSD … … 587 598 } 588 599 } 589 { 590 LispObj xcf = create_exception_callback_frame(xp), 591 cmain = nrs_CMAIN.vcell; 592 callback_to_lisp(tcr, cmain, xp, xcf, SIGBUS, is_write_fault(xp,info), (natural)addr, 0); 600 if (old_valence == TCR_STATE_LISP) { 601 LispObj cmain = nrs_CMAIN.vcell, 602 xcf; 603 if ((fulltag_of(cmain) == fulltag_misc) && 604 (header_subtag(header_of(cmain)) == subtag_macptr)) { 605 xcf = create_exception_callback_frame(xp); 606 callback_to_lisp(tcr, cmain, xp, xcf, SIGBUS, is_write_fault(xp,info), (natural)addr, 0); 607 } 593 608 } 594 609 return false; … … 719 734 720 735 Boolean 721 handle_exception(int signum, siginfo_t *info, ExceptionInformation *context, TCR *tcr )736 handle_exception(int signum, siginfo_t *info, ExceptionInformation *context, TCR *tcr, int old_valence) 722 737 { 723 738 pc program_counter = (pc)xpPC(context); … … 770 785 771 786 } else { 772 return handle_fault(tcr, context, info );787 return handle_fault(tcr, context, info, old_valence); 773 788 } 774 789 break; … … 824 839 #if SIGBUS != SIGNUM_FOR_INTN_TRAP 825 840 case SIGBUS: 826 return handle_fault(tcr, context, info );841 return handle_fault(tcr, context, info, old_valence); 827 842 #endif 828 843 829 844 #if SIGSEGV != SIGNUM_FOR_INTN_TRAP 830 845 case SIGSEGV: 831 return handle_fault(tcr, context, info );846 return handle_fault(tcr, context, info, old_valence); 832 847 #endif 833 848 … … 924 939 925 940 926 if (! handle_exception(signum, info, context, tcr )) {941 if (! handle_exception(signum, info, context, tcr, old_valence)) { 927 942 char msg[512]; 928 943 … … 1041 1056 1042 1057 #ifdef DARWIN 1043 /* 1044 There seems to be a problem with thread-level exception handling; 1045 Mach seems (under some cirumstances) to conclude that there's 1046 no thread-level handler and exceptions get passed up to a 1047 handler that raises Un*x signals. Ignore those signals so that 1048 the exception will repropagate and eventually get caught by 1049 catch_exception_raise() at the thread level. 1050 1051 Mach sucks, but no one understands how. 1052 */ 1053 void 1054 bogus_signal_handler() 1055 { 1056 /* This does nothing, but does it with signals masked */ 1058 void 1059 bogus_signal_handler(int signum, siginfo_t *info, ExceptionInformation *xp) 1060 { 1061 if (signum == SIGSYS) { 1062 return; /* Leopard lossage */ 1063 } 1057 1064 } 1058 1065 #endif … … 1160 1167 old_valence = prepare_to_wait_for_exception_lock(tcr, context); 1161 1168 wait_for_exception_lock_in_handler(tcr, context, &xframe_link); 1162 handle_exception(signum, info, context, tcr );1169 handle_exception(signum, info, context, tcr, old_valence); 1163 1170 if (alloc_displacement) { 1164 1171 tcr->save_allocptr -= alloc_displacement; … … 1729 1736 } 1730 1737 } 1731 xpPC(xp) = xpGPR(xp,Ira0); 1738 { 1739 /* These subprimitives are called via CALL/RET; need 1740 to pop the return address off the stack and set 1741 the PC there. */ 1742 LispObj *rsp = (LispObj *)xpGPR(xp,Isp), ra = *rsp++; 1743 xpPC(xp) = ra; 1744 xpGPR(xp,Isp)=(LispObj)rsp; 1745 } 1732 1746 return; 1733 1747 } … … 1900 1914 #define TCR_TO_EXCEPTION_PORT(tcr) ((mach_port_t)((natural)(tcr))) 1901 1915 1916 #if USE_MACH_EXCEPTION_LOCK 1902 1917 pthread_mutex_t _mach_exception_lock, *mach_exception_lock; 1918 #endif 1903 1919 extern void pseudo_sigreturn(void); 1904 1920 … … 2276 2292 #endif 2277 2293 2294 2278 2295 kern_return_t 2279 2296 catch_exception_raise(mach_port_t exception_port, … … 2295 2312 2296 2313 2314 2297 2315 #ifdef DEBUG_MACH_EXCEPTIONS 2298 2316 fprintf(stderr, "obtaining Mach exception lock in exception thread\n"); … … 2300 2318 2301 2319 2302 if (pthread_mutex_trylock(mach_exception_lock) == 0) { 2320 if ( 2321 #if USE_MACH_EXCEPTION_LOCK 2322 pthread_mutex_trylock(mach_exception_lock) == 0 2323 #else 2324 1 2325 #endif 2326 ) { 2303 2327 #ifdef X8664 2304 thread_state_count = x86_THREAD_STATE64_COUNT; 2305 call_kret = thread_get_state(thread, 2306 x86_THREAD_STATE64, 2307 (thread_state_t)&ts, 2308 &thread_state_count); 2328 do { 2329 thread_state_count = x86_THREAD_STATE64_COUNT; 2330 call_kret = thread_get_state(thread, 2331 x86_THREAD_STATE64, 2332 (thread_state_t)&ts, 2333 &thread_state_count); 2334 } while (call_kret == KERN_ABORTED); 2309 2335 MACH_CHECK_ERROR("getting thread state",call_kret); 2310 2336 #else … … 2344 2370 } 2345 2371 break; 2346 2372 2347 2373 case EXC_SOFTWARE: 2348 signum = SIGILL;2374 signum = SIGILL; 2349 2375 break; 2350 2376 2351 2377 case EXC_ARITHMETIC: 2352 2378 signum = SIGFPE; 2353 2379 break; 2354 2380 2355 2381 default: 2356 2382 break; … … 2364 2390 &ts); 2365 2391 #if 0 2366 fprintf(stderr, "Setup pseudosignal handling in 0x%x\n",tcr);2367 #endif 2368 2392 fprintf(stderr, "Setup pseudosignal handling in 0x%x\n",tcr); 2393 #endif 2394 2369 2395 } else { 2370 2396 kret = 17; 2371 2397 } 2372 2398 } 2399 #if USE_MACH_EXCEPTION_LOCK 2373 2400 #ifdef DEBUG_MACH_EXCEPTIONS 2374 2401 fprintf(stderr, "releasing Mach exception lock in exception thread\n"); 2375 2402 #endif 2376 2403 pthread_mutex_unlock(mach_exception_lock); 2404 #endif 2377 2405 } else { 2378 2406 SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION); … … 2381 2409 fprintf(stderr, "deferring pending exception in 0x%x\n", tcr); 2382 2410 #endif 2383 kret = 0;2411 kret = KERN_SUCCESS; 2384 2412 if (tcr == gc_tcr) { 2385 2413 int i; … … 2437 2465 kern_return_t kret; 2438 2466 if (__exception_port_set == MACH_PORT_NULL) { 2467 #if USE_MACH_EXCEPTION_LOCK 2439 2468 mach_exception_lock = &_mach_exception_lock; 2440 2469 pthread_mutex_init(mach_exception_lock, NULL); 2470 #endif 2441 2471 2442 2472 kret = mach_port_allocate(mach_task_self(),
Note:
See TracChangeset
for help on using the changeset viewer.
