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

📄 compat_linux.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  arch/s390x/kernel/linux32.c * *  S390 version *    Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com), *               Gerhard Tonn (ton@de.ibm.com)    *               Thomas Spatzier (tspat@de.ibm.com) * *  Conversion between 31bit and 64bit native syscalls. * * Heavily inspired by the 32-bit Sparc compat code which is  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) * */#include <linux/config.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/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/quota.h>#include <linux/module.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/filter.h>#include <linux/highmem.h>#include <linux/highuid.h>#include <linux/mman.h>#include <linux/ipv6.h>#include <linux/in.h>#include <linux/icmpv6.h>#include <linux/syscalls.h>#include <linux/sysctl.h>#include <linux/binfmts.h>#include <linux/compat.h>#include <linux/vfs.h>#include <linux/ptrace.h>#include <asm/types.h>#include <asm/ipc.h>#include <asm/uaccess.h>#include <asm/semaphore.h>#include <net/scm.h>#include <net/sock.h>#include "compat_linux.h" /* For this source file, we want overflow handling. */#undef high2lowuid#undef high2lowgid#undef low2highuid#undef low2highgid#undef SET_UID16#undef SET_GID16#undef NEW_TO_OLD_UID#undef NEW_TO_OLD_GID#undef SET_OLDSTAT_UID#undef SET_OLDSTAT_GID#undef SET_STAT_UID#undef SET_STAT_GID#define high2lowuid(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)#define high2lowgid(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)#define low2highuid(uid) ((uid) == (u16)-1) ? (uid_t)-1 : (uid_t)(uid)#define low2highgid(gid) ((gid) == (u16)-1) ? (gid_t)-1 : (gid_t)(gid)#define SET_UID16(var, uid)	var = high2lowuid(uid)#define SET_GID16(var, gid)	var = high2lowgid(gid)#define NEW_TO_OLD_UID(uid)	high2lowuid(uid)#define NEW_TO_OLD_GID(gid)	high2lowgid(gid)#define SET_OLDSTAT_UID(stat, uid)	(stat).st_uid = high2lowuid(uid)#define SET_OLDSTAT_GID(stat, gid)	(stat).st_gid = high2lowgid(gid)#define SET_STAT_UID(stat, uid)		(stat).st_uid = high2lowuid(uid)#define SET_STAT_GID(stat, gid)		(stat).st_gid = high2lowgid(gid)asmlinkage long sys32_chown16(const char * filename, u16 user, u16 group){	return sys_chown(filename, low2highuid(user), low2highgid(group));}asmlinkage long sys32_lchown16(const char * filename, u16 user, u16 group){	return sys_lchown(filename, low2highuid(user), low2highgid(group));}asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group){	return sys_fchown(fd, low2highuid(user), low2highgid(group));}asmlinkage long sys32_setregid16(u16 rgid, u16 egid){	return sys_setregid(low2highgid(rgid), low2highgid(egid));}asmlinkage long sys32_setgid16(u16 gid){	return sys_setgid((gid_t)gid);}asmlinkage long sys32_setreuid16(u16 ruid, u16 euid){	return sys_setreuid(low2highuid(ruid), low2highuid(euid));}asmlinkage long sys32_setuid16(u16 uid){	return sys_setuid((uid_t)uid);}asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid){	return sys_setresuid(low2highuid(ruid), low2highuid(euid),		low2highuid(suid));}asmlinkage long sys32_getresuid16(u16 *ruid, u16 *euid, u16 *suid){	int retval;	if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&	    !(retval = put_user(high2lowuid(current->euid), euid)))		retval = put_user(high2lowuid(current->suid), suid);	return retval;}asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid){	return sys_setresgid(low2highgid(rgid), low2highgid(egid),		low2highgid(sgid));}asmlinkage long sys32_getresgid16(u16 *rgid, u16 *egid, u16 *sgid){	int retval;	if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&	    !(retval = put_user(high2lowgid(current->egid), egid)))		retval = put_user(high2lowgid(current->sgid), sgid);	return retval;}asmlinkage long sys32_setfsuid16(u16 uid){	return sys_setfsuid((uid_t)uid);}asmlinkage long sys32_setfsgid16(u16 gid){	return sys_setfsgid((gid_t)gid);}static int groups16_to_user(u16 *grouplist, struct group_info *group_info){	int i;	u16 group;	for (i = 0; i < group_info->ngroups; i++) {		group = (u16)GROUP_AT(group_info, i);		if (put_user(group, grouplist+i))			return -EFAULT;	}	return 0;}static int groups16_from_user(struct group_info *group_info, u16 *grouplist){	int i;	u16 group;	for (i = 0; i < group_info->ngroups; i++) {		if (get_user(group, grouplist+i))			return  -EFAULT;		GROUP_AT(group_info, i) = (gid_t)group;	}	return 0;}asmlinkage long sys32_getgroups16(int gidsetsize, u16 *grouplist){	int i;	if (gidsetsize < 0)		return -EINVAL;	get_group_info(current->group_info);	i = current->group_info->ngroups;	if (gidsetsize) {		if (i > gidsetsize) {			i = -EINVAL;			goto out;		}		if (groups16_to_user(grouplist, current->group_info)) {			i = -EFAULT;			goto out;		}	}out:	put_group_info(current->group_info);	return i;}asmlinkage long sys32_setgroups16(int gidsetsize, u16 *grouplist){	struct group_info *group_info;	int retval;	if (!capable(CAP_SETGID))		return -EPERM;	if ((unsigned)gidsetsize > NGROUPS_MAX)		return -EINVAL;	group_info = groups_alloc(gidsetsize);	if (!group_info)		return -ENOMEM;	retval = groups16_from_user(group_info, grouplist);	if (retval) {		put_group_info(group_info);		return retval;	}	retval = set_current_groups(group_info);	put_group_info(group_info);	return retval;}asmlinkage long sys32_getuid16(void){	return high2lowuid(current->uid);}asmlinkage long sys32_geteuid16(void){	return high2lowuid(current->euid);}asmlinkage long sys32_getgid16(void){	return high2lowgid(current->gid);}asmlinkage long sys32_getegid16(void){	return high2lowgid(current->egid);}/* 32-bit timeval and related flotsam.  */static inline long get_tv32(struct timeval *o, struct compat_timeval *i){	return (!access_ok(VERIFY_READ, tv32, sizeof(*tv32)) ||		(__get_user(o->tv_sec, &i->tv_sec) ||		 __get_user(o->tv_usec, &i->tv_usec)));}static inline long put_tv32(struct compat_timeval *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)));}/* * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit emulation. * * This is really horribly ugly. */asmlinkage long sys32_ipc(u32 call, int first, int second, int third, u32 ptr){	if (call >> 16)		/* hack for backward compatibility */		return -EINVAL;	call &= 0xffff;	switch (call) {	case SEMTIMEDOP:		return compat_sys_semtimedop(first, compat_ptr(ptr),					     second, compat_ptr(third));	case SEMOP:		/* struct sembuf is the same on 32 and 64bit :)) */		return sys_semtimedop(first, compat_ptr(ptr),				      second, NULL);	case SEMGET:		return sys_semget(first, second, third);	case SEMCTL:		return compat_sys_semctl(first, second, third,					 compat_ptr(ptr));	case MSGSND:		return compat_sys_msgsnd(first, second, third,					 compat_ptr(ptr));	case MSGRCV:		return compat_sys_msgrcv(first, second, 0, third,					 0, compat_ptr(ptr));	case MSGGET:		return sys_msgget((key_t) first, second);	case MSGCTL:		return compat_sys_msgctl(first, second, compat_ptr(ptr));	case SHMAT:		return compat_sys_shmat(first, second, third,					0, compat_ptr(ptr));	case SHMDT:		return sys_shmdt(compat_ptr(ptr));	case SHMGET:		return sys_shmget(first, second, third);	case SHMCTL:		return compat_sys_shmctl(first, second, compat_ptr(ptr));	}	return -ENOSYS;}asmlinkage long sys32_truncate64(const char * path, unsigned long high, unsigned long low){	if ((int)high < 0)		return -EINVAL;	else		return sys_truncate(path, (high << 32) | low);}asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low){	if ((int)high < 0)		return -EINVAL;	else		return sys_ftruncate(fd, (high << 32) | low);}/* readdir & getdents */#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))#define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))struct old_linux_dirent32 {	u32		d_ino;	u32		d_offset;	unsigned short	d_namlen;	char		d_name[1];};struct readdir_callback32 {	struct old_linux_dirent32 * dirent;	int count;};static int fillonedir(void * __buf, const char * name, int namlen,		      loff_t offset, ino_t ino, unsigned int d_type){	struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;	struct old_linux_dirent32 * 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 long old32_readdir(unsigned int fd, struct old_linux_dirent32 *dirent, unsigned int count){	int error = -EBADF;	struct file * file;	struct readdir_callback32 buf;	file = fget(fd);	if (!file)		goto out;	buf.count = 0;	buf.dirent = dirent;	error = vfs_readdir(file, fillonedir, &buf);	if (error < 0)		goto out_putf;	error = buf.count;out_putf:	fput(file);out:	return error;}struct linux_dirent32 {	u32		d_ino;	u32		d_off;	unsigned short	d_reclen;	char		d_name[1];};

⌨️ 快捷键说明

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