⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 traps-linux.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
              if (result != 0)                break;              translate_endian((void *) &value, sizeof(value));              if ((s.write_mem) (cb, &s, arg2, (char *) &value, sizeof(value))                  != sizeof(value))                {                  result = -1;                  errcode = EINVAL;                }            }            break;          case __NR_stat:            {              char *buf;              int buflen;              struct stat statbuf;              result = stat((char *) t2h_addr(cb, &s, arg1), &statbuf);              errcode = errno;              if (result < 0)                break;              buflen = cb_host_to_target_stat (cb, NULL, NULL);              buf = xmalloc (buflen);              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)                {                  /* The translation failed.  This is due to an internal                     host program error, not the target's fault.  */                  free (buf);                  result = -1;                  errcode = ENOSYS;                  break;                }              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)                {                  free (buf);                  result = -1;                  errcode = EINVAL;                  break;                }              free (buf);            }            break;          case __NR_lstat:            {              char *buf;              int buflen;              struct stat statbuf;              result = lstat((char *) t2h_addr(cb, &s, arg1), &statbuf);              errcode = errno;              if (result < 0)                break;              buflen = cb_host_to_target_stat (cb, NULL, NULL);              buf = xmalloc (buflen);              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)                {                  /* The translation failed.  This is due to an internal                     host program error, not the target's fault.  */                  free (buf);                  result = -1;                  errcode = ENOSYS;                  break;                }              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)                {                  free (buf);                  result = -1;                  errcode = EINVAL;                  break;                }              free (buf);            }            break;          case __NR_fstat:            {              char *buf;              int buflen;              struct stat statbuf;              result = fstat(arg1, &statbuf);              errcode = errno;              if (result < 0)                break;              buflen = cb_host_to_target_stat (cb, NULL, NULL);              buf = xmalloc (buflen);              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)                {                  /* The translation failed.  This is due to an internal                     host program error, not the target's fault.  */                  free (buf);                  result = -1;                  errcode = ENOSYS;                  break;                }              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)                {                  free (buf);                  result = -1;                  errcode = EINVAL;                  break;                }              free (buf);            }            break;          case __NR_sysinfo:            {              struct sysinfo info;              result = sysinfo(&info);              errcode = errno;              if (result != 0)                break;              info.uptime    = conv_endian(info.uptime);              info.loads[0]  = conv_endian(info.loads[0]);              info.loads[1]  = conv_endian(info.loads[1]);              info.loads[2]  = conv_endian(info.loads[2]);              info.totalram  = conv_endian(info.totalram);              info.freeram   = conv_endian(info.freeram);              info.sharedram = conv_endian(info.sharedram);              info.bufferram = conv_endian(info.bufferram);              info.totalswap = conv_endian(info.totalswap);              info.freeswap  = conv_endian(info.freeswap);              info.procs     = conv_endian16(info.procs);#if LINUX_VERSION_CODE >= 0x20400              info.totalhigh = conv_endian(info.totalhigh);              info.freehigh  = conv_endian(info.freehigh);              info.mem_unit  = conv_endian(info.mem_unit);#endif              if ((s.write_mem) (cb, &s, arg1, (char *) &info, sizeof(info))                  != sizeof(info))                {                  result = -1;                  errcode = EINVAL;                }            }            break;#if 0          case __NR_ipc:            {              result = ipc(arg1, arg2, arg3, arg4,                           (void *) t2h_addr(cb, &s, arg5), arg6);              errcode = errno;            }            break;#endif          case __NR_fsync:            result = fsync(arg1);            errcode = errno;            break;          case __NR_uname:            /* utsname contains only arrays of char, so it is not necessary               to translate endian. */            result = uname((struct utsname *) t2h_addr(cb, &s, arg1));            errcode = errno;            break;          case __NR_adjtimex:            {              struct timex buf;              result = adjtimex(&buf);              errcode = errno;              if (result != 0)                break;              translate_endian((void *) &buf, sizeof(buf));              if ((s.write_mem) (cb, &s, arg1, (char *) &buf, sizeof(buf))                  != sizeof(buf))                {                  result = -1;                  errcode = EINVAL;                }            }            break;          case __NR_mprotect:            result = mprotect((void *) arg1, arg2, arg3);            errcode = errno;            break;          case __NR_fchdir:            result = fchdir(arg1);            errcode = errno;            break;          case __NR_setfsuid:            result = setfsuid(arg1);            errcode = errno;            break;          case __NR_setfsgid:            result = setfsgid(arg1);            errcode = errno;            break;#if 0          case __NR__llseek:            {              loff_t buf;              result = _llseek(arg1, arg2, arg3, &buf, arg5);              errcode = errno;              if (result != 0)                break;              translate_endian((void *) &buf, sizeof(buf));              if ((s.write_mem) (cb, &s, t2h_addr(cb, &s, arg4),                                 (char *) &buf, sizeof(buf)) != sizeof(buf))                {                  result = -1;                  errcode = EINVAL;                }            }            break;          case __NR_getdents:            {              struct dirent dir;              result = getdents(arg1, &dir, arg3);              errcode = errno;              if (result != 0)                break;              dir.d_ino = conv_endian(dir.d_ino);              dir.d_off = conv_endian(dir.d_off);              dir.d_reclen = conv_endian16(dir.d_reclen);              if ((s.write_mem) (cb, &s, arg2, (char *) &dir, sizeof(dir))                  != sizeof(dir))                {                  result = -1;                  errcode = EINVAL;                }            }            break;#endif          case __NR_flock:            result = flock(arg1, arg2);            errcode = errno;            break;          case __NR_msync:            result = msync((void *) arg1, arg2, arg3);            errcode = errno;            break;          case __NR_readv:            {              struct iovec vector;              vector = *((struct iovec *) t2h_addr(cb, &s, arg2));              translate_endian((void *) &vector, sizeof(vector));              result = readv(arg1, &vector, arg3);              errcode = errno;            }            break;          case __NR_writev:            {              struct iovec vector;              vector = *((struct iovec *) t2h_addr(cb, &s, arg2));              translate_endian((void *) &vector, sizeof(vector));              result = writev(arg1, &vector, arg3);              errcode = errno;            }            break;          case __NR_fdatasync:            result = fdatasync(arg1);            errcode = errno;            break;          case __NR_mlock:            result = mlock((void *) t2h_addr(cb, &s, arg1), arg2);            errcode = errno;            break;          case __NR_munlock:            result = munlock((void *) t2h_addr(cb, &s, arg1), arg2);            errcode = errno;            break;          case __NR_nanosleep:            {              struct timespec req, rem;              req = *((struct timespec *) t2h_addr(cb, &s, arg2));              translate_endian((void *) &req, sizeof(req));              result = nanosleep(&req, &rem);              errcode = errno;              if (result != 0)                break;              translate_endian((void *) &rem, sizeof(rem));              if ((s.write_mem) (cb, &s, arg2, (char *) &rem, sizeof(rem))                  != sizeof(rem))                {                  result = -1;                  errcode = EINVAL;                }            }            break;          case __NR_mremap: /* FIXME */            result = (int) mremap((void *) t2h_addr(cb, &s, arg1), arg2, arg3, arg4);             errcode = errno;            break;          case __NR_getresuid:            {              uid_t ruid, euid, suid;              result = getresuid(&ruid, &euid, &suid);              errcode = errno;              if (result != 0)                break;              *((uid_t *) t2h_addr(cb, &s, arg1)) = conv_endian(ruid);              *((uid_t *) t2h_addr(cb, &s, arg2)) = conv_endian(euid);              *((uid_t *) t2h_addr(cb, &s, arg3)) = conv_endian(suid);            }            break;          case __NR_poll:            {              struct pollfd ufds;              ufds = *((struct pollfd *) t2h_addr(cb, &s, arg1));              ufds.fd = conv_endian(ufds.fd);              ufds.events = conv_endian16(ufds.events);              ufds.revents = conv_endian16(ufds.revents);              result = poll(&ufds, arg2, arg3);              errcode = errno;            }            break;          case __NR_getresgid:            {              uid_t rgid, egid, sgid;              result = getresgid(&rgid, &egid, &sgid);              errcode = errno;              if (result != 0)                break;              *((uid_t *) t2h_addr(cb, &s, arg1)) = conv_endian(rgid);              *((uid_t *) t2h_addr(cb, &s, arg2)) = conv_endian(egid);              *((uid_t *) t2h_addr(cb, &s, arg3)) = conv_endian(sgid);            }            break;          case __NR_pread:            result =  pread(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4);             errcode = errno;            break;          case __NR_pwrite:            result =  pwrite(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4);             errcode = errno;            break;          case __NR_chown:            result = chown((char *) t2h_addr(cb, &s, arg1), arg2, arg3);            errcode = errno;            break;          case __NR_getcwd:            result = (int) getcwd((char *) t2h_addr(cb, &s, arg1), arg2);            errcode = errno;            break;          case __NR_sendfile:            {              off_t offset;              offset = *((off_t *) t2h_addr(cb, &s, arg3));              offset = conv_endian(offset);              result = sendfile(arg1, arg2, &offset, arg3);              errcode = errno;              if (result != 0)                break;              *((off_t *) t2h_addr(cb, &s, arg3)) = conv_endian(offset);            }            break;          default:            result = -1;            errcode = ENOSYS;            break;          }                if (result == -1)	  m32rbf_h_gr_set (current_cpu, 0, -errcode);        else	  m32rbf_h_gr_set (current_cpu, 0, result);	break;      }    case TRAP_BREAKPOINT:      sim_engine_halt (sd, current_cpu, NULL, pc,		       sim_stopped, SIM_SIGTRAP);      break;    case TRAP_FLUSH_CACHE:      /* Do nothing.  */      break;    default :      {	/* Use cr5 as EVB (EIT Vector Base) register.  */        USI new_pc = m32rbf_h_cr_get (current_cpu, 5) + 0x40 + num * 4;	return new_pc;      }    }  /* Fake an "rte" insn.  */  /* FIXME: Should duplicate all of rte processing.  */  return (pc & -4) + 4;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -