Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Feb 2005 18:25:01 -0500
From:      John Baldwin <jhb@FreeBSD.org>
To:        alpha@FreeBSD.org
Subject:   [PATCH] ABI changes, please test
Message-ID:  <200502071825.01946.jhb@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
Can folks test this patch on HEAD.  It fixes various things with the Linux and 
OSF/1 compat ABIs similar to the changes I committed to ibcs2 and svr4 today:

--- //depot/projects/smpng/sys/alpha/linux/linux_machdep.c	2004/12/15 21:41:34
+++ //depot/user/jhb/proc/alpha/linux/linux_machdep.c	2005/02/02 22:25:59
@@ -31,7 +31,9 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/imgact.h>
 #include <sys/lock.h>
+#include <sys/malloc.h>
 #include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/mutex.h>
@@ -64,20 +66,23 @@
 int
 linux_execve(struct thread *td, struct linux_execve_args *args)
 {
-	struct execve_args bsd;
-	caddr_t sg;
+	struct image_args eargs;
+	char *path;
+	int error;
 
-	sg = stackgap_init();
-	CHECKALTEXIST(td, &sg, args->path);
+	LCONVPATHEXIST(td, args->path, &path);
 
 #ifdef DEBUG
 	if (ldebug(execve))
-		printf(ARGS(execve, "%s"), args->path);
+		printf(ARGS(execve, "%s"), path);
 #endif
-	bsd.fname = args->path;
-	bsd.argv = args->argp;
-	bsd.envv = args->envp;
-	return (execve(td, &bsd));
+	error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, args->argp,
+	    args->envp);
+	free(path, M_TEMP);
+	if (error == 0)
+		error = kern_execve(td, &eargs, NULL);
+	exec_free_args(&eargs);
+	return (error);
 }
 
 /*
--- //depot/projects/smpng/sys/alpha/osf1/osf1_misc.c	2005/01/05 22:38:38
+++ //depot/user/jhb/proc/alpha/osf1/osf1_misc.c	2005/02/02 22:25:59
@@ -95,6 +95,7 @@
 static int  osf2bsd_pathconf(int *);
 
 static const char osf1_emul_path[] = "/compat/osf1";
+
 /*
  * [ taken from the linux emulator ]
  * Search an alternate path before passing pathname arguments on
@@ -105,133 +106,12 @@
  * be in exists.
  */
 int
