Skip to contentSkip to conversation

Copy large memory regions from & to userspace

DISCUSSION Clemens Kolbitsch 1 participant 2 messages Aug 30, 2007 – Aug 31, 2007 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi!
Just a short question: What is the correct method of copying large areas of memory from userspace into userspace when running in kernel-mode?

According to just about any type of documentation out there something like

unsigned long *from = 0x08000000;
unsigned long *to = 0x09000000;
memcpy(to, from, 0x1000);

should be avoided as copy_from_user, put_user, etc. should be used instead...

Is there a third set of functions for direct from-userspace-to-userspace copying or is it legitimate to assure that the first bytes in the from & to memory areas are available and then just do the plain memcpy?

Maybe there is a simple "just use the xxx function-set" answer to that, that i just have not ran into yet :-)

Thanks!

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 6 lines · On Friday 31 August 2007 15:25:40 you wrote:
Quoted 3 lines · Clemens Kolbitsch

Hi!
Just a short question: What is the correct method of copying large areas of memory from userspace into userspace when running in kernel-mode?

relayfs?

no... I'm copying user-memory to user-memory, not kernel-to-user, however running the code in kernel-mode.

what i wanted to know is how to check the access-rights... i didn't get any other answers, so for now i'm just using

if (access_ok(VERIFY_READ, from, PAGE_SIZE) &&
access_ok(VERIFY_WRITE, to, PAGE_SIZE))

{
    memcpy(to, from, PAGE_SIZE);
}

and hope that this is the *correct* way to do it...