Created
October 1, 2014 20:43
-
-
Save norcali/f07347000509de45d996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SYSCALL_DEFINE3(silly_copy, | |
unsigned long *, src, | |
unsigned long *, dst, | |
unsigned long, len) | |
{ | |
unsigned long buf[64]; /* Buffer for chunks */ | |
unsigned long lenleft = len; /* Remaining size */ | |
unsigned long chunklen = sizeof(buf); /* Initial chunk length */ | |
/* Loop handling chunk sizes */ | |
while (lenleft > 0) { | |
/* Change chunk length on last chunk */ | |
if (lenleft < chunklen) chunklen = lenleft; | |
/* copy src(user) to buf(kernel) then dst(user) */ | |
if (copy_from_user(buf, src, chunklen)) return -EFAULT; | |
if (copy_to_user(dst, buf, chunklen)) return -EFAULT; | |
/* Adjust pointers and remaining size */ | |
src += chunklen; dst += chunklen; lenleft -= chunklen; | |
} | |
/* return amount of data copied */ | |
return len; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment