This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Volatile MEMs in statement expressions and functions inlined as trees


On Tue, Dec 04, 2001 at 08:33:25AM -0200, Alexandre Oliva wrote:
> Does anybody have pointers to existing SIGSEGV handlers that will skip
> a faulty instruction on say GNU/Linux/x86 (probably the most common
> target these days, and one I happen to have local access to :-)

I know I've seen one somewhere in the past, but I can't think 
where.  It isn't as diffucult as you imagine -- you only have
to recognize the "mov" instruction -- if you get anything else 
you abort.

So, something like

	unsigned char *pc = ...

	if (*pc == 0x66)	/* operand size override */
	  pc++;
	if (*pc == 0x89	/* reg to memory */
	    || *pc == 0x8a	/* mem to reg8 */
	    || *pc == 0x8b)	/* mem to reg16 or reg32 */
	  {
	    unsigned char modrm = *++pc;
	    switch (modrm >> 5)
	      {
	      case 0: /* Nominally, indirect address */
		switch (modrm & 7)
		  {
		  case 4: /* SIB byte follows */
		    pc += 1;
		    break;
		  case 5: /* 32-bit absolute address follows */
		    pc += 4;
		    break;
		  }
		break;
	      case 1: /* Nominally, indirect plus disp8 */
		if ((modrm & 7) == 4) /* SIB byte follows */
		  pc += 1;
		pc += 1;
		break;
	      case 2: /* Nominally, indirect plus disp32 */
		if ((modrm & 7) == 4) /* SIB byte follows */
		  pc += 1;
		pc += 4;
		break;
	      case 3: /* Register, not memory, source.  */
		break;
	      }

	    /* Store pc back into signal struct.  */
	    return;
	  }
	abort ();


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]