Go with the flow; use `/emul/sunos' pseudo-root (from Matthew Green).

Note: sunos_stat() and sunos_lstat() were added too.
This commit is contained in:
pk 1995-06-11 22:33:50 +00:00
parent 769310e81d
commit 1e070197f4
10 changed files with 319 additions and 26 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.sunos,v 1.1 1995/04/27 12:05:37 christos Exp $
# $NetBSD: files.sunos,v 1.2 1995/06/11 22:33:50 pk Exp $
#
# Config.new file description for machine-independent SunOS compat code.
# Included by ports that need it.
@ -10,4 +10,5 @@ file compat/sunos/sunos_exec.c compat_sunos
file compat/sunos/sunos_sysent.c compat_sunos
file compat/sunos/sunos_ioctl.c compat_sunos
file compat/sunos/sunos_misc.c compat_sunos
file compat/sunos/sunos_util.c compat_sunos
#file compat/sunos/sunos_syscalls.c compat_sunos

View File

@ -1,4 +1,4 @@
/* $NetBSD: sunos_ioctl.c,v 1.18 1995/05/04 19:46:31 pk Exp $ */
/* $NetBSD: sunos_ioctl.c,v 1.19 1995/06/11 22:33:52 pk Exp $ */
/*
* Copyright (c) 1993 Markus Wild.
@ -677,7 +677,6 @@ sunos_ioctl(p, uap, retval)
sunos_aui.play = *(struct sunos_audio_prinfo *)&aui.play;
sunos_aui.record = *(struct sunos_audio_prinfo *)&aui.record;
sunos_aui.monitor_gain = aui.__spare; /* XXX */
/* `avail_ports' is `seek' in BSD */
#define AUDIO_SPEAKER 1
@ -689,6 +688,12 @@ sunos_ioctl(p, uap, retval)
sunos_aui.record.waiting = 0;
sunos_aui.play.eof = 0;
sunos_aui.record.eof = 0;
sunos_aui.monitor_gain = aui.__spare; /* XXX */
/*XXXsunos_aui.output_muted = 0;*/
/*XXX*/sunos_aui.reserved[0] = 0;
/*XXX*/sunos_aui.reserved[1] = 0;
/*XXX*/sunos_aui.reserved[2] = 0;
/*XXX*/sunos_aui.reserved[3] = 0;
return copyout ((caddr_t)&sunos_aui, SCARG(uap, data),
sizeof (sunos_aui));

View File

