Answer the question
In order to leave comments, you need to log in
Arm assembler in Linux kernel?
Good afternoon! Poking around in the Linux kernel sorts, under the ARM architecture, I found the following code, which is used in the copy_from_user function:
#define __range_ok(addr,size) ({ \<br/>
unsigned long flag, roksum; \<br/>
__chk_user_ptr(addr); \<br/>
__asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \<br/>
: "=&r" (flag), "=&r" (roksum) \<br/>
: "r" (addr), "Ir" (size), "" (current_thread_info()->addr_limit) \<br/>
: "cc"); \<br/>
flag; })<br/>
Answer the question
In order to leave comments, you need to log in
flag is used as the return value (note the last line).
As a result, __range_ok will return 0 if and only if addr + size <= addr_limit and no overflow has occurred on addition.
It works like this:
0. flag = addr_limit (assuming addr_limit != 0);
1. roksum = addr + size;
2. if there was no overflow in item 1, then roksum = roksum - addr_limit - 1;
3. if after step 2 rok_sum >= 0, then flag = 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question