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

Markos Chandras markos.chandras at gmail.com
Fri Feb 22 15:10:16 UTC 2013


On 21 February 2013 15:00, Bernhard Reutner-Fischer
<rep.dot.nop at gmail.com> wrote:
> 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?

Hi Bernhard,

We can't use an immediate constraint. The behaviour of asm specifiers
on variables is extremely special and it interacts with function calls
when variables have been forced into registers that are used as part
of the calling convention. There are no immediates involved in this
particular section of code we are merely guaranteeing that certain
variables will be present in specific registers at the point of the
inline asm block. Function calls between definition and use of the asm
variables break the guarantees that GCC otherwise provides.

Due to the significant number of registers involved in the calling
convention we do not provide an asm register constraint class for each
individual register so using asm variables is the best alternative.

-- 
Regards,
Markos Chandras


More information about the uClibc mailing list