Example #1
0
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
	int pid = getpid ();
	self_sections_count = 0;
#if __APPLE__
	mach_port_t	task;
	kern_return_t	rc;
	rc = task_for_pid (mach_task_self(),pid, &task);	
	if (rc) {
		eprintf ("task_for_pid failed\n");
		return NULL;
	}
	macosx_debug_regions (task, (void*)(size_t)1, 1000);
	io->va = R_TRUE; // nop
	return r_io_desc_new (&r_io_plugin_self,
		pid, file, rw, mode, NULL);
#elif __linux__
	char *pos_c;
	char null[64];
	char path[1024], line[1024];
	char region[100], region2[100], perms[5];
	snprintf (path, sizeof (path)-1, "/proc/%d/maps", pid);
	FILE *fd = fopen (file, "r");
	if (!fd) 
		return NULL;

	while (!feof (fd)) {
		line[0]='\0';
		fgets (line, sizeof (line)-1, fd);
		if (line[0]=='\0')
			break;
		path[0]='\0';
		sscanf (line, "%s %s %s %s %s %s",
			&region[2], perms, null, null, null, path);
		pos_c = strchr (&region[2], '-');
		if (pos_c) strncpy (path, pos_c, sizeof (path)-1);
		else path[0] = 0;
		int i, perm = 0;
		for (i = 0; perms[i] && i < 4; i++)
			switch (perms[i]) {
			case 'r': perm |= R_IO_READ; break;
			case 'w': perm |= R_IO_WRITE; break;
			case 'x': perm |= R_IO_EXEC; break;
			}
		self_sections[self_sections_count].from = r_num_get (NULL, region);
		self_sections[self_sections_count].to = r_num_get (NULL, region2);
		self_sections[self_sections_count].perm = perm;
		self_sections_count++;
		r_num_get (NULL, region2);
		if (!pos_c)
			continue;
	}
	return r_io_desc_new (&r_io_plugin_self,
		pid, file, rw, mode, NULL);
#else
	#warning not yet implemented for this platform
#endif
	return NULL;
}
Example #2
0
void
info_mach_regions_command (char *exp, int from_tty)
{
  if ((!macosx_status) || (macosx_status->task == TASK_NULL))
    {
      error ("Inferior not available");
    }

  macosx_debug_regions (macosx_status->task, 0, -1);
}
Example #3
0
static int update_self_regions(int pid) {
	self_sections_count = 0;

#if __APPLE__
	mach_port_t	task;
	kern_return_t	rc;
	rc = task_for_pid (mach_task_self(),pid, &task);
	if (rc) {
		eprintf ("task_for_pid failed\n");
		return R_FALSE;
	}
	macosx_debug_regions (task, (size_t)1, 1000);

	return R_TRUE;
#elif __linux__
	char *pos_c;
	int i, l, perm;
	char null[64];
	char path[1024], line[1024];
	char region[100], region2[100], perms[5];
	snprintf (path, sizeof (path)-1, "/proc/%d/maps", pid);
	FILE *fd = fopen (path, "r");
	if (!fd)
		return R_FALSE;

	while (!feof (fd)) {
		line[0]='\0';
		fgets (line, sizeof (line)-1, fd);
		if (line[0]=='\0')
			break;
		path[0]='\0';
		sscanf (line, "%s %s %s %s %s %s",
			region+2, perms, null, null, null, path);
		memcpy (region, "0x", 2);
		pos_c = strchr (region+2, '-');
		if (pos_c) {
			*pos_c++ = 0;
			memcpy (region2, "0x", 2);
			l = strlen (pos_c);
			memcpy (region2+2, pos_c, l);
			region2[2+l] = 0;
		} else {
			region2[0] = 0;
		}
		perm = 0;
		for (i = 0; i < 4 && perms[i]; i++)
			switch (perms[i]) {
			case 'r': perm |= R_IO_READ; break;
			case 'w': perm |= R_IO_WRITE; break;
			case 'x': perm |= R_IO_EXEC; break;
			}
		self_sections[self_sections_count].from = r_num_get (NULL, region);
		self_sections[self_sections_count].to = r_num_get (NULL, region2);
		self_sections[self_sections_count].name = strdup (path);

		self_sections[self_sections_count].perm = perm;
		self_sections_count++;
		r_num_get (NULL, region2);
		if (!pos_c)
			continue;
	}
	fclose (fd);

	return R_TRUE;
#else
	#warning not yet implemented for this platform
	return R_FALSE;
#endif
}