2

Does the copy_from_user function, declared in uaccess.h, modify the (void __user *)from pointer? The pointer isn't declared as const in the function declaration, only the contents it points to.

The reason I ask is that I want to use copy_from_user twice, with the second copy_from_user copying from the place where the first one finished.

I was planning on doing something like this, is it guaranteed to work?

//buf is a user pointer that is already defined
copy_from_user(my_first_alloced_region, buf, some_size);
//do stuff
copy_from_user(my_second_alloced_region, buf + some_size, some_other_size);

Thanks in advance.

4

1 回答 1

3

被调用函数不能修改指针本身,因为您只是将指针值作为参数传递给函数。如果参数被声明为指向const类型的指针,那么被调用者也不能修改所指向的内容(至少在没有会抛弃const指针的 -ness 的强制转换的情况下不能修改)。修改调用者本身的指针值的唯一方法是向被调用者传递一个指针到指针的类型。

于 2012-09-18T02:59:56.440 回答