by shigemk2

当面は技術的なことしか書かない

gttyとstty

P399

カーネルランドにある端末の情報をユーザランドに書き込むのがgtty

逆にユーザランドにある端末の情報をカーネルランドに書き込むのがstty

書き込み先の指定はsgtty関数で行う(処理は丸投げ)

suwordはカーネル→ユーザ fuwordはユーザ→カーネル

dmr/tty.c

gtty

/*
 * The routine implementing the gtty system call.
 * Just call lower level routine and pass back values.
 */
gtty()
{
    /* gttyシステムコールで読み出すデータを指定する */
    /* ユーザランドのポインタだからupはわかるけど、vpのvってなんだ。vectorか */
    int v[3];
    register *up, *vp;

    vp = v;
    sgtty(vp);
    if (u.u_error)
        return;
    /* 端末情報を読み出すユーザ空間中のアドレス */
    up = u.u_arg[0];
    suword(up, *vp++);
    suword(++up, *vp++);
    suword(++up, *vp++);
}

dmr/tty.c

stty

/*
 * The routine implementing the stty system call.
 * Read in values and call lower level.
 */
stty()
{
    register int *up;

    /* 端末情報を読み出すユーザ空間中のアドレス */
    up = u.u_arg[0];
    u.u_arg[0] = fuword(up);
    u.u_arg[1] = fuword(++up);
    u.u_arg[2] = fuword(++up);
    sgtty(0);
}

uとは

sys/user.h

uはグロ変

/*
 * The user structure.
 * One allocated per process.
 * Contains all per process data
 * that doesn't need to be referenced
 * while the process is swapped.
 * The user block is USIZE*64 bytes
 * long; resides at virtual kernel
 * loc 140000; contains the system
 * stack per user; is cross referenced
 * with the proc structure for the
 * same process.
 */
struct user
{
    int    u_rsav[2];     /* save r5,r6 when exchanging stacks */
    int    u_fsav[25];        /* save fp registers */
                    /* rsav and fsav must be first in structure */
    char   u_segflg;       /* flag for IO; user or kernel space */
    char   u_error;        /* return error code */
    char   u_uid;          /* effective user id */
    char   u_gid;          /* effective group id */
    char   u_ruid;         /* real user id */
    char   u_rgid;         /* real group id */
    int    u_procp;        /* pointer to proc structure */
    char   *u_base;        /* base address for IO */
    char   *u_count;       /* bytes remaining for IO */
    char   *u_offset[2];      /* offset in file for IO */
    int    *u_cdir;        /* pointer to inode of current directory */
    char   u_dbuf[DIRSIZ];     /* current pathname component */
    char   *u_dirp;        /* current pointer to inode */
    struct {           /* current directory entry */
        int    u_ino;
        char   u_name[DIRSIZ];
    } u_dent;
    int    *u_pdir;        /* inode of parent directory of dirp */
    int    u_uisa[16];        /* prototype of segmentation addresses */
    int    u_uisd[16];        /* prototype of segmentation descriptors */
    int    u_ofile[NOFILE];    /* pointers to file structures of open files */
    int    u_arg[5];      /* arguments to current system call */
    int    u_tsize;        /* text size (*64) */
    int    u_dsize;        /* data size (*64) */
    int    u_ssize;        /* stack size (*64) */
    int    u_sep;          /* flag for I and D separation */
    int    u_qsav[2];     /* label variable for quits and interrupts */
    int    u_ssav[2];     /* label variable for swapping */
    int    u_signal[NSIG];     /* disposition of signals */
    int    u_utime;        /* this process user time */
    int    u_stime;        /* this process system time */
    int    u_cutime[2];       /* sum of childs' utimes */
    int    u_cstime[2];       /* sum of childs' stimes */
    int    *u_ar0;         /* address of users saved R0 */
    int    u_prof[4];     /* profile arguments */
    char   u_intflg;       /* catch intr from sys */
                    /* kernel stack per user
                    * extends from u + USIZE*64
                    * backward not to reach here
                    */
} u;