⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syscall.c~

📁 jos lab3代码
💻 C~
字号:
/* See COPYRIGHT for copyright information. */#include <inc/x86.h>#include <inc/error.h>#include <inc/string.h>#include <inc/assert.h>#include <kern/env.h>#include <kern/pmap.h>#include <kern/trap.h>#include <kern/syscall.h>#include <kern/console.h>// Print a string to the system console.// The string is exactly 'len' characters long.// Destroys the environment on memory errors.static voidsys_cputs(const char *s, size_t len){	// Check that the user has permission to read memory [s, s+len).	// Destroy the environment if not.		// LAB 3: Your code here.	user_mem_assert(curenv, s, len, 0);		// Print the string supplied by the user.	cprintf("%.*s", len, s);}// Read a character from the system console.// Returns the character.static intsys_cgetc(void){	int c;	// The cons_getc() primitive doesn't wait for a character,	// but the sys_cgetc() system call does.	while ((c = cons_getc()) == 0)		/* do nothing */;	return c;}// Returns the current environment's envid.static envid_tsys_getenvid(void){	return curenv->env_id;}// Destroy a given environment (possibly the currently running environment).//// Returns 0 on success, < 0 on error.  Errors are://	-E_BAD_ENV if environment envid doesn't currently exist,//		or the caller doesn't have permission to change envid.static intsys_env_destroy(envid_t envid){	int r;	struct Env *e;	if ((r = envid2env(envid, &e, 1)) < 0)		return r;	if (e == curenv)		cprintf("[%08x] exiting gracefully\n", curenv->env_id);	else		cprintf("[%08x] destroying %08x\n", curenv->env_id, e->env_id);	env_destroy(e);	return 0;}// Dispatches to the correct kernel function, passing the arguments.int32_tsyscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5){	// Call the function corresponding to the 'syscallno' parameter.	// Return any appropriate return value.	// LAB 3: Your code here.	switch (syscallno)	{	case SYS_cputs:		sys_cputs((char *) a1, (size_t) a2);		return 0;	case SYS_cgetc:		return (int32_t) sys_cgetc();	case SYS_getenvid:		return (int32_t) sys_getenvid();	case SYS_env_destroy:		return (int32_t) sys_env_destroy((envid_t) a1);	default:		return -E_INVAL;	}	//panic("syscall not implemented");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -