clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -40,80 +40,70 @@
* used. The cheesy hack versions in dumbvm.c are used instead.
*/
struct addrspace *
as_create(void)
{
struct addrspace *as;
struct addrspace *as_create(void) {
struct addrspace *as;
as = kmalloc(sizeof(struct addrspace));
if (as == NULL) {
return NULL;
}
as = kmalloc(sizeof(struct addrspace));
if (as == NULL) {
return NULL;
}
/*
* Initialize as needed.
*/
/*
* Initialize as needed.
*/
return as;
return as;
}
int
as_copy(struct addrspace *old, struct addrspace **ret)
{
struct addrspace *newas;
int as_copy(struct addrspace *old, struct addrspace **ret) {
struct addrspace *newas;
newas = as_create();
if (newas==NULL) {
return ENOMEM;
}
newas = as_create();
if (newas == NULL) {
return ENOMEM;
}
/*
* Write this.
*/
/*
* Write this.
*/
(void)old;
(void)old;
*ret = newas;
return 0;
*ret = newas;
return 0;
}
void
as_destroy(struct addrspace *as)
{
/*
* Clean up as needed.
*/
void as_destroy(struct addrspace *as) {
/*
* Clean up as needed.
*/
kfree(as);
kfree(as);
}
void
as_activate(void)
{
struct addrspace *as;
void as_activate(void) {
struct addrspace *as;
as = proc_getas();
if (as == NULL) {
/*
* Kernel thread without an address space; leave the
* prior address space in place.
*/
return;
}
as = proc_getas();
if (as == NULL) {
/*
* Kernel thread without an address space; leave the
* prior address space in place.
*/
return;
}
/*
* Write this.
*/
/*
* Write this.
*/
}
void
as_deactivate(void)
{
/*
* Write this. For many designs it won't need to actually do
* anything. See proc.c for an explanation of why it (might)
* be needed.
*/
void as_deactivate(void) {
/*
* Write this. For many designs it won't need to actually do
* anything. See proc.c for an explanation of why it (might)
* be needed.
*/
}
/*
@@ -126,57 +116,48 @@ as_deactivate(void)
* moment, these are ignored. When you write the VM system, you may
* want to implement them.
*/
int
as_define_region(struct addrspace *as, vaddr_t vaddr, size_t memsize,
int readable, int writeable, int executable)
{
/*
* Write this.
*/
int as_define_region(struct addrspace *as, vaddr_t vaddr, size_t memsize,
int readable, int writeable, int executable) {
/*
* Write this.
*/
(void)as;
(void)vaddr;
(void)memsize;
(void)readable;
(void)writeable;
(void)executable;
return ENOSYS;
(void)as;
(void)vaddr;
(void)memsize;
(void)readable;
(void)writeable;
(void)executable;
return ENOSYS;
}
int
as_prepare_load(struct addrspace *as)
{
/*
* Write this.
*/
int as_prepare_load(struct addrspace *as) {
/*
* Write this.
*/
(void)as;
return 0;
(void)as;
return 0;
}
int
as_complete_load(struct addrspace *as)
{
/*
* Write this.
*/
int as_complete_load(struct addrspace *as) {
/*
* Write this.
*/
(void)as;
return 0;
(void)as;
return 0;
}
int
as_define_stack(struct addrspace *as, vaddr_t *stackptr)
{
/*
* Write this.
*/
int as_define_stack(struct addrspace *as, vaddr_t *stackptr) {
/*
* Write this.
*/
(void)as;
(void)as;
/* Initial user-level stack pointer */
*stackptr = USERSTACK;
/* Initial user-level stack pointer */
*stackptr = USERSTACK;
return 0;
return 0;
}

View File

@@ -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;
}

File diff suppressed because it is too large Load Diff