@ -1,4 +1,4 @@
/* $NetBSD: sunos_misc.c,v 1.47 1995/04/27 12:05:40 christos Exp $ */
/* $NetBSD: sunos_misc.c,v 1.48 1995/06/11 22:33:54 pk Exp $ */
/*
* Copyright (c) 1992, 1993
@ -83,6 +83,7 @@
#include <sys/syscallargs.h>
#include <compat/sunos/sunos.h>
#include <compat/sunos/sunos_syscallargs.h>
#include <compat/sunos/sunos_util.h>
#include <netinet/in.h>
@ -113,12 +114,51 @@ sunos_creat(p, uap, retval)
{
struct sunos_open_args ouap;
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
SCARG(&ouap, path) = SCARG(uap, path);
SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
SCARG(&ouap, mode) = SCARG(uap, mode);
return (open(p, &ouap, retval));
}
int
sunos_access(p, uap, retval)
struct proc *p;
struct sunos_access_args *uap;
register_t *retval;
{
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
return (access(p, uap, retval));
}
int
sunos_stat(p, uap, retval)
struct proc *p;
struct sunos_stat_args *uap;
register_t *retval;
{
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
return (compat_43_stat(p, uap, retval));
}
int
sunos_lstat(p, uap, retval)
struct proc *p;
struct sunos_lstat_args *uap;
register_t *retval;
{
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
return (compat_43_lstat(p, uap, retval));
}
int
sunos_execv(p, uap, retval)
struct proc *p;
@ -127,6 +167,9 @@ sunos_execv(p, uap, retval)
{
struct execve_args ouap;
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
SCARG(&ouap, path) = SCARG(uap, path);
SCARG(&ouap, argp) = SCARG(uap, argp);
SCARG(&ouap, envp) = NULL;
@ -165,11 +208,8 @@ sunos_mount(p, uap, retval)
register_t *retval;
{
int oflags = SCARG(uap, flags), nflags, error;
extern char sigcode[], esigcode[];
char fsname[MFSNAMELEN];
#define szsigcode (esigcode - sigcode)
if (oflags & (SUNM_NOSUB | SUNM_SYS5))
return (EINVAL);
if ((oflags & SUNM_NEWTYPE) == 0)
@ -581,6 +621,9 @@ sunos_open(p, uap, retval)
int noctty;
int ret;
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
/* convert mode into NetBSD mode */
l = SCARG(uap, flags);
noctty = l & 0x8000;
@ -707,6 +750,9 @@ sunos_statfs(p, uap, retval)
int error;
struct nameidata nd;
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
if (error = namei(&nd))
return (error);
@ -759,6 +805,9 @@ sunos_mknod(p, uap, retval)
struct sunos_mknod_args *uap;
register_t *retval;
{
caddr_t sg = stackgap_init();
CHECKALT(p, &sg, SCARG(uap, path));
if (S_ISFIFO(SCARG(uap, mode)))
return mkfifo(p, uap, retval);

View File

@ -30,11 +30,11 @@
#define SUNOS_SYS_setuid 23
#define SUNOS_SYS_getuid 24
#define SUNOS_SYS_sunos_ptrace 26
#define SUNOS_SYS_access 33
#define SUNOS_SYS_sunos_access 33
#define SUNOS_SYS_sync 36
#define SUNOS_SYS_kill 37
#define SUNOS_SYS_compat_43_stat 38
#define SUNOS_SYS_compat_43_lstat 40
#define SUNOS_SYS_sunos_stat 38
#define SUNOS_SYS_sunos_lstat 40
#define SUNOS_SYS_dup 41
#define SUNOS_SYS_pipe 42
#define SUNOS_SYS_profil 44

View File

@ -44,6 +44,21 @@ struct sunos_ptrace_args {
syscallarg(char *) addr2;
};
struct sunos_access_args {
syscallarg(char *) path;
syscallarg(int) flags;
};
struct sunos_stat_args {
syscallarg(char *) path;
syscallarg(struct ostat *) ub;
};
struct sunos_lstat_args {
syscallarg(char *) path;
syscallarg(struct ostat *) ub;
};
struct sunos_mctl_args {
syscallarg(caddr_t) addr;
syscallarg(int) len;

View File

@ -39,14 +39,14 @@ char *sunos_syscallnames[] = {
"#30 (unimplemented sunos_utime)", /* 30 = unimplemented sunos_utime */
"#31 (unimplemented sunos_stty)", /* 31 = unimplemented sunos_stty */
"#32 (unimplemented sunos_gtty)", /* 32 = unimplemented sunos_gtty */
"access", /* 33 = access */
"sunos_access", /* 33 = sunos_access */
"#34 (unimplemented sunos_nice)", /* 34 = unimplemented sunos_nice */
"#35 (unimplemented sunos_ftime)", /* 35 = unimplemented sunos_ftime */
"sync", /* 36 = sync */
"kill", /* 37 = kill */
"compat_43_stat", /* 38 = compat_43_stat */
"sunos_stat", /* 38 = sunos_stat */
"#39 (unimplemented sunos_setpgrp)", /* 39 = unimplemented sunos_setpgrp */
"compat_43_lstat", /* 40 = compat_43_lstat */
"sunos_lstat", /* 40 = sunos_lstat */
"dup", /* 41 = dup */
"pipe", /* 42 = pipe */
"#43 (unimplemented sunos_times)", /* 43 = unimplemented sunos_times */

View File

@ -34,11 +34,11 @@ int getpid();
int setuid();
int getuid();
int sunos_ptrace();
int access();
int sunos_access();
int sync();
int kill();
int compat_43_stat();
int compat_43_lstat();
int sunos_stat();
int sunos_lstat();
int dup();
int pipe();
int profil();
@ -310,8 +310,8 @@ struct sysent sunos_sysent[] = {
nosys }, /* 31 = unimplemented sunos_stty */
{ 0, 0,
nosys }, /* 32 = unimplemented sunos_gtty */
{ 2, s(struct access_args),
access }, /* 33 = access */
{ 2, s(struct sunos_access_args),
sunos_access }, /* 33 = sunos_access */
{ 0, 0,
nosys }, /* 34 = unimplemented sunos_nice */
{ 0, 0,
@ -320,12 +320,12 @@ struct sysent sunos_sysent[] = {
sync }, /* 36 = sync */
{ 2, s(struct kill_args),
kill }, /* 37 = kill */
{ 2, s(struct compat_43_stat_args),
compat_43_stat }, /* 38 = compat_43_stat */
{ 2, s(struct sunos_stat_args),
sunos_stat }, /* 38 = sunos_stat */
{ 0, 0,
nosys }, /* 39 = unimplemented sunos_setpgrp */
{ 2, s(struct compat_43_lstat_args),
compat_43_lstat }, /* 40 = compat_43_lstat */
{ 2, s(struct sunos_lstat_args),
sunos_lstat }, /* 40 = sunos_lstat */
{ 1, s(struct dup_args),
dup }, /* 41 = dup */
{ 0, 0,

View File

@ -0,0 +1,152 @@
/* $NetBSD: sunos_util.c,v 1.1 1995/06/11 22:34:04 pk Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/namei.h>
#include <sys/proc.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/filedesc.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/exec.h>
#include <compat/sunos/sunos_util.h>
const char sunos_emul_path[] = "/emul/sunos";
int
sunos_emul_find(p, sgp, prefix, path, pbuf)
struct proc * p;
caddr_t * sgp; /* Pointer to stackgap memory */
const char * prefix;
char * path;
char ** pbuf;
{
struct nameidata nd;
struct nameidata ndroot;
struct vattr vat;
struct vattr vatroot;
int error;
char *ptr, *buf;
size_t sz, len;
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) {
DPRINTF(("copy failed %d\n", error));
free(buf, M_TEMP);
return error;
}
DPRINTF(("looking for %s [%d, %d]: ", buf, sz, len));
if (*ptr != '/') {
DPRINTF(("no slash\n"));
free(buf, M_TEMP);
return EINVAL;
}
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p);
if ((error = namei(&nd)) != 0) {
DPRINTF(("not found\n"));
free(buf, M_TEMP);
return error;
}
/*
* We now compare the vnode of the sunos_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 :-(
*/
/* XXX: prototype should have const here for NDINIT */
NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE,
(char *) sunos_emul_path, p);
if ((error = namei(&ndroot)) != 0) {
/* Cannot happen! */
DPRINTF(("no %s!\n", sunos_emul_path));
free(buf, M_TEMP);
vrele(nd.ni_vp);
return error;
}
if ((error = VOP_GETATTR(nd.ni_vp, &vat, p->p_ucred, p)) != 0) {
DPRINTF(("no attr for directory\n"));
goto done;
}
if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, p->p_ucred, p)) != 0) {
DPRINTF(("no attr for root\n"));
goto done;
}
if (vat.va_fsid == vatroot.va_fsid &&
vat.va_fileid == vatroot.va_fileid) {
DPRINTF(("return the real root\n"));
error = ENOENT;
goto done;
}
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);
}
DPRINTF(("ok\n"));
done:
vrele(nd.ni_vp);
vrele(ndroot.ni_vp);
return error;
}

