📄 emul_unix.c
字号:
/* Solaris specific implementation */typedef signed32 solaris_uid_t;typedef signed32 solaris_gid_t;typedef signed32 solaris_off_t;typedef signed32 solaris_pid_t;typedef signed32 solaris_time_t;typedef unsigned32 solaris_dev_t;typedef unsigned32 solaris_ino_t;typedef unsigned32 solaris_mode_t;typedef unsigned32 solaris_nlink_t;#ifdef HAVE_SYS_STAT_H#define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */struct solaris_stat { solaris_dev_t st_dev; signed32 st_pad1[3]; /* reserved for network id */ solaris_ino_t st_ino; solaris_mode_t st_mode; solaris_nlink_t st_nlink; solaris_uid_t st_uid; solaris_gid_t st_gid; solaris_dev_t st_rdev; signed32 st_pad2[2]; solaris_off_t st_size; signed32 st_pad3; /* future off_t expansion */ struct unix_timeval st_atim; struct unix_timeval st_mtim; struct unix_timeval st_ctim; signed32 st_blksize; signed32 st_blocks; char st_fstype[SOLARIS_ST_FSTYPSZ]; signed32 st_pad4[8]; /* expansion area */};/* Convert from host stat structure to solaris stat structure */STATIC_INLINE_EMUL_UNIX voidconvert_to_solaris_stat(unsigned_word addr, struct stat *host, cpu *processor, unsigned_word cia){ struct solaris_stat target; int i; target.st_dev = H2T_4(host->st_dev); target.st_ino = H2T_4(host->st_ino); target.st_mode = H2T_4(host->st_mode); target.st_nlink = H2T_4(host->st_nlink); target.st_uid = H2T_4(host->st_uid); target.st_gid = H2T_4(host->st_gid); target.st_size = H2T_4(host->st_size);#ifdef HAVE_ST_RDEV target.st_rdev = H2T_4(host->st_rdev);#else target.st_rdev = 0;#endif#ifdef HAVE_ST_BLKSIZE target.st_blksize = H2T_4(host->st_blksize);#else target.st_blksize = 0;#endif#ifdef HAVE_ST_BLOCKS target.st_blocks = H2T_4(host->st_blocks);#else target.st_blocks = 0;#endif target.st_atim.tv_sec = H2T_4(host->st_atime); target.st_atim.tv_usec = 0; target.st_ctim.tv_sec = H2T_4(host->st_ctime); target.st_ctim.tv_usec = 0; target.st_mtim.tv_sec = H2T_4(host->st_mtime); target.st_mtim.tv_usec = 0; for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++) target.st_pad1[i] = 0; for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++) target.st_pad2[i] = 0; target.st_pad3 = 0; for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++) target.st_pad4[i] = 0; /* For now, just punt and always say it is a ufs file */ strcpy (target.st_fstype, "ufs"); emul_write_buffer(&target, addr, sizeof(target), processor, cia);}#endif /* HAVE_SYS_STAT_H */#ifndef HAVE_STAT#define do_solaris_stat 0#elsestatic voiddo_solaris_stat(os_emul_data *emul, unsigned call, const int arg0, cpu *processor, unsigned_word cia){ unsigned_word path_addr = cpu_registers(processor)->gpr[arg0]; unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1]; char path_buf[PATH_MAX]; struct stat buf; char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia); int status; if (WITH_TRACE && ppc_trace[trace_os_emul]) printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt); status = stat (path, &buf); if (status == 0) convert_to_solaris_stat (stat_pkt, &buf, processor, cia); emul_write_status(processor, status, errno);}#endif#ifndef HAVE_LSTAT#define do_solaris_lstat 0#elsestatic voiddo_solaris_lstat(os_emul_data *emul, unsigned call, const int arg0, cpu *processor, unsigned_word cia){ unsigned_word path_addr = cpu_registers(processor)->gpr[arg0]; unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1]; char path_buf[PATH_MAX]; struct stat buf; char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia); int status; if (WITH_TRACE && ppc_trace[trace_os_emul]) printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt); status = lstat (path, &buf); if (status == 0) convert_to_solaris_stat (stat_pkt, &buf, processor, cia); emul_write_status(processor, status, errno);}#endif#ifndef HAVE_FSTAT#define do_solaris_fstat 0#elsestatic voiddo_solaris_fstat(os_emul_data *emul, unsigned call, const int arg0, cpu *processor, unsigned_word cia){ int fildes = (int)cpu_registers(processor)->gpr[arg0]; unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1]; struct stat buf; int status; if (WITH_TRACE && ppc_trace[trace_os_emul]) printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt); status = fstat (fildes, &buf); if (status == 0) convert_to_solaris_stat (stat_pkt, &buf, processor, cia); emul_write_status(processor, status, errno);}#endif#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)#define SOLARIS_TIOC ('T'<<8)#define SOLARIS_NCC 8#define SOLARIS_NCCS 19#define SOLARIS_VINTR 0#define SOLARIS_VQUIT 1#define SOLARIS_VERASE 2#define SOLARIS_VKILL 3#define SOLARIS_VEOF 4#define SOLARIS_VEOL 5#define SOLARIS_VEOL2 6#define SOLARIS_VSWTCH 7#define SOLARIS_VSTART 8#define SOLARIS_VSTOP 9#define SOLARIS_VSUSP 10#define SOLARIS_VDSUSP 11#define SOLARIS_VREPRINT 12#define SOLARIS_VDISCARD 13#define SOLARIS_VWERASE 14#define SOLARIS_VLNEXT 15#endif#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)/* Convert to/from host termio structure */struct solaris_termio { unsigned16 c_iflag; /* input modes */ unsigned16 c_oflag; /* output modes */ unsigned16 c_cflag; /* control modes */ unsigned16 c_lflag; /* line discipline modes */ unsigned8 c_line; /* line discipline */ unsigned8 c_cc[SOLARIS_NCC]; /* control chars */};STATIC_INLINE_EMUL_UNIX voidconvert_to_solaris_termio(unsigned_word addr, struct termio *host, cpu *processor, unsigned_word cia){ struct solaris_termio target; int i; target.c_iflag = H2T_2 (host->c_iflag); target.c_oflag = H2T_2 (host->c_oflag); target.c_cflag = H2T_2 (host->c_cflag); target.c_lflag = H2T_2 (host->c_lflag);#if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE) target.c_line = host->c_line;#else target.c_line = 0;#endif for (i = 0; i < SOLARIS_NCC; i++) target.c_cc[i] = 0;#ifdef VINTR target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];#endif#ifdef VQUIT target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];#endif#ifdef VERASE target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];#endif#ifdef VKILL target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];#endif#ifdef VEOF target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];#endif#ifdef VEOL target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];#endif#ifdef VEOL2 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];#endif#ifdef VSWTCH target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];#else#ifdef VSWTC target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];#endif#endif emul_write_buffer(&target, addr, sizeof(target), processor, cia);}#endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */#ifdef HAVE_TERMIOS_STRUCTURE/* Convert to/from host termios structure */typedef unsigned32 solaris_tcflag_t;typedef unsigned8 solaris_cc_t;typedef unsigned32 solaris_speed_t;struct solaris_termios { solaris_tcflag_t c_iflag; solaris_tcflag_t c_oflag; solaris_tcflag_t c_cflag; solaris_tcflag_t c_lflag; solaris_cc_t c_cc[SOLARIS_NCCS];};STATIC_INLINE_EMUL_UNIX voidconvert_to_solaris_termios(unsigned_word addr, struct termios *host, cpu *processor, unsigned_word cia){ struct solaris_termios target; int i; target.c_iflag = H2T_4 (host->c_iflag); target.c_oflag = H2T_4 (host->c_oflag); target.c_cflag = H2T_4 (host->c_cflag); target.c_lflag = H2T_4 (host->c_lflag); for (i = 0; i < SOLARIS_NCCS; i++) target.c_cc[i] = 0;#ifdef VINTR target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];#endif#ifdef VQUIT target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];#endif#ifdef VERASE target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];#endif#ifdef VKILL target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];#endif#ifdef VEOF target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];#endif#ifdef VEOL target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];#endif#ifdef VEOL2 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];#endif#ifdef VSWTCH target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];#else#ifdef VSWTC target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];#endif#endif#ifdef VSTART target.c_cc[SOLARIS_VSTART] = host->c_cc[VSTART];#endif#ifdef VSTOP target.c_cc[SOLARIS_VSTOP] = host->c_cc[VSTOP];#endif#ifdef VSUSP target.c_cc[SOLARIS_VSUSP] = host->c_cc[VSUSP];#endif#ifdef VDSUSP target.c_cc[SOLARIS_VDSUSP] = host->c_cc[VDSUSP];#endif#ifdef VREPRINT target.c_cc[SOLARIS_VREPRINT] = host->c_cc[VREPRINT];#endif#ifdef VDISCARD target.c_cc[SOLARIS_VDISCARD] = host->c_cc[VDISCARD];#endif#ifdef VWERASE target.c_cc[SOLARIS_VWERASE] = host->c_cc[VWERASE];#endif#ifdef VLNEXT target.c_cc[SOLARIS_VLNEXT] = host->c_cc[VLNEXT];#endif emul_write_buffer(&target, addr, sizeof(target), processor, cia);}#endif /* HAVE_TERMIOS_STRUCTURE */#ifndef HAVE_IOCTL#define do_solaris_ioctl 0#elsestatic voiddo_solaris_ioctl(os_emul_data *emul, unsigned call, const int arg0, cpu *processor, unsigned_word cia){ int fildes = cpu_registers(processor)->gpr[arg0]; unsigned request = cpu_registers(processor)->gpr[arg0+1]; unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2]; int status = 0; const char *name = "<unknown>";#ifdef HAVE_TERMIOS_STRUCTURE struct termios host_termio;#else#ifdef HAVE_TERMIO_STRUCTURE struct termio host_termio;#endif#endif switch (request) { case 0: /* make sure we have at least one case */ default: status = -1; errno = EINVAL; break;#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)#if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR) case SOLARIS_TIOC | 1: /* TCGETA */ name = "TCGETA";#ifdef HAVE_TCGETATTR status = tcgetattr(fildes, &host_termio);#elif defined(TCGETS) status = ioctl (fildes, TCGETS, &host_termio);#else status = ioctl (fildes, TCGETA, &host_termio);#endif if (status == 0) convert_to_solaris_termio (argp_addr, &host_termio, processor, cia); break;#endif /* TCGETA */#endif /* HAVE_TERMIO_STRUCTURE */#ifdef HAVE_TERMIOS_STRUCTURE#if defined(TCGETS) || defined(HAVE_TCGETATTR) case SOLARIS_TIOC | 13: /* TCGETS */ name = "TCGETS";#ifdef HAVE_TCGETATTR status = tcgetattr(fildes, &host_termio);#else status = ioctl (fildes, TCGETS, &host_termio);#endif if (status == 0) convert_to_solaris_termios (argp_addr, &host_termio, processor, cia); break;#endif /* TCGETS */#endif /* HAVE_TERMIOS_STRUCTURE */ } emul_write_status(processor, status, errno); if (WITH_TRACE && ppc_trace[trace_os_emul]) printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);}#endif /* HAVE_IOCTL */static emul_syscall_descriptor solaris_descriptors[] = { /* 0 */ { 0, "syscall" }, /* 1 */ { do_unix_exit, "exit" }, /* 2 */ { 0, "fork" }, /* 3 */ { do_unix_read, "read" }, /* 4 */ { do_unix_write, "write" }, /* 5 */ { do_unix_open, "open" }, /* 6 */ { do_unix_close, "close" }, /* 7 */ { 0, "wait" }, /* 8 */ { 0, "creat" }, /* 9 */ { do_unix_link, "link" }, /* 10 */ { do_unix_unlink, "unlink" }, /* 11 */ { 0, "exec" }, /* 12 */ { do_unix_chdir, "chdir" }, /* 13 */ { do_unix_time, "time" }, /* 14 */ { 0, "mknod" }, /* 15 */ { 0, "chmod" }, /* 16 */ { 0, "chown" }, /* 17 */ { do_unix_break, "brk" }, /* 18 */ { do_solaris_stat, "stat" }, /* 19 */ { do_unix_lseek, "lseek" }, /* 20 */ { do_unix_getpid2, "getpid" }, /* 21 */ { 0, "mount" }, /* 22 */ { 0, "umount" }, /* 23 */ { 0, "setuid" }, /* 24 */ { do_unix_getuid2, "getuid" }, /* 25 */ { 0, "stime" }, /* 26 */ { 0, "ptrace" }, /* 27 */ { 0, "alarm" }, /* 28 */ { do_solaris_fstat, "fstat" }, /* 29 */ { 0, "pause" }, /* 30 */ { 0, "utime" }, /* 31 */ { 0, "stty" }, /* 32 */ { 0, "gtty" }, /* 33 */ { do_unix_access, "access" }, /* 34 */ { 0, "nice" }, /* 35 */ { 0, "statfs" }, /* 36 */ { 0, "sync" }, /* 37 */ { 0, "kill" }, /* 38 */ { 0, "fstatfs" }, /* 39 */ { 0, "pgrpsys" }, /* 40 */ { 0, "xenix" }, /* 41 */ { do_unix_dup, "dup" }, /* 42 */ { 0, "pipe" }, /* 43 */ { 0, "times" }, /* 44 */ { 0, "profil" },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -