code:user - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

0400 /*

0401  * The user structure.

0402  * One allocated per process.

0403  * Contains all per process data

0404  * that doesn’t need to be referenced

0405  * while the process is swapped.

0406  * The user block is USIZE*64 bytes

0407  * long; resides at virtual kernel

0408  * loc 140000; contains the system

0409  * stack per user; is cross referenced

0410  * with the proc structure for the

0411  * same process.

0412  */

0413 struct user

0414 {

0415 int u_rsav[2]; /* save r5,r6 when exchanging stacks */

0416 int u_fsav[25]; /* save fp registers */

0417          /* rsav and fsav must be first in structure */

0418 char u_segflg; /* flag for IO; user or kernel space */

  • 用于 声明 当前I/O 所使用的地址空间
0419 char u_error; /* return error code */
0420 char u_uid; /* effective user id */

0421 char u_gid; /* effective group id */

0422 char u_ruid; /* real user id */

0423 char u_rgid; /* real group id */

  • 分别为
    • 有效用户ID
    • 有效组ID
    • 真实用户ID
    • 真实组ID
  • 参看权限管理
0424 int u_procp; /* pointer to proc structure */
0425 char *u_base; /* base address for IO */
  • 当前 I/O 的基地址
0426 char *u_count; /* bytes remaining for IO */
  • 当前 I/O 的 剩余字节数
0427 char *u_offset[2]; /* offset in file for IO */
  • 当前 I/O 的 文件偏移量
0428 int *u_cdir; /* pointer to inode for current directory */
0429 char u_dbuf[DIRSIZ]; /* current pathname component */

0430 char *u_dirp; /* current pointer to inode */

  • namei 调用时, 指向 文件路径字符串
0431 struct { /* current directory entry */

0432      int u_ino;

0433      char u_name[DIRSIZ];

0434 } u_dent;

  • 当前目录项 的 信息
    • u_ino : 目录项对应的 INODE 号
    • u_name : 目录项的文件名
0435 int *u_pdir; /* inode of parent directory of dirp */
  • 指向 目录的父目录的INODE
0436 int u_uisa[16]; /* prototype segmentation addresses */

0437 int u_uisd[16]; /* prototype segmentation descriptors */

  • 与 UISA UISD 对应的相对地址映照表
  • 参看 内存管理
0438 int u_ofile[NOFILE]; /* pointers to file structures of

0439                open files */

0440 int u_arg[5]; /* arguments to current system call */
0441 int u_tsize; /* text size (*64) */

0442 int u_dsize; /* data size (*64) */

0443 int u_ssize; /* stack size (*64) */

  • 分别是进程的
    • 共享正文段 大小
    • 数据段 大小
    • 用户栈 大小
  • 都以 内存块 为单位(64字节/块)
  • 参看 进程图像
0444 int u_sep; /* flag for I and D separation */
  • 指令空间 和 数据空间 的 分离标志
  • 对于 pdp11/40 始终为0
0445 int u_qsav[2]; /* label variable for quits & interrupts */

0446 int u_ssav[2]; /* label variable for swapping */

0447 int u_signal[NSIG]; /* disposition of signals */

  • 信号处理函数 入口表
0448 int u_utime; /* this process user time */
0449 int u_stime; /* this process system time */
0450 int u_cutime[2]; /* sum of childs’ utimes */

0451 int u_cstime[2]; /* sum of childs’ stimes */

分别是
0452 int *u_ar0; /* address of users saved R0 */
关于u_ar0的使用,参考关于u_ar0的使用
0453 int u_prof[4]; /* profile arguments */
0454 char u_intflg; /* catch intr from sys */
  • 系统调用 出错标志
0455 /* kernel stack per user

0456  * extends from u + USIZE*64

0457  * backward not to reach here

0458  */

0459 } u;

0460 /* ------------------------- */

Ref

Caller

⚠️ **GitHub.com Fallback** ⚠️