-osf1_emul_find(td, sgp, prefix, path, pbuf, cflag)
-	struct thread	*td;
-	caddr_t		*sgp;          /* Pointer to stackgap memory */
-	const char	*prefix;
-	char		*path;
-	char		**pbuf;
-	int		cflag;
+osf1_emul_find(struct thread *td, char *path, enum uio_seg pathseg,
+    char **pbuf, int create)
 {
-        int			error;
-        size_t			len, sz;
-        char			*buf, *cp, *ptr;
-	struct ucred		*ucred;
-        struct nameidata	nd;
-        struct nameidata	ndroot;
-        struct vattr		vat;
-        struct vattr		vatroot;
 
-	buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
-	*pbuf = path;
-
-	for (ptr = buf; (*ptr = *prefix) != '\0'; ptr++, prefix++)
-		continue;
-
-	sz = MAXPATHLEN - (ptr - buf);
-
-	/*
-	 * If sgp is not given then the path is already in kernel space
-	 */
-	if (sgp == NULL)
-		error = copystr(path, ptr, sz, &len);
-	else
-		error = copyinstr(path, ptr, sz, &len);
-
-	if (error) {
-		free(buf, M_TEMP);
-		return error;
-	}
-
-	if (*ptr != '/') {
-		free(buf, M_TEMP);
-		return EINVAL;
-	}
-
-	/*
-	 *  We know that there is a / somewhere in this pathname.
-	 *  Search backwards for it, to find the file's parent dir
-	 *  to see if it exists in the alternate tree. If it does,
-	 *  and we want to create a file (cflag is set). We don't
-	 *  need to worry about the root comparison in this case.
-	 */
-
-	if (cflag) {
-		for (cp = &ptr[len] - 1; *cp != '/'; cp--)
-			;
-		*cp = '\0';
-
-		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
-
-		if ((error = namei(&nd)) != 0) {
-			free(buf, M_TEMP);
-			return error;
-		}
-
-		*cp = '/';
-	} else {
-		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
-
-		if ((error = namei(&nd)) != 0) {
-			free(buf, M_TEMP);
-			return error;
-		}
-
-		/*
-		 * We now compare the vnode of the osf1_root to the one
-		 * vnode asked. If they resolve to be the same, then we
-		 * ignore the match so that the real root gets used.
-		 * This avoids the problem of traversing "../.." to find the
-		 * root directory and never finding it, because "/" resolves
-		 * to the emulation root directory. This is expensive :-(
-		 */
-		NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, osf1_emul_path,
-		    td);
-
-		if ((error = namei(&ndroot)) != 0) {
-			/* Cannot happen! */
-			free(buf, M_TEMP);
-			vrele(nd.ni_vp);
-			return error;
-		}
-
-		ucred = td->td_ucred;
-		if ((error = VOP_GETATTR(nd.ni_vp, &vat, ucred, td)) != 0) {
-			goto bad;
-		}
-
-		if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, ucred,
-		    td)) != 0) {
-			goto bad;
-		}
-
-		if (vat.va_fsid == vatroot.va_fsid &&
-		    vat.va_fileid == vatroot.va_fileid) {
-			error = ENOENT;
-			goto bad;
-		}
-
-	}
-	if (sgp == NULL)
-		*pbuf = buf;
-	else {
-		sz = &ptr[len] - buf;
-		*pbuf = stackgap_alloc(sgp, sz + 1);
-		error = copyout(buf, *pbuf, sz);
-		free(buf, M_TEMP);
-	}
-
-	vrele(nd.ni_vp);
-	if (!cflag)
-		vrele(ndroot.ni_vp);
-
-	return error;
-
-bad:
-	vrele(ndroot.ni_vp);
-	vrele(nd.ni_vp);
-	free(buf, M_TEMP);
-	return error;
+	return (kern_alternate_path(td, osf1_emul_path, path, pathseg, pbuf,
+	    create));
 }
 
 
@@ -240,21 +120,15 @@
 	struct thread *td;
 	struct osf1_open_args *uap;
 {
-	struct open_args /* {
-		syscallarg(char *) path;
-		syscallarg(int) flags;
-		syscallarg(int) mode;
-	} */ a;
-	caddr_t sg;
+	char *path;
+	int error;
 
-	sg = stackgap_init();
-	CHECKALTEXIST(td, &sg, uap->path);
+	CHECKALTEXIST(td, uap->path, &path);
 
-	a.path = uap->path;
-	a.flags = uap->flags;		/* XXX translate */
-	a.mode = uap->mode;
-
-	return open(td, &a);
+	/* XXX: translate flags */
+	error = kern_open(td, path, UIO_SYSSPACE, uap->flags, uap->mode);
+	free(path, M_TEMP);
+	return (error);
 }
 
 extern long totalphysmem;
@@ -608,22 +482,15 @@
 	struct thread *td;
 	struct osf1_stat_args *uap;
 {
-	int error;
 	struct stat sb;
 	struct osf1_stat osb;
-	struct nameidata nd;
-	caddr_t sg;
+	char *path;
+	int error;
 
-	sg = stackgap_init();
+	CHECKALTEXIST(td, uap->path, &path);
 
-	CHECKALTEXIST(td, &sg, uap->path);
-
-	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
-	    uap->path, td);
-	if ((error = namei(&nd)))
-		return (error);
-	error = vn_stat(nd.ni_vp, &sb, td->td_ucred, NOCRED, td);
-	vput(nd.ni_vp);
+	error = kern_stat(td, path, UIO_SYSSPACE, &sb);
+	free(path, M_TEMP);
 	if (error)
 		return (error);
 	cvtstat2osf1(&sb, &osb);
@@ -643,18 +510,13 @@
 {
 	struct stat sb;
 	struct osf1_stat osb;
+	char *path;
 	int error;
-	struct nameidata nd;
-	caddr_t sg = stackgap_init();
 
-	CHECKALTEXIST(td, &sg, uap->path);
+	CHECKALTEXIST(td, uap->path, &path);
 
-	NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE,
-	    uap->path, td);
-	if ((error = namei(&nd)))
-		return (error);
-	error = vn_stat(nd.ni_vp, &sb, td->td_ucred, NOCRED, td);
-	vput(nd.ni_vp);
+	error = kern_lstat(td, path, UIO_SYSSPACE, &sb);
+	free(path, M_TEMP);
 	if (error)
 		return (error);
 	cvtstat2osf1(&sb, &osb);
@@ -671,15 +533,13 @@
 	struct thread *td;
 	register struct osf1_fstat_args *uap;
 {
-	struct file *fp;
+	struct osf1_stat oub;
 	struct stat ub;
-	struct osf1_stat oub;
 	int error;
 
-	if ((error = fget(td, uap->fd, &fp)) != 0)
+	error = kern_fstat(td, uap->fd, &ub);
+	if (error)
 		return (error);
-	error = fo_stat(fp, &ub, td->td_ucred, td);
-	fdrop(fp, td);
 	cvtstat2osf1(&ub, &oub);
 	if (error == 0)
 		error = copyout((caddr_t)&oub, (caddr_t)uap->sb,
@@ -735,12 +595,13 @@
 	struct thread *td;
 	struct osf1_access_args *uap;
 {
-	caddr_t sg;
+	char *path;
+	int error;
 
-	sg = stackgap_init();
-	CHECKALTEXIST(td, &sg, uap->path);
-
-	return access(td, (struct access_args *)uap);
+	CHECKALTEXIST(td, uap->path, &path);
+	error = kern_access(td, path, UIO_SYSSPACE, uap->flags);
+	free(path, M_TEMP);
+	return (error);
 }
 
 
@@ -1239,17 +1100,13 @@
 	struct thread *td;
 	struct osf1_truncate_args *uap;
 {
-	caddr_t sg;
-	struct truncate_args a;
+	char *path;
+	int error;
 
-	sg = stackgap_init();
-        CHECKALTEXIST(td, &sg, uap->path);
-
-	a.path = uap->path;
-	a.pad = 0;
-	a.length = uap->length;
-
-	return truncate(td, &a);
+        CHECKALTEXIST(td, uap->path, &path);
+	error = kern_truncate(td, path, UIO_SYSSPACE, uap->length);
+	free(path, M_TEMP);
+	return (error);
 }
 
 
@@ -1309,11 +1166,15 @@
 	struct thread *td;
 	struct osf1_pathconf_args *uap;
 {
+	char *path;
+	int error;
 
 	if (osf2bsd_pathconf(&uap->name))
 		return (EINVAL);
-	else
-		return (pathconf(td, (void *)uap));
+	CHECKALTEXIST(td, uap->path, &path);
+	error = kern_pathconf(td, path, UIO_SYSSPACE, uap->name);
+	free(path, M_TEMP);
+	return (error);
 }
 
 
@@ -1397,17 +1258,19 @@
 	struct thread *td;
 	struct osf1_execve_args *uap;
 {
-	caddr_t sg;
-	struct execve_args ap;
+	struct image_args eargs;
+	char *path;
+	int error;
 
-	sg = stackgap_init();
-	CHECKALTEXIST(td, &sg, uap->path);
+	CHECKALTEXIST(td, uap->path, &path);
 
-	ap.fname = uap->path;
-	ap.argv = uap->argp;
-	ap.envv = uap->envp;
-
-	return execve(td, &ap);
+	error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
+	    uap->envp);
+	free(path, M_TEMP);
+	if (error == 0)
+		error = kern_execve(td, &eargs, NULL);
+	exec_free_args(&eargs);
+	return (error);
 }
 
 
@@ -1454,7 +1317,8 @@
 }
 
 
-int osf1_gettimeofday(td, uap)
+int
+osf1_gettimeofday(td, uap)
 	struct thread *td;
 	register struct osf1_gettimeofday_args *uap;
 {
@@ -1482,26 +1346,24 @@
 }
 
 
-int osf1_select(td, uap)
+int
+osf1_select(td, uap)
 	struct thread *td;
 	register struct osf1_select_args *uap;
 {
-	if (uap->tv) {
-		int error;
-		caddr_t sg;
-		struct osf1_timeval otv;
-		struct timeval tv;
+	struct osf1_timeval otv;
+	struct timeval tv, *tvp;
+	int error;
 
-		sg = stackgap_init();
-
-		if ((error=copyin((caddr_t)uap->tv,(caddr_t)&otv,sizeof(otv))))
-			return(error);
-		TV_CP(otv,tv);
-		uap->tv = stackgap_alloc(&sg, sizeof(struct timeval));
-		if ((error=copyout((caddr_t)&tv, (caddr_t)uap->tv,sizeof(tv))))
-			return(error);
-	}
-	return(select(td, (struct select_args *)uap));
+	if (uap->tv != NULL) {
+		error = copyin(uap->tv, &otv, sizeof(otv));
+		if (error)
+			return (error);
+		TV_CP(otv, tv);
+		tvp = &tv;
+	} else
+		tvp = NULL;
+	return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp));
 }
 
 
@@ -1510,43 +1372,27 @@
 	struct thread *td;
 	struct osf1_setitimer_args *uap;
 {
-
+	struct itimerval itv, oitv;
+	struct osf1_itimerval otv;
 	int error;
-	caddr_t old_oitv, sg;
-	struct itimerval itv;
-	struct osf1_itimerval otv;
 
-	error = 0;
-	old_oitv = (caddr_t)uap->oitv;
-	sg = stackgap_init();
-
-	if ((error = copyin((caddr_t)uap->itv,(caddr_t)&otv,sizeof(otv)))) {
+	error = copyin(uap->itv, &otv, sizeof(otv));
+	if (error) {
 		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-		return error;
+		return (error);
 	}
-	TV_CP(otv.it_interval,itv.it_interval);
-	TV_CP(otv.it_value,itv.it_value);
-	uap->itv = stackgap_alloc(&sg, sizeof(struct itimerval));
-	if ((error = copyout((caddr_t)&itv,(caddr_t)uap->itv,sizeof(itv)))) {
+	TV_CP(otv.it_interval, itv.it_interval);
+	TV_CP(otv.it_value, itv.it_value);
+	error = kern_setitimer(td, uap->which, &itv, &oitv);
+	if (error || uap->oitv == NULL)
+		return (error);
+
+	TV_CP(oitv.it_interval, otv.it_interval);
+	TV_CP(oitv.it_value, otv.it_value);
+	error = copyout(&otv, uap->oitv, sizeof(otv));
+	if (error)
 		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-		return error;
-	}
-	uap->oitv = stackgap_alloc(&sg, sizeof(struct itimerval));
-	if ((error = setitimer(td, (struct setitimer_args *)uap))) {
-		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-		return error;
-	}
-	if ((error = copyin((caddr_t)uap->oitv,(caddr_t)&itv,sizeof(itv)))) {
-		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-		return error;
-	}
-	TV_CP(itv.it_interval,otv.it_interval);
-	TV_CP(itv.it_value,otv.it_value);
-	if (old_oitv
-	    && (error = copyout((caddr_t)&otv, old_oitv, sizeof(otv)))) {
-		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-	}
-	return error;
+	return (error);
 }
 
 
@@ -1555,30 +1401,19 @@
 	struct thread *td;
 	struct osf1_getitimer_args *uap;
 {
-	int error;
-	caddr_t old_itv, sg;
 	struct itimerval itv;
 	struct osf1_itimerval otv;
+	int error;
 
-	error = 0;
-	old_itv = (caddr_t)uap->itv;
-	sg = stackgap_init();
-
-	uap->itv = stackgap_alloc(&sg, sizeof(struct itimerval));
-	if ((error = getitimer(td, (struct getitimer_args *)uap))) {
+	error = kern_getitimer(td, uap->which, &itv);
+	if (error)
+		return (error);
+	TV_CP(itv.it_interval, otv.it_interval);
+	TV_CP(itv.it_value, otv.it_value);
+	error = copyout(&otv, uap->itv, sizeof(otv));
+	if (error)
 		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-		return error;
-	}
-	if ((error = copyin((caddr_t)uap->itv,(caddr_t)&itv,sizeof(itv)))) {
-		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-		return error;
-	}
-	TV_CP(itv.it_interval,otv.it_interval);
-	TV_CP(itv.it_value,otv.it_value);
-	if ((error = copyout((caddr_t)&otv, old_itv, sizeof(otv)))) {
-		printf("%s(%d): error = %d\n", __FILE__, __LINE__, error);
-	}
-	return error;
+	return (error);
 }
 
 
--- //depot/projects/smpng/sys/alpha/osf1/osf1_mount.c	2005/01/05 22:38:38
+++ //depot/user/jhb/proc/alpha/osf1/osf1_mount.c	2005/02/02 22:25:59
@@ -52,6 +52,7 @@
 #include <sys/socketvar.h>
 #include <sys/domain.h>
 #include <sys/protosw.h>
+#include <sys/syscallsubr.h>
 #include <sys/namei.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
@@ -122,29 +123,15 @@
 	struct thread *td;
 	struct osf1_statfs_args *uap;
 {
+	struct osf1_statfs osfs;
+	struct statfs sf;
 	int error;
-	struct mount *mp;
-	struct statfs *sp;
-	struct osf1_statfs osfs;
-	struct nameidata nd;
 
-	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
-	if ((error = namei(&nd)))
-		return (error);
-	mp = nd.ni_vp->v_mount;
-	sp = &mp->mnt_stat;
-	vrele(nd.ni_vp);
-#ifdef MAC
-	error = mac_check_mount_stat(td->td_ucred, mp);
+	error = kern_statfs(td, uap->path, UIO_USERSPACE, &sf);
 	if (error)
 		return (error);
-#endif
-	if ((error = VFS_STATFS(mp, sp, td)))
-		return (error);
-	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
-	bsd2osf_statfs(sp, &osfs);
-	return copyout(&osfs, uap->buf, min(sizeof osfs,
-	    uap->len));
+	bsd2osf_statfs(&sf, &osfs);
+	return (copyout(&osfs, uap->buf, min(sizeof osfs, uap->len)));
 }
 
 int
@@ -152,31 +139,15 @@
 	struct thread *td;
 	struct osf1_fstatfs_args *uap;
 {
+	struct osf1_statfs osfs;
+	struct statfs sf;
 	int error;
-	struct file *fp;
-	struct mount *mp;
-	struct statfs *sp;
-	struct osf1_statfs osfs;
 
-	if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)))
-		return (error);
-	mp = fp->f_vnode->v_mount;
-#ifdef MAC
-	error = mac_check_mount_stat(td->td_ucred, mp);
-	if (error) {
-		fdrop(fp, td);
-		return (error);
-	}
-#endif
-	sp = &mp->mnt_stat;
-	error = VFS_STATFS(mp, sp, td);
-	fdrop(fp, td);
+	error = kern_fstatfs(td, uap->fd, &sf);
 	if (error)
 		return (error);
