static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) { RIOMach *riom; int pid; task_t task; if (!__plugin_open (io, file)) return NULL; pid = atoi (file+(file[0]=='a'?9:7)); if (pid<1) return NULL; task = debug_attach (pid); if ((int)task == -1) { switch (errno) { case EPERM: eprintf ("Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; default: eprintf ("unknown error in debug_attach\n"); break; } return NULL; } riom = R_NEW (RIOMach); riom->pid = pid; riom->task = task; return r_io_desc_new (&r_io_plugin_mach, riom->pid, file, 1, mode, riom); }
/* * Initialize */ static int serial_init(void) { DPRINTF(("serial_init\n")); /* Initialize port */ if (port_init() == -1) return -1; #if defined(DEBUG) && defined(CONFIG_DIAG_SERIAL) debug_attach(diag_print); #endif tty_init(&serial_tty); /* init data */ serial_tty.t_oproc = serial_start; serial_tty.t_winsize.ws_row = (u_short)TERM_ROWS; serial_tty.t_winsize.ws_col = (u_short)TERM_COLS; serial_dev = tty_attach("console", &serial_tty); tty_dev = tty_attach("tty", &serial_tty); ASSERT(tty_dev); return 0; }
/* * Init */ static int console_init(void) { struct bootinfo *bootinfo; machine_bootinfo(&bootinfo); cols = bootinfo->video.text_x; rows = bootinfo->video.text_y; esc_index = 0; attrib = 0x0F; vram = phys_to_virt((void *)VID_RAM); reset_cursor(); #if defined(DEBUG) && defined(CONFIG_DIAG_SCREEN) debug_attach(console_puts); #endif tty_init(&console_tty); /* init data */ console_tty.t_oproc = console_start; console_tty.t_winsize.ws_row = (u_short)rows; console_tty.t_winsize.ws_col = (u_short)cols; console_dev = tty_attach("console", &console_tty); tty_dev = tty_attach("tty", &console_tty); ASSERT(tty_dev); return 0; }
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { RIODesc *ret = NULL; RIOMach *riom; const char *pidfile; char *pidpath, *endptr; int pid; task_t task; if (!__plugin_open (io, file, 0)) return NULL; pidfile = file + (file[0] == 'a' ? 9:7); pid = (int)strtol (pidfile, &endptr, 10); if (endptr == pidfile || pid < 0) return NULL; task = debug_attach (pid); if (task == -1) { return NULL; } if (!task) { if (pid > 0 && io->referer && !strncmp (io->referer, "dbg://", 6)) { eprintf ("Child killed\n"); kill (pid, 9); } switch (errno) { case EPERM: eprintf ("Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; default: eprintf ("unknown error in debug_attach\n"); break; } return NULL; } riom = R_NEW0 (RIOMach); riom->pid = pid; riom->task = task; // sleep 1s to get proper path (program name instead of ls) (racy) if (!pid) pidpath = strdup ("kernel"); else pidpath = r_sys_pid_to_path (pid); ret = r_io_desc_new (&r_io_plugin_mach, riom->pid, pidpath, rw | R_IO_EXEC, mode, riom); free (pidpath); return ret; }
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { RIODesc *ret = NULL; RIOMach *riom; const char *pidfile; char *pidpath; int pid; task_t task; if (!__plugin_open (io, file, 0)) return NULL; pidfile = file+(file[0]=='a'?9:7); if (!strcmp (pidfile, "0")) { /* tfp0 */ pid = 0; } else { pid = atoi (pidfile); if (pid<1) return NULL; } task = debug_attach (pid); if ((int)task == -1) { switch (errno) { case EPERM: eprintf ("Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; default: eprintf ("unknown error in debug_attach\n"); break; } return NULL; } riom = R_NEW0 (RIOMach); riom->pid = pid; riom->task = task; // sleep 1s to get proper path (program name instead of ls) (racy) pidpath = r_sys_pid_to_path (pid); ret = r_io_desc_new (&r_io_plugin_mach, riom->pid, pidpath, rw | R_IO_EXEC, mode, riom); free (pidpath); return ret; }