clang-format
This commit is contained in:
@@ -95,12 +95,7 @@
|
||||
* We use the C standard function longjmp() to teleport up the call
|
||||
* stack to where setjmp() was called. At that point we return EFAULT.
|
||||
*/
|
||||
static
|
||||
void
|
||||
copyfail(void)
|
||||
{
|
||||
longjmp(curthread->t_machdep.tm_copyjmp, 1);
|
||||
}
|
||||
static void copyfail(void) { longjmp(curthread->t_machdep.tm_copyjmp, 1); }
|
||||
|
||||
/*
|
||||
* Memory region check function. This checks to make sure the block of
|
||||
@@ -113,33 +108,30 @@ copyfail(void)
|
||||
*
|
||||
* Assumes userspace runs from 0 through USERSPACETOP-1.
|
||||
*/
|
||||
static
|
||||
int
|
||||
copycheck(const_userptr_t userptr, size_t len, size_t *stoplen)
|
||||
{
|
||||
vaddr_t bot, top;
|
||||
static int copycheck(const_userptr_t userptr, size_t len, size_t *stoplen) {
|
||||
vaddr_t bot, top;
|
||||
|
||||
*stoplen = len;
|
||||
*stoplen = len;
|
||||
|
||||
bot = (vaddr_t) userptr;
|
||||
top = bot+len-1;
|
||||
bot = (vaddr_t)userptr;
|
||||
top = bot + len - 1;
|
||||
|
||||
if (top < bot) {
|
||||
/* addresses wrapped around */
|
||||
return EFAULT;
|
||||
}
|
||||
if (top < bot) {
|
||||
/* addresses wrapped around */
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
if (bot >= USERSPACETOP) {
|
||||
/* region is within the kernel */
|
||||
return EFAULT;
|
||||
}
|
||||
if (bot >= USERSPACETOP) {
|
||||
/* region is within the kernel */
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
if (top >= USERSPACETOP) {
|
||||
/* region overlaps the kernel. adjust the max length. */
|
||||
*stoplen = USERSPACETOP - bot;
|
||||
}
|
||||
if (top >= USERSPACETOP) {
|
||||
/* region overlaps the kernel. adjust the max length. */
|
||||
*stoplen = USERSPACETOP - bot;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -149,33 +141,31 @@ copycheck(const_userptr_t userptr, size_t len, size_t *stoplen)
|
||||
* to kernel address DEST. We can use memcpy because it's protected by
|
||||
* the tm_badfaultfunc/copyfail logic.
|
||||
*/
|
||||
int
|
||||
copyin(const_userptr_t usersrc, void *dest, size_t len)
|
||||
{
|
||||
int result;
|
||||
size_t stoplen;
|
||||
int copyin(const_userptr_t usersrc, void *dest, size_t len) {
|
||||
int result;
|
||||
size_t stoplen;
|
||||
|
||||
result = copycheck(usersrc, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
if (stoplen != len) {
|
||||
/* Single block, can't legally truncate it. */
|
||||
return EFAULT;
|
||||
}
|
||||
result = copycheck(usersrc, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
if (stoplen != len) {
|
||||
/* Single block, can't legally truncate it. */
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
memcpy(dest, (const void *)usersrc, len);
|
||||
memcpy(dest, (const void *)usersrc, len);
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return 0;
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -185,33 +175,31 @@ copyin(const_userptr_t usersrc, void *dest, size_t len)
|
||||
* user-level address USERDEST. We can use memcpy because it's
|
||||
* protected by the tm_badfaultfunc/copyfail logic.
|
||||
*/
|
||||
int
|
||||
copyout(const void *src, userptr_t userdest, size_t len)
|
||||
{
|
||||
int result;
|
||||
size_t stoplen;
|
||||
int copyout(const void *src, userptr_t userdest, size_t len) {
|
||||
int result;
|
||||
size_t stoplen;
|
||||
|
||||
result = copycheck(userdest, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
if (stoplen != len) {
|
||||
/* Single block, can't legally truncate it. */
|
||||
return EFAULT;
|
||||
}
|
||||
result = copycheck(userdest, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
if (stoplen != len) {
|
||||
/* Single block, can't legally truncate it. */
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
memcpy((void *)userdest, src, len);
|
||||
memcpy((void *)userdest, src, len);
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return 0;
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -230,28 +218,25 @@ copyout(const void *src, userptr_t userdest, size_t len)
|
||||
* userspace. Thus in the latter case we return EFAULT, not
|
||||
* ENAMETOOLONG.
|
||||
*/
|
||||
static
|
||||
int
|
||||
copystr(char *dest, const char *src, size_t maxlen, size_t stoplen,
|
||||
size_t *gotlen)
|
||||
{
|
||||
size_t i;
|
||||
static int copystr(char *dest, const char *src, size_t maxlen, size_t stoplen,
|
||||
size_t *gotlen) {
|
||||
size_t i;
|
||||
|
||||
for (i=0; i<maxlen && i<stoplen; i++) {
|
||||
dest[i] = src[i];
|
||||
if (src[i] == 0) {
|
||||
if (gotlen != NULL) {
|
||||
*gotlen = i+1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (stoplen < maxlen) {
|
||||
/* ran into user-kernel boundary */
|
||||
return EFAULT;
|
||||
}
|
||||
/* otherwise just ran out of space */
|
||||
return ENAMETOOLONG;
|
||||
for (i = 0; i < maxlen && i < stoplen; i++) {
|
||||
dest[i] = src[i];
|
||||
if (src[i] == 0) {
|
||||
if (gotlen != NULL) {
|
||||
*gotlen = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (stoplen < maxlen) {
|
||||
/* ran into user-kernel boundary */
|
||||
return EFAULT;
|
||||
}
|
||||
/* otherwise just ran out of space */
|
||||
return ENAMETOOLONG;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -262,29 +247,27 @@ copystr(char *dest, const char *src, size_t maxlen, size_t stoplen,
|
||||
* logic to protect against invalid addresses supplied by a user
|
||||
* process.
|
||||
*/
|
||||
int
|
||||
copyinstr(const_userptr_t usersrc, char *dest, size_t len, size_t *actual)
|
||||
{
|
||||
int result;
|
||||
size_t stoplen;
|
||||
int copyinstr(const_userptr_t usersrc, char *dest, size_t len, size_t *actual) {
|
||||
int result;
|
||||
size_t stoplen;
|
||||
|
||||
result = copycheck(usersrc, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = copycheck(usersrc, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
result = copystr(dest, (const char *)usersrc, len, stoplen, actual);
|
||||
result = copystr(dest, (const char *)usersrc, len, stoplen, actual);
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return result;
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -295,27 +278,26 @@ copyinstr(const_userptr_t usersrc, char *dest, size_t len, size_t *actual)
|
||||
* logic to protect against invalid addresses supplied by a user
|
||||
* process.
|
||||
*/
|
||||
int
|
||||
copyoutstr(const char *src, userptr_t userdest, size_t len, size_t *actual)
|
||||
{
|
||||
int result;
|
||||
size_t stoplen;
|
||||
int copyoutstr(const char *src, userptr_t userdest, size_t len,
|
||||
size_t *actual) {
|
||||
int result;
|
||||
size_t stoplen;
|
||||
|
||||
result = copycheck(userdest, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = copycheck(userdest, len, &stoplen);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
curthread->t_machdep.tm_badfaultfunc = copyfail;
|
||||
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
result = setjmp(curthread->t_machdep.tm_copyjmp);
|
||||
if (result) {
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
result = copystr((char *)userdest, src, len, stoplen, actual);
|
||||
result = copystr((char *)userdest, src, len, stoplen, actual);
|
||||
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return result;
|
||||
curthread->t_machdep.tm_badfaultfunc = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user