Finally: Mac Intel patches

Mikael Pettersson <>
Thu Aug 24 09:27:14 CEST 2006


Joel Reymont writes:
 > >> +#elif defined(__DARWIN__) && defined(__i386__)
 > >> +    mcontext_t mc = uc->uc_mcontext;
 > >> +    i386_float_state_t fpstate = mc->fs;
 > >> +    fpstate.fpu_mxcsr = 0x1F80;
 > >> +    *((unsigned short *)&fpstate.fpu_fsw) &= ~0xFF;
 > >> #elif defined(__DARWIN__)
 > >>     mcontext_t mc = uc->uc_mcontext;
 > >>     mc->ss.srr0 += 4;
 > >
 > > You're copying the float state into fpstate and updating the copy
 > > without flushing the changes back to the original. This cannot be
 > > right. fpstate should be a pointer to mc->fs.
 > 
 > I'm updating the structure and the changes are flushed back by the  
 > kernel when the signal handler terminates.

No. You're only reading *uc and *mc, never writing them.
Your assignments to fpstate are to a local variable unrelated
to the memory area (*uc and *mc) written and read by the kernel.

You change to the signal handler in sys_float.c is different and
correct, it's only erts/configure.in that has this problem.

 > > What is the concrete type of the fpu_fsw field? I really don't
 > > want to update it via a pointer cast like this.
...
 > fpu_sw has type of fp_status_t which is a union.
 > 
 > /*
 > * Status word.
 > */
 > 
 > typedef struct fp_status {
 >      unsigned short              invalid :1,
 >                                  denorm  :1,
 >                                  zdiv    :1,
 >                                  ovrfl   :1,
 >                                  undfl   :1,
 >                                  precis  :1,
 >                                  stkflt  :1,
 >                                  errsumm :1,
 >                                  c0      :1,
 >                                  c1      :1,
 >                                  c2      :1,
 >                                  tos     :3,
 >                                  c3      :1,
 >                                  busy    :1;
 > } fp_status_t;

Yuck, that's horrible. I'll keep the pointer cast.

 > > The current x86 assembly code uses .global not .globl.
 > 
 > Apple's assembler uses .globl. Don't ask me!

Your patch changed .global to .globl on both Darwin and non-Darwin.



More information about the erlang-questions mailing list