[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [microblaze-uclinux] [patch] errno corruption




Jivin John Williams lays it down ...
> Hi David,
> 
> David McCullough wrote:
> >The real trouble with unistd.h is that the syscalls are done as macros
> >and not inline functions.  This means the can be included into the
> >middle of some C code,  and at the point the optimiser may move your
> >declarations away from the asm,  leaving the possibility for the value
> >in the register to not be preserved and break your system call.
> 
> Can we do one of the silly tricks like putting do {} while 0; around it?

I don't know,  I'll have a chat with paul tomorrrow,  he knows more about
this than I do.  I'll pass on his thoughts.  I think the {}'s around it
are as good as a do {} while();  remember that common sub expression
elimination and constants can cause code to be moved outside of loops,
but I don't know what gcc will do.

> Or, is there any reason not to make them inline function calls?

I believe that if you only ever used the macro in a function,  as in:

	func()
	{
		syscall2(...);
	}

that you would be safe.  So inline functions would seem safe for the
same reason.  I don't know if the compiler will optimise in and around
and inline function call.  We chose to take the performance hit,  doesn't
mean it was the only way though.  When you have potential problems its
with code like this:

	func()
	{
		blah
		blah
		...
		syscall2(...)
		...
		blah
		blah
	}

That it can get confused.  uClibc or uC-libc used to have some examples
of this IIRC,

Cheers,
Davidm

-- 
David McCullough, davidm@snapgear.com  Ph:+61 7 34352815 http://www.SnapGear.com
Custom Embedded Solutions + Security   Fx:+61 7 38913630 http://www.uCdot.org
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@itee.uq.edu.au
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/