Exemplo n.º 1
0
GMM_EXPORT
void gmm_dump_dptr(const char *filepath, const void *dptr, const size_t size)
{
	struct region *r;

	if (!filepath) {
		gprint(DEBUG, "bad filepath for gmm_dump\n");
		return;
	}
	if (size <= 0) {
		gprint(DEBUG, "bad size for gmm_dump\n");
		return;
	}

	r = region_lookup(pcontext, dptr);
	if (!r) {
		gprint(DEBUG, "region lookup failed for %p in gmm_dump\n", dptr);
		return;
	}

	if (dptr + size > &(r->swp_addr) + r->size) {//potential bug
		gprint(DEBUG, "bad dump range for gmm_dump\n");
		return;
	}

	gmm_dump_region(filepath, r, dptr, size);
}
Exemplo n.º 2
0
// Print info of the region containing %dptr
GMM_EXPORT
void gmm_print_dptr(const void *dptr)
{
	struct region *r;

	r = region_lookup(pcontext, dptr);
	if (!r) {
		gprint(DEBUG, "failed to look up region containing %p\n", dptr);
		return;
	}
	gmm_print_region(r);
}
Exemplo n.º 3
0
/*
 * allocate_program_memory()
 *
 * This function attempts to allocate program memory sections.
 *
 * Called by: allocate_memory()
 *
 * Calls:     build_alloc_section_list()
 *            build_free_block_list()
 *            locate_sections()
 *            pic32_section_list_length()
 *
 * Returns:   status code
 *            (0 = success)
 */
