Example #1
0
/** attach dataspace to our address space. */
int
attach_ds(l4dm_dataspace_t *ds, l4_uint32_t flags, l4_addr_t *addr)
{
  int error;
  l4_size_t size;
 
  if ((error = l4dm_mem_size(ds, &size)))
    {
      printf("Error %d (%s) getting size of dataspace\n",
	  error, l4env_errstr(error));
      return error;
    }
  
  if ((error = l4rm_attach(ds, size, 0, flags, addr)))
    {
      printf("Error %d (%s) attaching dataspace\n",
	  error, l4env_errstr(error));
      return error;
    }

  return 0;
}
Example #2
0
static void get_fb(void)
{
  l4_addr_t fpage_addr;
  l4_size_t fpage_size;
  l4dm_dataspace_t ds;
  CORBA_Environment env = dice_default_environment;
  int i, pages, error;
  struct stat st;

  /* check if we're running under L4Linux */
  if (stat("/proc/l4", &st) == -1) {
    fprintf(stderr, "Error: /proc/l4 doesn't exist, not running on L4Linux?!\n");
    exit(1);
  }

  /* ask for 'con' (timeout = 5000 ms) */
  if (names_waitfor_name(CON_NAMES_STR, &con_l4id, 5000) == 0) {
    fprintf(stderr, "PANIC: %s not registered at names", CON_NAMES_STR);
    exit(1);
  }
  INFO("Found my console through names, it's at "l4util_idfmt".\n",
       l4util_idstr(con_l4id));

  PRINT("Screenshot'ing, please smile... ;-)\n");
  /* get screenshot */
  if (con_if_screenshot_call(&con_l4id, get_vc, &ds, 
			&xres, &yres, &bpp, &env)) {
    fprintf(stderr, "Could not get screenshot\n");
    exit(1);
  }
  INFO("Got screenshot: res: %dx%d, bpp: %d\n", xres, yres, bpp);

  if (l4dm_mem_size(&ds, &fb_size)) {
    fprintf(stderr, "Couldn't get size of data space\n");
    exit(1);
  }
  INFO("Size of data space: %d\n", fb_size);

  if ((fb_mem = malloc(fb_size)) == NULL) {
    fprintf(stderr, "Couldn't malloc %d Bytes of memory!\n", fb_size);
    exit(1);
  }
  raw_pic_size = xres*yres*3;
  if ((raw_pic_mem = malloc(raw_pic_size)) == NULL) {
    fprintf(stderr, "Couldn't malloc %d bytes of memory!\n", raw_pic_size);
    exit(1);
  }
  
  pages = fb_size / L4_PAGESIZE; // size is always a multiple of L4_PAGESIZE?
  for (i = 0; i < pages; i++) {
    /* unmap memory */
    l4_fpage_unmap(l4_fpage((l4_umword_t)map_page, L4_LOG2_PAGESIZE,
	  	   L4_FPAGE_RW, L4_MAP_ITEM_MAP),
                   L4_FP_FLUSH_PAGE|L4_FP_ALL_SPACES);

    /* page in L4 page */
    if ((error = l4dm_map_pages(&ds, i*L4_PAGESIZE, L4_PAGESIZE,
			        (l4_addr_t)map_page, L4_LOG2_PAGESIZE,
				0, L4DM_RO, &fpage_addr,&fpage_size)) < 0) {
      fprintf(stderr, "Error %d requesting ds %d at ds_manager "
	      l4util_idfmt"\n",
	  error, ds.id, l4util_idstr(ds.manager));
      l4dm_close(&ds);
      exit(error);
    }

    memcpy(fb_mem + i*L4_PAGESIZE, map_page, L4_PAGESIZE);
  }

  if (l4dm_close(&ds)) {
    fprintf(stderr, "Error on closing dataspace, expect memory leakage...\n");
  }
}