Skip to contentSkip to conversation

unaligned.c

PATCH New Zhang Fuxin 1 participant 1 message Dec 7, 2001 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unaligned.c

hi,linux-mips,
This patch does:
1.As Mr. Atsushi Nemoto has pointed out,the newest unaligned.c leave out several jb in
the sw/sh emulation code.It will lead to oops if someone use unaligned addresses as syscall arguments to be stored to.Because the fixup code won't return to emulate_load_store_insn then.

2.when search_exception_table does find a fixup in emulate_load_store_insn,I think we should
skip compute_return_epc(regs) in do_ade then.Or it will jump to wrong fixup position later. ltp failed the getsockname syscall test in this way:
getsockname(fd,&sock,(int *)1) 1 is used at the position of &sinlen.
then,kernel will finally call get_user to fetch the user provided len and cause a AdeL exception:
get_user(len,ulen)
(a fixup installed for the lw)
---->exception
---> do_ade
------>emulate_load_store_insn
emulate fail
--->exception
<---fixup
search_exception_table find the handler installed by get_user and change
regs->cp0_epc to the fixup position
<-------return
compute_return_epc(regs) ADD another 4 to epc!
<----------------
execution continues from fixup + 4,this omit the code to load -EFAULT to return value of get_user,may lead to further failures
so i propose watch epc during emulate_load_store_insn,if it changes,then skip compute_return _epc

3.(optional,implemented)it may be better for search_exception_table & fixup_exception
to use PC instead of regs->cp0_epc as arguments. PC points to the actual load/store instruction anyway, although this is for kernel code so it is almost impossible for user space accessing code to put load/store in a branch delay.

4.(optional,unimplemented) Will it be more efficient to put use emulation code of lw/lh/sw/sh
before other impossible conditions?

Am i missing something?

BTW:
Could somebody be so kind to explain the use of save_static_function?I know they build
a pseudo function with a return, so call sys_sigsuspend will fall through to _sys_sigsuspend but what's the use? Nobody calls _sys_sigsuspend.

Regards
Zhang Fuxin
[email protected]

219a220

Quoted 1 line
			"j\t3b\n\t"

258a260

Quoted 1 line
			"j\t3b\n\t"

285a288

Quoted 1 line
			"j\t3b\n\t"

332c335
< fixup = search_exception_table(regs->cp0_epc);
---

Quoted 1 line
	fixup = search_exception_table(pc);

335c338
< new_epc = fixup_exception(dpf_reg, fixup, regs->cp0_epc);
---

Quoted 1 line
		new_epc = fixup_exception(dpf_reg, fixup, pc);

361a365

Quoted 1 line
	unsigned long oldepc;

387a392

Quoted 1 line
	oldepc = regs->cp0_epc;

392c397,403
< compute_return_epc(regs);
---

Quoted 7 lines
	
	/* If epc changed under us,the only possibility is the exception
	 * is forwarded to new location during fixup,then we can't change
	 * it here--zfx
	 */
	if (oldepc == regs->cp0_epc)
		compute_return_epc(regs);