static int
allocate_program_memory() {
  struct memory_region_struct *region;
  unsigned int mask = code;
  int result = 0;

  if (pic32_debug)
    printf("\nBuilding allocation list for region \"program\"\n"
           "  attribute mask = %x\n", mask);

  build_alloc_section_list(mask);
  if (pic32_section_list_length(alloc_section_list) == 0)
    return result;

  region = region_lookup ("kseg0_program_mem");
  build_free_block_list(region, mask);

  if (pic32_debug) {
    pic32_print_section_list(alloc_section_list, "allocation");
  }

#if 0
  if (pic32_debug)
    pic32_print_section_list(unassigned_sections, "unassigned");
#endif

  reset_locate_options();
  result |= locate_sections(address, 0, region);   /* most restrictive  */
  result |= locate_sections(all_attr, 0, region);  /* least restrictive */

  /* save the free blocks list */
  program_memory_free_blocks = free_blocks;
  free_blocks = 0;

  return result;
} /* allocate_program_memory() */
Exemplo n.º 4
0
/*
** Utility routine: bfd_pic30_report_memory_usage
**
** - print a section chart to file *fp
**/
static void
bfd_pic30_report_memory_usage (FILE *fp) {
  bfd_size_type max_heap, max_stack;
  lang_memory_region_type *region;
  struct pic30_section *s;
  int has_eedata = 0;

  /* clear the counters */
  actual_prog_memory_used = 0;
  actual_eedata_memory_used = 0;
  data_memory_used = 0;

  /* build an ordered list of output sections */
  pic30_init_section_list(&pic30_section_list);
  bfd_map_over_sections(output_bfd, &pic30_build_section_list, NULL);

  region = region_lookup("program");
  /* print code header */
  fprintf( fp, "\n\nProgram Memory  [Origin = 0x%lx, Length = 0x%lx]\n\n",
           region->origin, region->length);
  fprintf( fp, "section                    address   length (PC units)"
           "   length (bytes) (dec)\n");
  fprintf( fp, "-------                    -------   -----------------"
           "   --------------------\n");

  /* report code sections */
  for (s = pic30_section_list; s != NULL; s = s->next)
    if ((s->sec) && in_bounds(s->sec, region))
      bfd_pic30_report_program_sections (s->sec, fp);

  /* print code summary */
  fprintf( fp, "\n                     Total program memory used (bytes):"
           "     %#10lx  (%ld) ",
         actual_prog_memory_used, actual_prog_memory_used);
  report_percent_used((actual_prog_memory_used * 2)/3,
                      region->length, fp);
  fprintf( fp, "\n");
  
  /* the eedata report is optional */
  for (s = pic30_section_list; s != NULL; s = s->next)
    if ((s->sec) && PIC30_IS_EEDATA_ATTR(s->sec))
      has_eedata = 1;

  if (has_eedata) {
    region = region_lookup("eedata");
    /* print eedata header */
    fprintf( fp, "\n\nData EEPROM Memory  [Origin = 0x%lx, Length = 0x%lx]\n\n",
             region->origin, region->length);
    fprintf( fp, "section                    address   length (PC units)"
             "   length (bytes) (dec)\n");
    fprintf( fp, "-------                    -------   -----------------"
             "   --------------------\n");

    /* report eedata sections */
    for (s = pic30_section_list; s != NULL; s = s->next)
      if ((s->sec) && in_bounds(s->sec, region))
        bfd_pic30_report_eedata_sections (s->sec, fp);

    /* print eedata summary */
    fprintf( fp, "\n                        Total data EEPROM used (bytes):"
             "     %#10lx  (%ld) ",
             actual_eedata_memory_used, actual_eedata_memory_used);
  report_percent_used(actual_eedata_memory_used, region->length, fp);
  fprintf( fp, "\n");
  }

  /* print data header */
  region = region_lookup("data");
  fprintf( fp, "\n\nData Memory  [Origin = 0x%lx, Length = 0x%lx]\n\n",
           region->origin, region->length);
  fprintf( fp, "section                    address      alignment gaps"
           "    total length  (dec)\n");
  fprintf( fp, "-------                    -------      --------------"
           "    -------------------\n");

  /* report data sections */
  for (s = pic30_section_list; s != NULL; s = s->next)
    if ((s->sec) && in_bounds(s->sec, region))
      bfd_pic30_report_data_sections (s->sec, fp);

  /* print data summary */
  fprintf( fp, "\n                        Total data memory used (bytes):"
           "     %#10lx  (%ld) ",
         data_memory_used, data_memory_used);
  if (data_memory_used > 0)
    report_percent_used(data_memory_used, region->length, fp);
  fprintf( fp, "\n");

  /* print dynamic header */
  fprintf( fp, "\n\nDynamic Memory Usage\n\n");
  fprintf( fp, "region                     address                      "
           "maximum length  (dec)\n");
  fprintf( fp, "------                     -------                      "
           "---------------------\n");

  /* report dynamic regions */
  max_heap  = heap_limit - heap_base;
  fprintf( fp, "%-24s%#10x%#36lx  (%ld)\n", "heap",
           heap_base, max_heap, max_heap);

  if (user_defined_stack) {
    max_stack = 0;
    fprintf( fp, "(user-defined stack at 0x%x, length = 0x%x)\n",
             stack_base, (unsigned int) (stack_limit - stack_base));
  }
  else {
    max_stack = stack_limit - stack_base + pic30_stackguard_size;
    fprintf( fp, "%-24s%#10x%#36lx  (%ld)\n", "stack",
             stack_base, max_stack, max_stack);
  }

  /* print dynamic summary */
  fprintf( fp, "\n                        Maximum dynamic memory (bytes):"
           " %#14lx  (%ld)\n\n",
         (max_heap + max_stack), (max_heap + max_stack));

  /* report user-defined memory sections...
     they require some extra effort to organize by
     external memory region */
  if (has_user_defined_memory) {
    struct pic30_section *r, *rnext, *s;
    const char *region_name;
    /* loop through any user-defined regions */
    for (r = memory_region_list; r != NULL; r = rnext) {
  
      rnext = r->next;
      if (r->sec == 0) continue;
    
      region_name = r->sec->name + strlen(memory_region_prefix);
      fprintf( fp, "\nExternal Memory %s"
               "  [Origin = 0x%lx, Length = 0x%lx]\n\n",
                region_name, r->sec->vma, r->sec->lma);

      fprintf( fp, "section                    address                       "
               " total length  (dec)\n");
      fprintf( fp, "-------                    -------                       "
               " -------------------\n");

      external_memory_used = 0;
      for (s = pic30_section_list; s != NULL; s = s->next)
        if (s->sec)
          bfd_pic30_report_memory_sections (region_name, s->sec, fp);

      /* print summary for this region */
      fprintf( fp, "\n                    Total external memory used (bytes):"
               "     %#10lx  (%ld) ",
              external_memory_used, external_memory_used);
      if (external_memory_used > 0)
        report_percent_used(external_memory_used, r->sec->lma, fp);
      fprintf( fp, "\n\n");
    }
  }
  
  /* free the output section list */
  pic30_free_section_list(&pic30_section_list);

} /* static void bfd_pic30_report_memory_usage (...)*/
Exemplo n.º 5
0
isc_boolean_t
dns_geoip_match(const isc_netaddr_t *reqaddr, isc_uint8_t *scope,
		const dns_geoip_databases_t *geoip,
		const dns_geoip_elem_t *elt)
{
#ifndef HAVE_GEOIP
	UNUSED(reqaddr);
	UNUSED(geoip);
	UNUSED(elt);

	return (ISC_FALSE);
#else
	GeoIP *db;
	GeoIPRecord *record;
	GeoIPRegion *region;
	dns_geoip_subtype_t subtype;
	isc_uint32_t ipnum = 0;
	int maxlen = 0, id, family;
	const char *cs;
	char *s;
#ifdef HAVE_GEOIP_V6
	const geoipv6_t *ipnum6 = NULL;
#else
	const void *ipnum6 = NULL;
#endif

	INSIST(geoip != NULL);

	family = reqaddr->family;
	switch (family) {
	case AF_INET:
		ipnum = ntohl(reqaddr->type.in.s_addr);
		break;
	case AF_INET6:
#ifdef HAVE_GEOIP_V6
		ipnum6 = &reqaddr->type.in6;
		break;
#else
		return (ISC_FALSE);
#endif
	default:
		return (ISC_FALSE);
	}

	subtype = fix_subtype(reqaddr, geoip, elt->subtype);

	switch (subtype) {
	case dns_geoip_country_code:
		maxlen = 2;
		goto getcountry;

	case dns_geoip_country_code3:
		maxlen = 3;
		goto getcountry;

	case dns_geoip_country_name:
		maxlen = 255;
 getcountry:
		db = DB46(reqaddr, geoip, country);
		if (db == NULL)
			return (ISC_FALSE);

		INSIST(elt->as_string != NULL);

		cs = country_lookup(db, subtype, family, ipnum, ipnum6, scope);
		if (cs != NULL && strncasecmp(elt->as_string, cs, maxlen) == 0)
			return (ISC_TRUE);
		break;

	case dns_geoip_city_countrycode:
	case dns_geoip_city_countrycode3:
	case dns_geoip_city_countryname:
	case dns_geoip_city_region:
	case dns_geoip_city_regionname:
	case dns_geoip_city_name:
	case dns_geoip_city_postalcode:
	case dns_geoip_city_continentcode:
	case dns_geoip_city_timezonecode:
		INSIST(elt->as_string != NULL);

		db = DB46(reqaddr, geoip, city);
		if (db == NULL)
			return (ISC_FALSE);

		record = city_lookup(db, subtype, family,
				     ipnum, ipnum6, scope);
		if (record == NULL)
			break;

		s = city_string(record, subtype, &maxlen);
		INSIST(maxlen != 0);
		if (s != NULL && strncasecmp(elt->as_string, s, maxlen) == 0)
			return (ISC_TRUE);
		break;

	case dns_geoip_city_metrocode:
		db = DB46(reqaddr, geoip, city);
		if (db == NULL)
			return (ISC_FALSE);

		record = city_lookup(db, subtype, family,
				     ipnum, ipnum6, scope);
		if (record == NULL)
			break;

		if (elt->as_int == record->metro_code)
			return (ISC_TRUE);
		break;

	case dns_geoip_city_areacode:
		db = DB46(reqaddr, geoip, city);
		if (db == NULL)
			return (ISC_FALSE);

		record = city_lookup(db, subtype, family,
				     ipnum, ipnum6, scope);
		if (record == NULL)
			break;

		if (elt->as_int == record->area_code)
			return (ISC_TRUE);
		break;

	case dns_geoip_region_countrycode:
	case dns_geoip_region_code:
	case dns_geoip_region_name:
	case dns_geoip_region:
		if (geoip->region == NULL)
			return (ISC_FALSE);

		INSIST(elt->as_string != NULL);

		/* Region DB is not supported for IPv6 */
		if (family == AF_INET6)
			return (ISC_FALSE);

		region = region_lookup(geoip->region, subtype, ipnum, scope);
		if (region == NULL)
			break;

		s = region_string(region, subtype, &maxlen);
		INSIST(maxlen != 0);
		if (s != NULL && strncasecmp(elt->as_string, s, maxlen) == 0)
			return (ISC_TRUE);
		break;

	case dns_geoip_isp_name:
		db = geoip->isp;
		goto getname;

	case dns_geoip_org_name:
		db = geoip->org;
		goto getname;

	case dns_geoip_as_asnum:
		db = geoip->as;
		goto getname;

	case dns_geoip_domain_name:
		db = geoip->domain;

 getname:
		if (db == NULL)
			return (ISC_FALSE);

		INSIST(elt->as_string != NULL);
		/* ISP, Org, AS, and Domain are not supported for IPv6 */
		if (family == AF_INET6)
			return (ISC_FALSE);

		s = name_lookup(db, subtype, ipnum, scope);
		if (s != NULL) {
			size_t l;
			if (strcasecmp(elt->as_string, s) == 0)
				return (ISC_TRUE);
			if (subtype != dns_geoip_as_asnum)
				break;
			/*
			 * Just check if the ASNNNN value matches.
			 */
			l = strlen(elt->as_string);
			if (l > 0U && strchr(elt->as_string, ' ') == NULL &&
			    strncasecmp(elt->as_string, s, l) == 0 &&
			    s[l] == ' ')
				return (ISC_TRUE);
		}
		break;

	case dns_geoip_netspeed_id:
		INSIST(geoip->netspeed != NULL);

		/* Netspeed DB is not supported for IPv6 */
		if (family == AF_INET6)
			return (ISC_FALSE);

		id = netspeed_lookup(geoip->netspeed, subtype, ipnum, scope);
		if (id == elt->as_int)
			return (ISC_TRUE);
		break;

	case dns_geoip_countrycode:
	case dns_geoip_countrycode3:
	case dns_geoip_countryname:
	case dns_geoip_regionname:
		/*
		 * If these were not remapped by fix_subtype(),
		 * the database was unavailable. Always return false.
		 */
		break;

	default:
		INSIST(0);
	}

	return (ISC_FALSE);
#endif
}
Exemplo n.º 6
0
/*
 * allocate_data_memory()
 *
 * This function attempts to allocate data memory sections.
 *
 * Called by: allocate_memory()
 *
 * Calls:     build_section_list()
 *            build_free_block_list()
 *            locate_sections()
 *
 * Returns:   status code
 *            (0 = success)
 *
 * Notes: List "data_memory_free_blocks" is needed by
 *        bfd_pic322_finish() to allocate the stack
 *        and heap, so don't exit this function early.
 *
 *        EDS allocation is tricky. Although these sections
 *        can be allocated anywhere, we need to preserve
 *        low memory for the stack. In the first pass,
 *        we exclude memory below the stack limit altogether.
 *        In the second pass, we scan free blocks in reverse
 *        only, which helps when a block crosses the
 *        stack limit boundary. Eventually we'll take
 *        whatever memory we need to, and leave the rest
 *        for the stack and heap.
 *
 *        We also support allocation of stack and heap
 *        that are defined with section attributes.
 *
 *        See comments below for additional info
 *        about stack allocation.
 */