View File

@ -0,0 +1,71 @@
/* $NetBSD: sunos_util.h,v 1.1 1995/06/11 22:34:05 pk Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
* Copyright (c) 1995 Matthew Green
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _SUNOS_UTIL_H_
#define _SUNOS_UTIL_H_
#include <machine/vmparam.h>
extern char sigcode[], esigcode[];
#define szsigcode (esigcode - sigcode)
static __inline caddr_t
stackgap_init()
{
return STACKGAPBASE;
}
static __inline void *
stackgap_alloc(sgp, sz)
caddr_t *sgp;
size_t sz;
{
void *p = (void *) *sgp;
*sgp += ALIGN(sz);
return p;
}
#ifdef DEBUG_SUNOS
#define DPRINTF(a) printf a;
#else
#define DPRINTF(a)
#endif
extern const char sunos_emul_path[];
extern int sunos_error[];
int sunos_emul_find __P((struct proc *, caddr_t *,
const char *, char *, char **));
#define CHECKALT(p, sgp, path) \
sunos_emul_find(p, sgp, sunos_emul_path, path, &(path))
#endif /* !_SUNOS_UTIL_H_ */

View File

@ -1,4 +1,4 @@
$NetBSD: syscalls.master,v 1.26 1995/04/22 23:45:33 christos Exp $
$NetBSD: syscalls.master,v 1.27 1995/06/11 22:34:06 pk Exp $
; @(#)syscalls.master 8.1 (Berkeley) 7/19/93
@ -74,14 +74,14 @@
30 UNIMPL sunos_utime
31 UNIMPL sunos_stty
32 UNIMPL sunos_gtty
33 NOARGS { int access(char *path, int flags); }
33 STD { int sunos_access(char *path, int flags); }
34 UNIMPL sunos_nice
35 UNIMPL sunos_ftime
36 NOARGS { int sync(void); }
37 NOARGS { int kill(int pid, int signum); }
38 NOARGS { int compat_43_stat(char *path, struct ostat *ub); }
38 STD { int sunos_stat(char *path, struct ostat *ub); }
39 UNIMPL sunos_setpgrp
40 NOARGS { int compat_43_lstat(char *path, struct ostat *ub); }
40 STD { int sunos_lstat(char *path, struct ostat *ub); }
41 NOARGS { int dup(u_int fd); }
42 NOARGS { int pipe(void); }
43 UNIMPL sunos_times