asst3-Virtual Memory Translation/kern/syscall/runprogram.c
static
int
argbuf_copyout(struct argbuf *buf, vaddr_t *ustackp,
	       int *argc_ret, userptr_t *uargv_ret)
{
	vaddr_t ustack;
	userptr_t ustringbase, uargvbase, uargv_i;
	userptr_t thisarg;
	size_t thisarglen;
	size_t pos;
	int result;

	/* Begin the stack at the passed in top. */
	ustack = *ustackp;

	/*
	 * Allocate space.
	 *
	 * buf->pos is the amount of space used by the strings; put that
	 * first, then align the stack, then make space for the argv
	 * pointers. Allow an extra slot for the ending NULL.
	 */

	ustack -= buf->len;
	ustack -= (ustack & (sizeof(void *) - 1));
	ustringbase = (userptr_t)ustack;

	ustack -= (buf->nargs + 1) * sizeof(userptr_t);
	uargvbase = (userptr_t)ustack;

	/* Now copy the data out. */
	pos = 0;
	uargv_i = uargvbase;
	while (pos < buf->len) {
		/* The user address of the string will be ustringbase + pos. */
		thisarg = ustringbase + pos;

		/* Place it in the argv array. */
		result = copyout(&thisarg, uargv_i, sizeof(thisarg));
		if (result) {
			return result;
		}

		/* Push out the string. */
		result = copyoutstr(buf->data + pos, thisarg,
				    buf->len - pos, &thisarglen);
		if (result) {
			return result;
		}

		/* thisarglen includes the \0 */
		pos += thisarglen;
		uargv_i += sizeof(thisarg);
	}
	/* Should have come out even... */
	KASSERT(pos == buf->len);

	/* Add the NULL. */
	thisarg = NULL;
	result = copyout(&thisarg, uargv_i, sizeof(userptr_t));
	if (result) {
		return result;
	}

	*ustackp = ustack;
	*argc_ret = buf->nargs;
	*uargv_ret = uargvbase;
	return 0;
}
/*
 * Copy an argv out of kernel space to user space.
 *
 * Note: ustackp is an in/out argument.
 */
Copy an argv out of kernel space to user space.
Note: ustackp is an in/out argument.
Copy an argv out of kernel space to user space . Note : ustackp is an in / out argument .
static
int
argbuf_copyout(struct argbuf *buf, vaddr_t *ustackp,
	       int *argc_ret, userptr_t *uargv_ret)
{
	vaddr_t ustack;
	userptr_t ustringbase, uargvbase, uargv_i;
	userptr_t thisarg;
	size_t thisarglen;
	size_t pos;
	int result;
	ustack = *ustackp;
	ustack -= buf->len;
	ustack -= (ustack & (sizeof(void *) - 1));
	ustringbase = (userptr_t)ustack;
	ustack -= (buf->nargs + 1) * sizeof(userptr_t);
	uargvbase = (userptr_t)ustack;
	pos = 0;
	uargv_i = uargvbase;
	while (pos < buf->len) {
		thisarg = ustringbase + pos;
		result = copyout(&thisarg, uargv_i, sizeof(thisarg));
		if (result) {
			return result;
		}
		result = copyoutstr(buf->data + pos, thisarg,
				    buf->len - pos, &thisarglen);
		if (result) {
			return result;
		}
		pos += thisarglen;
		uargv_i += sizeof(thisarg);
	}
	KASSERT(pos == buf->len);
	thisarg = NULL;
	result = copyout(&thisarg, uargv_i, sizeof(userptr_t));
	if (result) {
		return result;
	}
	*ustackp = ustack;
	*argc_ret = buf->nargs;
	*uargv_ret = uargvbase;
	return 0;
}
static int argbuf_copyout ( struct argbuf * buf , vaddr_t * ustackp , int * argc_ret , userptr_t * uargv_ret ) { vaddr_t ustack ; userptr_t ustringbase , uargvbase , uargv_i ; userptr_t thisarg ; size_t thisarglen ; size_t pos ; int result ; ustack = * ustackp ; ustack -= buf -> len ; ustack -= ( ustack & ( sizeof ( void * ) - 1 ) ) ; ustringbase = ( userptr_t ) ustack ; ustack -= ( buf -> nargs + 1 ) * sizeof ( userptr_t ) ; uargvbase = ( userptr_t ) ustack ; pos = 0 ; uargv_i = uargvbase ; while ( pos < buf -> len ) { thisarg = ustringbase + pos ; result = copyout ( & thisarg , uargv_i , sizeof ( thisarg ) ) ; if ( result ) { return result ; } result = copyoutstr ( buf -> data + pos , thisarg , buf -> len - pos , & thisarglen ) ; if ( result ) { return result ; } pos += thisarglen ; uargv_i += sizeof ( thisarg ) ; } KASSERT ( pos == buf -> len ) ; thisarg = NULL ; result = copyout ( & thisarg , uargv_i , sizeof ( userptr_t ) ) ; if ( result ) { return result ; } * ustackp = ustack ; * argc_ret = buf -> nargs ; * uargv_ret = uargvbase ; return 0 ; }
Copy an argv out of kernel space to user space.
Copy an argv out of kernel space to user space .
/* Begin the stack at the passed in top. */ /*
	 * Allocate space.
	 *
	 * buf->pos is the amount of space used by the strings; put that
	 * first, then align the stack, then make space for the argv
	 * pointers. Allow an extra slot for the ending NULL.
	 */ /* Now copy the data out. */ /* The user address of the string will be ustringbase + pos. */ /* Place it in the argv array. */ /* Push out the string. */ /* thisarglen includes the \0 */ /* Should have come out even... */ /* Add the NULL. */