Patches. Again.
Hi!
Adapted to the latest softfloat changes and topped off with an evil hack that serves me well until someone implements the sigaltstack syscall properly.
qemu-jobsignals.patch: SIGTSTP/SIGCONT handling qemu-arm-sigfpe.patch: signal FPA exceptions on ARM targets qemu-syscalls.patch: implements syscalls acct, uselib, syslog, ftruncate64, mincore, madvise, readahead, and clock_gettime qemu-sigaltstackhack.patch: dummy sigaltstack implementation, workaround in host signal handler to prevent endless segfault loops
CU
Uli
Index: linux-user/signal.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/signal.c,v retrieving revision 1.27
signal.c +6 -1
@@ -348,10 +348,15 @@ k = &sigact_table[sig -1 ]; handler = k->sa._sa_handler;if (handler ==TARGET_SIG_DFL ) { +if (sig ==TARGET_SIGTSTP || sig ==TARGET_SIGTTIN || sig ==TARGET_SIGTTOU ) { +kill (getpid (),SIGSTOP ); +return 0 ; + }else /* default handler : ignore some signal. The other are fatal */ if (sig !=TARGET_SIGCHLD && sig !=TARGET_SIGURG && - sig !=TARGET_SIGWINCH ) { + sig !=TARGET_SIGWINCH && + sig !=TARGET_SIGCONT ) {force_sig (sig); }else {return 0 ;/* indicate ignored */
Index: linux-user/main.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/main.c,v
retrieving revision 1.62
main.c +38 -2
@@ -325,18 +325,54 @@ {TaskState *ts = env->opaque;uint32_t opcode; +int rc;/* we handle the FPU emulation here, as Linux */ /* we get the opcode */ opcode =ldl_raw ((uint8_t *)env->regs[15 ]); -if (EmulateAll (opcode, &ts->fpa, env->regs) ==0 ) { +if ((rc=EmulateAll (opcode, &ts->fpa, env->regs)) ==0 ) {/* illegal instruction */ info.si_signo =SIGILL ; info.si_errno =0 ; info.si_code =TARGET_ILL_ILLOPN ; info._sifields._sigfault._addr = env->regs[15 ];queue_signal (info.si_signo, &info); - }else { + }else if (rc <0 ) {/* FP exception */ +int arm_fpe=0 ; +/* translate softfloat flags to FPSR flags */ +if (-rc & float_flag_invalid) arm_fpe |=BIT_IOC ; +if (-rc & float_flag_divbyzero) arm_fpe |=BIT_DZC ; +if (-rc & float_flag_overflow) arm_fpe |=BIT_OFC ; +if (-rc & float_flag_underflow) arm_fpe |=BIT_UFC ; +if (-rc & float_flag_inexact) arm_fpe |=BIT_IXC ; + +FPSR fpsr = ts->fpa.fpsr; +//printf("fpsr 0x%x, arm_fpe 0x%x\n",fpsr,arm_fpe); + +if (fpsr & (arm_fpe <<16 ))/* exception enabled? */ + { + info.si_signo =SIGFPE ; + info.si_errno =0 ; +/* ordered by priority, least first */ +if (arm_fpe &BIT_IXC ) info.si_code =TARGET_FPE_FLTRES ; +if (arm_fpe &BIT_UFC ) info.si_code =TARGET_FPE_FLTUND ; +if (arm_fpe &BIT_OFC ) info.si_code =TARGET_FPE_FLTOVF ; +if (arm_fpe &BIT_DZC ) info.si_code =TARGET_FPE_FLTDIV ; +if (arm_fpe &BIT_IOC ) info.si_code =TARGET_FPE_FLTINV ; + info._sifields._sigfault._addr = env->regs[15 ]; +queue_signal (info.si_signo, &info); + } +else + env->regs[15 ] +=4 ; + +/* accumulate unenabled exceptions */ +if ((!(fpsr &BIT_IXE )) && (arm_fpe &BIT_IXC )) fpsr |=BIT_IXC ; +if ((!(fpsr &BIT_UFE )) && (arm_fpe &BIT_UFC )) fpsr |=BIT_UFC ; +if ((!(fpsr &BIT_OFE )) && (arm_fpe &BIT_OFC )) fpsr |=BIT_OFC ; +if ((!(fpsr &BIT_DZE )) && (arm_fpe &BIT_DZC )) fpsr |=BIT_DZC ; +if ((!(fpsr &BIT_IOE )) && (arm_fpe &BIT_IOC )) fpsr |=BIT_IOC ; + ts->fpa.fpsr=fpsr; + }else {/* everything OK */ /* increment PC */ env->regs[15 ] +=4 ; }
Index: target-arm/nwfpe/fpa11.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-arm/nwfpe/fpa11.c,v retrieving revision 1.2
nwfpe/fpa11.c +7 -0
@@ -161,6 +161,8 @@ fpa11->initflag =1 ; } +set_float_exception_flags (0 , &fpa11->fp_status); +if (TEST_OPCODE (opcode,MASK_CPRT )) {//fprintf(stderr,"emulating CPRT\n");
@@ -190,6 +192,11 @@ }// restore_flags(flags); +if (nRc ==1 &&get_float_exception_flags (&fpa11->fp_status)) + { +//printf("fef 0x%x\n",float_exception_flags); + nRc=-get_float_exception_flags (&fpa11->fp_status); + }//printf("returning %d\n",nRc); return (nRc);
Index: Makefile.target
===================================================================
RCS file: /cvsroot/qemu/qemu/Makefile.target,v
retrieving revision 1.62
Makefile.target +2 -2
@@ -209,8 +209,8 @@ ######################################################### -DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -LIBS+=-lm +DEFINES+=-D_GNU_SOURCE -D_BSD_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE +LIBS+=-lm -lrt ifndef CONFIG_USER_ONLY LIBS+=-lz endif
Index: linux-user/syscall.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/syscall.c,v retrieving revision 1.58
syscall.c +37 -7
107 lines not on this page · raw message
Index: linux-user/arm/syscall_nr.h
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/arm/syscall_nr.h,v retrieving revision 1.2
arm/syscall_nr.h +1 -0
@@ -259,4 +259,5 @@/* 254 for set_thread_area */ /* 255 for get_thread_area */ /* 256 for set_tid_address */ +#define TARGET_NR_clock_gettime (263)#define TARGET_NR_utimes (269)
Index: linux-user/signal.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/signal.c,v retrieving revision 1.27
signal.c +21 -0
@@ -1019,6 +1026,14 @@return err; } +void * hack_stack; + +void hack_handler (int signum) +{ +fprintf (stderr,"QEMU: stack overflow, aborting\n" ); +exit (-SIGSEGV ); +} +static inline void *get_sigframe (struct emulated_sigaction *ka,CPUState *regs,int framesize) {
@@ -1031,6 +1046,19 @@if ((ka->sa.sa_flags &SA_ONSTACK ) && !sas_ss_flags (sp)) sp = current->sas_ss_sp + current->sas_ss_size;#endif + +/* EVIL HACK TIME! +This is supposed to prevent endless segfault loops in case of stack +overflows that can occur as a result of the dummy sigaltstack() +syscall. */ +struct sigaction oldact; +struct sigaction act; +memset (&act,0 ,sizeof (struct sigaction )); + act.sa_handler=hack_handler; +sigaction (SIGSEGV ,&act,&oldact); + hack_stack = *((void **)((sp-framesize)&~7 )); +sigaction (SIGSEGV ,&oldact,&act); +/* * ATPCS B01 mandates 8-byte alignment */
Index: linux-user/syscall.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/syscall.c,v retrieving revision 1.58
syscall.c +2 -1
@@ -2725,7 +2734,8 @@case TARGET_NR_capset: goto unimplemented;case TARGET_NR_sigaltstack: - goto unimplemented; + ret =0 ;/* good enough for most purposes */ +break ;case TARGET_NR_sendfile: goto unimplemented;#ifdef TARGET_NR_getpmsg