-	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
-	bsd2osf_statfs(sp, &osfs);
-	return copyout(&osfs, uap->buf, min(sizeof osfs,
-	    uap->len));
+	bsd2osf_statfs(&sf, &osfs);
+	return (copyout(&osfs, uap->buf, min(sizeof osfs, uap->len)));
 }
 
 int
--- //depot/projects/smpng/sys/alpha/osf1/osf1_util.h	2003/01/02 19:19:33
+++ //depot/user/jhb/proc/alpha/osf1/osf1_util.h	2005/02/01 23:18:12
@@ -60,19 +60,17 @@
 }
 
 
-extern const char osf1_emul_path[];
-int osf1_emul_find(struct thread *, caddr_t *, const char *, char *,
-			char **, int);
+int	osf1_emul_find(struct thread *td, char *path, enum uio_seg pathseg,
+	    char **pbuf, int create);
 
-#define CHECKALT(p, sgp, path, i)					\
+#define CHECKALT(td, upath, pathp, i)					\
 	do {								\
 		int _error;						\
 									\
-		_error = osf1_emul_find(p, sgp, osf1_emul_path, path,	\
-					&path, i);			\
-		if (_error == EFAULT)					\
+		_error = osf1_emul_find(td, upath, UIO_USERSPACE, pathp, i); \
+		if (*(pathp) == NULL)					\
 			return (_error);				\
 	} while (0)
 
-#define	CHECKALTEXIST(p, sgp, path) CHECKALT((p), (sgp), (path), 0)
-#define	CHECKALTCREAT(p, sgp, path) CHECKALT((p), (sgp), (path), 1)
+#define	CHECKALTEXIST(td, upath, pathp) CHECKALT((td), (upath), (pathp), 0)
+#define	CHECKALTCREAT(td, upath, pathp) CHECKALT((td), (upath), (pathp), 1)

-- 
John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200502071825.01946.jhb>