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

📄 sys_parisc32.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls. * * Copyright (C) 2000-2001 Hewlett Packard Company * Copyright (C) 2000 John Marvin * Copyright (C) 2001 Matthew Wilcox * * These routines maintain argument size conversion between 32bit and 64bit * environment. Based heavily on sys_ia32.c and sys_sparc32.c. */#include <linux/config.h>#include <linux/compat.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/fs.h> #include <linux/mm.h> #include <linux/file.h> #include <linux/signal.h>#include <linux/resource.h>#include <linux/times.h>#include <linux/utsname.h>#include <linux/time.h>#include <linux/timex.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/sem.h>#include <linux/msg.h>#include <linux/shm.h>#include <linux/slab.h>#include <linux/uio.h>#include <linux/nfs_fs.h>#include <linux/ncp_fs.h>#include <linux/sunrpc/svc.h>#include <linux/nfsd/nfsd.h>#include <linux/nfsd/cache.h>#include <linux/nfsd/xdr.h>#include <linux/nfsd/syscall.h>#include <linux/poll.h>#include <linux/personality.h>#include <linux/stat.h>#include <linux/highmem.h>#include <linux/highuid.h>#include <linux/mman.h>#include <linux/binfmts.h>#include <linux/namei.h>#include <linux/vfs.h>#include <linux/ptrace.h>#include <linux/swap.h>#include <linux/syscalls.h>#include <asm/types.h>#include <asm/uaccess.h>#include <asm/semaphore.h>#include <asm/mmu_context.h>#include "sys32.h"#undef DEBUG#ifdef DEBUG#define DBG(x)	printk x#else#define DBG(x)#endif/* * sys32_execve() executes a new program. */asmlinkage int sys32_execve(struct pt_regs *regs){	int error;	char *filename;	DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));	filename = getname((const char __user *) regs->gr[26]);	error = PTR_ERR(filename);	if (IS_ERR(filename))		goto out;	error = compat_do_execve(filename, compat_ptr(regs->gr[25]),				 compat_ptr(regs->gr[24]), regs);	if (error == 0) {		task_lock(current);		current->ptrace &= ~PT_DTRACE;		task_unlock(current);	}	putname(filename);out:	return error;}asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,	int r22, int r21, int r20){    printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",     	current->comm, current->pid, r20);    return -ENOSYS;}#ifdef CONFIG_SYSCTLstruct __sysctl_args32 {	u32 name;	int nlen;	u32 oldval;	u32 oldlenp;	u32 newval;	u32 newlen;	u32 __unused[4];};asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args){	struct __sysctl_args32 tmp;	int error;	unsigned int oldlen32;	size_t oldlen, *oldlenp = NULL;	unsigned long addr = (((long __force)&args->__unused[0]) + 7) & ~7;	extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,	       void *newval, size_t newlen);	DBG(("sysctl32(%p)\n", args));	if (copy_from_user(&tmp, args, sizeof(tmp)))		return -EFAULT;	if (tmp.oldval && tmp.oldlenp) {		/* Duh, this is ugly and might not work if sysctl_args		   is in read-only memory, but do_sysctl does indirectly		   a lot of uaccess in both directions and we'd have to		   basically copy the whole sysctl.c here, and		   glibc's __sysctl uses rw memory for the structure		   anyway.  */		/* a possibly better hack than this, which will avoid the		 * problem if the struct is read only, is to push the		 * 'oldlen' value out to the user's stack instead. -PB		 */		if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))			return -EFAULT;		oldlen = oldlen32;		if (put_user(oldlen, (size_t *)addr))			return -EFAULT;		oldlenp = (size_t *)addr;	}	lock_kernel();	error = do_sysctl((int *)(u64)tmp.name, tmp.nlen, (void *)(u64)tmp.oldval,			  oldlenp, (void *)(u64)tmp.newval, tmp.newlen);	unlock_kernel();	if (oldlenp) {		if (!error) {			if (get_user(oldlen, (size_t *)addr)) {				error = -EFAULT;			} else {				oldlen32 = oldlen;				if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))					error = -EFAULT;			}		}		if (copy_to_user(&args->__unused[0], tmp.__unused, sizeof(tmp.__unused)))			error = -EFAULT;	}	return error;}#endif /* CONFIG_SYSCTL */asmlinkage long sys32_sched_rr_get_interval(pid_t pid,	struct compat_timespec __user *interval){	struct timespec t;	int ret;	KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t);	if (put_compat_timespec(&t, interval))		return -EFAULT;	return ret;}static intput_compat_timeval(struct compat_timeval __user *u, struct timeval *t){	struct compat_timeval t32;	t32.tv_sec = t->tv_sec;	t32.tv_usec = t->tv_usec;	return copy_to_user(u, &t32, sizeof t32);}static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i){	long usec;	if (__get_user(o->tv_sec, &i->tv_sec))		return -EFAULT;	if (__get_user(usec, &i->tv_usec))		return -EFAULT;	o->tv_nsec = usec * 1000;	return 0;}asmlinkage intsys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz){    extern void do_gettimeofday(struct timeval *tv);    if (tv) {	    struct timeval ktv;	    do_gettimeofday(&ktv);	    if (put_compat_timeval(tv, &ktv))		    return -EFAULT;    }    if (tz) {	    extern struct timezone sys_tz;	    if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))		    return -EFAULT;    }    return 0;}asmlinkage int sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz){	struct timespec kts;	struct timezone ktz; 	if (tv) {		if (get_ts32(&kts, tv))			return -EFAULT;	}	if (tz) {		if (copy_from_user(&ktz, tz, sizeof(ktz)))			return -EFAULT;	}	return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);}int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf){	int err;	if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||	    !new_valid_dev(stat->rdev))		return -EOVERFLOW;	err  = put_user(new_encode_dev(stat->dev), &statbuf->st_dev);	err |= put_user(stat->ino, &statbuf->st_ino);	err |= put_user(stat->mode, &statbuf->st_mode);	err |= put_user(stat->nlink, &statbuf->st_nlink);	err |= put_user(0, &statbuf->st_reserved1);	err |= put_user(0, &statbuf->st_reserved2);	err |= put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);	err |= put_user(stat->size, &statbuf->st_size);	err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);	err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);	err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);	err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);	err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);	err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);	err |= put_user(stat->blksize, &statbuf->st_blksize);	err |= put_user(stat->blocks, &statbuf->st_blocks);	err |= put_user(0, &statbuf->__unused1);	err |= put_user(0, &statbuf->__unused2);	err |= put_user(0, &statbuf->__unused3);	err |= put_user(0, &statbuf->__unused4);	err |= put_user(0, &statbuf->__unused5);	err |= put_user(0, &statbuf->st_fstype); /* not avail */	err |= put_user(0, &statbuf->st_realdev); /* not avail */	err |= put_user(0, &statbuf->st_basemode); /* not avail */	err |= put_user(0, &statbuf->st_spareshort);	err |= put_user(stat->uid, &statbuf->st_uid);	err |= put_user(stat->gid, &statbuf->st_gid);	err |= put_user(0, &statbuf->st_spare4[0]);	err |= put_user(0, &statbuf->st_spare4[1]);	err |= put_user(0, &statbuf->st_spare4[2]);	return err;}struct linux32_dirent {	u32		d_ino;	compat_off_t	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 __user * current_dir;	struct linux32_dirent __user * previous;	int count;	int error;};struct readdir32_callback {	struct old_linux32_dirent __user * dirent;	int count;};#define ROUND_UP(x,a)	((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))static intfilldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,	   unsigned int d_type){	struct linux32_dirent __user * 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);	dirent = ((void __user *)dirent) + reclen;	buf->current_dir = dirent;	buf->count -= reclen;	return 0;}asmlinkage longsys32_getdents (unsigned int fd, void __user * dirent, unsigned int count){	struct file * file;	struct linux32_dirent __user * lastdirent;	struct getdents32_callback buf;	int error;	error = -EBADF;	file = fget(fd);	if (!file)		goto out;	buf.current_dir = (struct linux32_dirent __user *) 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;

⌨️ 快捷键说明

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