[PATCH 12/12] sched_setaffinity: Don't use function calls as arguments to INTERNAL_SYSCALL.

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Thu Feb 21 15:00:14 UTC 2013


On 21 February 2013 11:12, Markos Chandras <markos.chandras at gmail.com> wrote:
> From: Markos Chandras <markos.chandras at imgtec.com>
>
> This patch fixes a bug in sched_setaffinity() for Meta where the affinity
> argument was ignored when trying to set a process's scheduling
> affinity.
>
> INTERNAL_SYSCALL places its arguments in the argument registers in
> preparation for a system call, e.g.
>
>             register int arg1 __asm__ ("D1Ar1") = _arg1;
>             register int arg2 __asm__ ("D0Ar2") = _arg2;
>
> The problem comes when a function call is passed as an argment to
> INTERNAL_SYSCALL and the following code results,
>
>             register int arg1 __asm__ ("D1Ar1") = _arg1;
>             register int arg2 __asm__ ("D0Ar2") = _arg2;
>             register int arg3 __asm__ ("D1Ar3") = func();
>
> Now, because the compiler is smart enough to figure out the argument
> registers are not preserved across a function call, and that "func"
> takes no arguments, the assignments to D1Ar1 and D0Ar2 are dead code
> and the compiler eliminates them. Consequently, the syscall is
> performed with garbage arguments in D1Ar1 and D0Ar2.
>
> The solution is to use a temporary variable in which we store the
> result of func() and assign that temporary variable to D1Ar3.

Can't you use an immediate in your constraints?


More information about the uClibc mailing list