static int
allocate_data_memory() {
  struct memory_region_struct *region;
  struct pic32_section *s;
  unsigned int mask = data|bss|persist|stack|heap|ramfunc;
  int result = 0;

  if (pic32_debug)
    printf("\nBuilding allocation list for region \"data\"\n"
           "  attribute mask = %x\n", mask);

  build_alloc_section_list(mask);
  region = region_lookup ("kseg1_data_mem");

  build_free_block_list(region, mask);

  if (pic32_debug) {
    pic32_print_section_list(alloc_section_list, "allocation");
  }

  reset_locate_options();
  result |= locate_sections(ramfunc, 0, region);    /* most restrictive  */
  
  if (!bfd_pic32_is_defined_global_symbol("_ramfunc_begin"))
  {
    /* If there are no ram fumctions, add the _ramfunc_begin symbol with value 0 */
    _bfd_generic_link_add_one_symbol (&link_info, link_info.output_bfd, "_ramfunc_begin",
    BSF_GLOBAL, bfd_abs_section_ptr,
    0, "_ramfunc_begin", 1, 0, 0);
  }
  
  if (ramfunc_begin != 0) {
    set_locate_options(EXCLUDE_HIGH_ADDR, ramfunc_begin);
  }
  result |= locate_sections(address, 0, region);
  result |= locate_sections(near, 0, region);       /* less restrictive  */
  result |= locate_sections(all_attr, stack|heap, region);

#if 0
  /* user-defined heap */
  if (ramfunc_begin != 0) {
    set_locate_options(EXCLUDE_HIGH_ADDR, ramfunc_begin);
  }
  result |= locate_sections(heap, 0, region);

  /* user-defined stack */
  if (ramfunc_begin != 0) {
    set_locate_options(EXCLUDE_HIGH_ADDR, ramfunc_begin);
  }
  result |= locate_sections(stack, 0, region);
#else
  /* Don't support user-defined stack sections yet */
  for (s = alloc_section_list; s != NULL; s = s->next) {
    if (s->sec && (PIC32_IS_STACK_ATTR(s->sec) || PIC32_IS_HEAP_ATTR(s->sec))) {
      lang_output_section_statement_type *os;
      s->sec->lma = 0;
      s->sec->vma = 0;
      os = lang_output_section_statement_lookup (".stack", 0, TRUE);
      /* lang_add_section() will call init_os() if needed */
      lang_add_section (&os->children, s->sec, os);
      finish_section_info(s, os);
      pic32_remove_from_section_list(alloc_section_list,s);
      os->bfd_section->flags = s->sec->flags;
    }
  }

#endif

  /* if any sections are left in the allocation list, report an error */
  for (s = alloc_section_list; s != NULL; s = s->next) {
  if (s->attributes != 0) {
    report_allocation_error(s);
    result = 1;
    break;
  }
  }

  /* save the free blocks list */
  data_memory_free_blocks = free_blocks;
  free_blocks = 0;

  return result;
} /* allocate_data_memory() */