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

📄 sys_ia32.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
}static inline longput_tv32(struct timeval32 *o, struct timeval *i){	return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||		(__put_user(i->tv_sec, &o->tv_sec) |		 __put_user(i->tv_usec, &o->tv_usec)));}static inline longget_it32(struct itimerval *o, struct itimerval32 *i){	return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||		(__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) |		 __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) |		 __get_user(o->it_value.tv_sec, &i->it_value.tv_sec) |		 __get_user(o->it_value.tv_usec, &i->it_value.tv_usec)));	return ENOSYS;}static inline longput_it32(struct itimerval32 *o, struct itimerval *i){	return (!access_ok(VERIFY_WRITE, i, sizeof(*i)) ||		(__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) |		 __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) |		 __put_user(i->it_value.tv_sec, &o->it_value.tv_sec) |		 __put_user(i->it_value.tv_usec, &o->it_value.tv_usec)));	return ENOSYS;}extern int do_getitimer(int which, struct itimerval *value);asmlinkage longsys32_getitimer(int which, struct itimerval32 *it){	struct itimerval kit;	int error;	error = do_getitimer(which, &kit);	if (!error && put_it32(it, &kit))		error = -EFAULT;	return error;}extern int do_setitimer(int which, struct itimerval *, struct itimerval *);asmlinkage longsys32_setitimer(int which, struct itimerval32 *in, struct itimerval32 *out){	struct itimerval kin, kout;	int error;	if (in) {		if (get_it32(&kin, in))			return -EFAULT;	} else		memset(&kin, 0, sizeof(kin));	error = do_setitimer(which, &kin, out ? &kout : NULL);	if (error || !out)		return error;	if (put_it32(out, &kout))		return -EFAULT;	return 0;}asmlinkage unsigned long sys32_alarm(unsigned int seconds){	struct itimerval it_new, it_old;	unsigned int oldalarm;	it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;	it_new.it_value.tv_sec = seconds;	it_new.it_value.tv_usec = 0;	do_setitimer(ITIMER_REAL, &it_new, &it_old);	oldalarm = it_old.it_value.tv_sec;	/* ehhh.. We can't return 0 if we have an alarm pending.. */	/* And we'd better return too much than too little anyway */	if (it_old.it_value.tv_usec)		oldalarm++;	return oldalarm;}/* Translations due to time_t size differences.  Which affects all   sorts of things, like timeval and itimerval.  */struct utimbuf_32 {	int	atime;	int	mtime;};extern asmlinkage long sys_utimes(char * filename, struct timeval * utimes);extern asmlinkage long sys_gettimeofday (struct timeval *tv, struct timezone *tz);asmlinkage longia32_utime(char * filename, struct utimbuf_32 *times32){	mm_segment_t old_fs = get_fs();	struct timeval tv[2];	long ret;	if (times32) {		get_user(tv[0].tv_sec, &times32->atime);		tv[0].tv_usec = 0;		get_user(tv[1].tv_sec, &times32->mtime);		tv[1].tv_usec = 0;		set_fs (KERNEL_DS);	} else {		set_fs (KERNEL_DS);		ret = sys_gettimeofday(&tv[0], 0);		if (ret < 0)			goto out;		tv[1] = tv[0];	}	ret = sys_utimes(filename, tv);  out:	set_fs (old_fs);	return ret;}extern struct timezone sys_tz;extern int do_sys_settimeofday(struct timeval *tv, struct timezone *tz);asmlinkage longsys32_gettimeofday(struct timeval32 *tv, struct timezone *tz){	if (tv) {		struct timeval ktv;		do_gettimeofday(&ktv);		if (put_tv32(tv, &ktv))			return -EFAULT;	}	if (tz) {		if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))			return -EFAULT;	}	return 0;}asmlinkage longsys32_settimeofday(struct timeval32 *tv, struct timezone *tz){	struct timeval ktv;	struct timezone ktz; 	if (tv) {		if (get_tv32(&ktv, tv))			return -EFAULT;	}	if (tz) {		if (copy_from_user(&ktz, tz, sizeof(ktz)))			return -EFAULT;	}	return do_sys_settimeofday(tv ? &ktv : NULL, tz ? &ktz : NULL);}struct linux32_dirent {	u32	d_ino;	u32	d_off;	u16	d_reclen;	char	d_name[1];};struct old_linux32_dirent {	u32	d_ino;	u32	d_offset;	u16	d_namlen;	char	d_name[1];};struct getdents32_callback {	struct linux32_dirent * current_dir;	struct linux32_dirent * previous;	int count;	int error;};struct readdir32_callback {	struct old_linux32_dirent * dirent;	int count;};static intfilldir32 (void *__buf, const char *name, int namlen, off_t offset, ino_t ino,	   unsigned int d_type){	struct linux32_dirent * dirent;	struct getdents32_callback * buf = (struct getdents32_callback *) __buf;	int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1, 4);	buf->error = -EINVAL;	/* only used if we fail.. */	if (reclen > buf->count)		return -EINVAL;	dirent = buf->previous;	if (dirent)		put_user(offset, &dirent->d_off);	dirent = buf->current_dir;	buf->previous = dirent;	put_user(ino, &dirent->d_ino);	put_user(reclen, &dirent->d_reclen);	copy_to_user(dirent->d_name, name, namlen);	put_user(0, dirent->d_name + namlen);	((char *) dirent) += reclen;	buf->current_dir = dirent;	buf->count -= reclen;	return 0;}asmlinkage longsys32_getdents (unsigned int fd, void * dirent, unsigned int count){	struct file * file;	struct linux32_dirent * lastdirent;	struct getdents32_callback buf;	int error;	error = -EBADF;	file = fget(fd);	if (!file)		goto out;	buf.current_dir = (struct linux32_dirent *) dirent;	buf.previous = NULL;	buf.count = count;	buf.error = 0;	error = vfs_readdir(file, filldir32, &buf);	if (error < 0)		goto out_putf;	error = buf.error;	lastdirent = buf.previous;	if (lastdirent) {		put_user(file->f_pos, &lastdirent->d_off);		error = count - buf.count;	}out_putf:	fput(file);out:	return error;}static intfillonedir32 (void * __buf, const char * name, int namlen, off_t offset, ino_t ino,	      unsigned int d_type){	struct readdir32_callback * buf = (struct readdir32_callback *) __buf;	struct old_linux32_dirent * dirent;	if (buf->count)		return -EINVAL;	buf->count++;	dirent = buf->dirent;	put_user(ino, &dirent->d_ino);	put_user(offset, &dirent->d_offset);	put_user(namlen, &dirent->d_namlen);	copy_to_user(dirent->d_name, name, namlen);	put_user(0, dirent->d_name + namlen);	return 0;}asmlinkage longsys32_readdir (unsigned int fd, void * dirent, unsigned int count){	int error;	struct file * file;	struct readdir32_callback buf;	error = -EBADF;	file = fget(fd);	if (!file)		goto out;	buf.count = 0;	buf.dirent = dirent;	error = vfs_readdir(file, fillonedir32, &buf);	if (error >= 0)		error = buf.count;	fput(file);out:	return error;}/* * We can actually return ERESTARTSYS instead of EINTR, but I'd * like to be certain this leads to no problems. So I return * EINTR just for safety. * * Update: ERESTARTSYS breaks at least the xview clock binary, so * I'm trying ERESTARTNOHAND which restart only when you want to. */#define MAX_SELECT_SECONDS \	((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)#define ROUND_UP_TIME(x,y) (((x)+(y)-1)/(y))asmlinkage longsys32_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval32 *tvp32){	fd_set_bits fds;	char *bits;	long timeout;	int ret, size;	timeout = MAX_SCHEDULE_TIMEOUT;	if (tvp32) {		time_t sec, usec;		get_user(sec, &tvp32->tv_sec);		get_user(usec, &tvp32->tv_usec);		ret = -EINVAL;		if (sec < 0 || usec < 0)			goto out_nofds;		if ((unsigned long) sec < MAX_SELECT_SECONDS) {			timeout = ROUND_UP_TIME(usec, 1000000/HZ);			timeout += sec * (unsigned long) HZ;		}	}	ret = -EINVAL;	if (n < 0)		goto out_nofds;	if (n > current->files->max_fdset)		n = current->files->max_fdset;	/*	 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),	 * since we used fdset we need to allocate memory in units of	 * long-words. 	 */	ret = -ENOMEM;	size = FDS_BYTES(n);	bits = kmalloc(6 * size, GFP_KERNEL);	if (!bits)		goto out_nofds;	fds.in      = (unsigned long *)  bits;	fds.out     = (unsigned long *) (bits +   size);	fds.ex      = (unsigned long *) (bits + 2*size);	fds.res_in  = (unsigned long *) (bits + 3*size);	fds.res_out = (unsigned long *) (bits + 4*size);	fds.res_ex  = (unsigned long *) (bits + 5*size);	if ((ret = get_fd_set(n, inp, fds.in)) ||	    (ret = get_fd_set(n, outp, fds.out)) ||	    (ret = get_fd_set(n, exp, fds.ex)))		goto out;	zero_fd_set(n, fds.res_in);	zero_fd_set(n, fds.res_out);	zero_fd_set(n, fds.res_ex);	ret = do_select(n, &fds, &timeout);	if (tvp32 && !(current->personality & STICKY_TIMEOUTS)) {		time_t sec = 0, usec = 0;		if (timeout) {			sec = timeout / HZ;			usec = timeout % HZ;			usec *= (1000000/HZ);		}		put_user(sec, (int *)&tvp32->tv_sec);		put_user(usec, (int *)&tvp32->tv_usec);	}	if (ret < 0)		goto out;	if (!ret) {		ret = -ERESTARTNOHAND;		if (signal_pending(current))			goto out;		ret = 0;	}	set_fd_set(n, inp, fds.res_in);	set_fd_set(n, outp, fds.res_out);	set_fd_set(n, exp, fds.res_ex);out:	kfree(bits);out_nofds:	return ret;}struct sel_arg_struct {	unsigned int n;	unsigned int inp;	unsigned int outp;	unsigned int exp;	unsigned int tvp;};asmlinkage longold_select(struct sel_arg_struct *arg){	struct sel_arg_struct a;	if (copy_from_user(&a, arg, sizeof(a)))		return -EFAULT;	return sys32_select(a.n, (fd_set *)A(a.inp), (fd_set *)A(a.outp), (fd_set *)A(a.exp),			    (struct timeval32 *)A(a.tvp));}struct timespec32 {	int 	tv_sec;	int	tv_nsec;};extern asmlinkage long sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp); asmlinkage longsys32_nanosleep(struct timespec32 *rqtp, struct timespec32 *rmtp){	struct timespec t;	int ret;	mm_segment_t old_fs = get_fs ();		if (get_user (t.tv_sec, &rqtp->tv_sec) ||	    __get_user (t.tv_nsec, &rqtp->tv_nsec))		return -EFAULT;	set_fs (KERNEL_DS);	ret = sys_nanosleep(&t, rmtp ? &t : NULL);	set_fs (old_fs);	if (rmtp && ret == -EINTR) {		if (__put_user (t.tv_sec, &rmtp->tv_sec) ||	    	    __put_user (t.tv_nsec, &rmtp->tv_nsec))			return -EFAULT;	}	return ret;}struct iovec32 { unsigned int iov_base; int iov_len; };asmlinkage ssize_t sys_readv(unsigned long,const struct iovec *,unsigned long);asmlinkage ssize_t sys_writev(unsigned long,const struct iovec *,unsigned long);static struct iovec *get_iovec32(struct iovec32 *iov32, struct iovec *iov_buf, u32 count, int type){	int i;	u32 buf, len;	struct iovec *ivp, *iov;	/* Get the "struct iovec" from user memory */	if (!count)		return 0;	if(verify_area(VERIFY_READ, iov32, sizeof(struct iovec32)*count))		return(struct iovec *)0;	if (count > UIO_MAXIOV)		return(struct iovec *)0;	if (count > UIO_FASTIOV) {		iov = kmalloc(count*sizeof(struct iovec), GFP_KERNEL);		if (!iov)			return((struct iovec *)0);	} else		iov = iov_buf;	ivp = iov;	for (i = 0; i < count; i++) {		if (__get_user(len, &iov32->iov_len) ||		    __get_user(buf, &iov32->iov_base)) {			if (iov != iov_buf)				kfree(iov);			return((struct iovec *)0);		}		if (verify_area(type, (void *)A(buf), len)) {			if (iov != iov_buf)				kfree(iov);			return((struct iovec *)0);		}		ivp->iov_base = (void *)A(buf);		ivp->iov_len = (__kernel_size_t)len;		iov32++;		ivp++;	}	return(iov);}asmlinkage longsys32_readv(int fd, struct iovec32 *vector, u32 count){	struct iovec iovstack[UIO_FASTIOV];	struct iovec *iov;	int ret;	mm_segment_t old_fs = get_fs();	if ((iov = get_iovec32(vector, iovstack, count, VERIFY_WRITE)) == (struct iovec *)0)		return -EFAULT;	set_fs(KERNEL_DS);	ret = sys_readv(fd, iov, count);	set_fs(old_fs);	if (iov != iovstack)		kfree(iov);	return ret;}asmlinkage longsys32_writev(int fd, struct iovec32 *vector, u32 count){	struct iovec iovstack[UIO_FASTIOV];	struct iovec *iov;	int ret;	mm_segment_t old_fs = get_fs();	if ((iov = get_iovec32(vector, iovstack, count, VERIFY_READ)) == (struct iovec *)0)		return -EFAULT;	set_fs(KERNEL_DS);	ret = sys_writev(fd, iov, count);	set_fs(old_fs);	if (iov != iovstack)		kfree(iov);	return ret;}#define RLIM_INFINITY32	0x7fffffff#define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)struct rlimit32 {	int	rlim_cur;	int	rlim_max;};extern asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit *rlim);asmlinkage longsys32_getrlimit(unsigned int resource, struct rlimit32 *rlim){	struct rlimit r;	int ret;	mm_segment_t old_fs = get_fs ();

⌨️ 快捷键说明

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