예제 #1
0
void *
realloc(void * pointer, size_t size)
{
  void * (* libc_realloc)(void *, size_t) = (void *(*)(void *, size_t))dlsym(RTLD_NEXT, "realloc");
  if (enabled.load()) {
    return custom_realloc(pointer, size);
  }
  return libc_realloc(pointer, size);
}
예제 #2
0
파일: gc_alloc.cpp 프로젝트: 0xcc/pyston
extern "C" void* relloc(void* p, size_t sz) {
    static void *(*libc_realloc)(void*, size_t) = (void* (*)(void*, size_t))dlsym(RTLD_NEXT, "realloc");
    void* r = libc_realloc(p, sz);
    if (!recursive) {
        recursive = true;
        printf("\nrealloc %p %p\n", p, r);
        recursive = false;
    }
    return r;
}
예제 #3
0
파일: Profile.cpp 프로젝트: Gallaecio/0ad
void* realloc(void* ptr, size_t sz)
{
	cpu_AtomicAdd(&alloc_count, 1);

	static void *(*libc_realloc)(void*, size_t);
	if (libc_realloc == NULL)
	{
		alloc_has_called_dlsym = true;
		libc_realloc = (void *(*)(void*, size_t)) dlsym(RTLD_NEXT, "realloc");
	}
	void* ret = libc_realloc(ptr, sz);
#ifdef ALLOC_DEBUG
	printf("### realloc(%p, %d) = %p\n", ptr, sz, ret);
#endif
	return ret;
}
예제 #4
0
파일: contest-alloc.c 프로젝트: Yankkk/C
void *realloc(void *ptr, size_t size)
{
	if (inside_init)
		return libc_realloc(ptr, size);
	
	if (!alloc_handle)
		contest_alloc_init();

	void *addr;
	if (!ptr)
		addr = alloc_malloc(size);
	else if (size == 0)
	{	
		alloc_free(ptr);
		addr = NULL;
	}
	else
		addr = alloc_realloc(ptr, size);
	contest_tracking();

	return addr;
}
예제 #5
0
void *realloc(void *ptr, size_t size)
{
	void *p = NULL;

	if (libc_realloc == NULL)
		SAVE_LIBC_FUNC(libc_realloc, "realloc");

	init_env();

	// TODO: CHECK new heap size *before* allowing realloc
	if (mem_allocated <= mem_threshold) {
		p = libc_realloc(ptr, size);
	} else {
		errno = ENOMEM;
		return NULL;
	}

	if (!no_hook)
		account_realloc(p, ptr, size);

	return p;
}
예제 #6
0
/*
 * load a message catalog which specified with current locale,
 * and catalog name.
 */
static struct db_info *
load_db(const char *curloc, const char *catname, int *err)
{
	char pathname[PATH_MAX];
	struct	stat64 sb;
	caddr_t	addr;
	struct db_info *db;
	int fd;
	int i;

	*err = 0;

	/* First time called, allocate space */
	if (!db_info) {
		if ((db_info =
		    libc_malloc(MINDB * sizeof (struct db_info))) == NULL) {
			*err = 1;
			return (NULL);
		}
		maxdb = MINDB;
	}

	for (i = 0; i < db_count; i++) {
		if (db_info[i].flag == 0)
			break;
	}
	/* New catalogue */
	if (i == db_count) {
		if (db_count == maxdb) {
			if ((db = libc_realloc(db_info,
			    ++maxdb * sizeof (struct db_info))) == NULL) {
				*err = 1;
				return (NULL);
			}
			db_info = db;
		}
		db_count++;
	}
	db = &db_info[i];
	db->flag = 0;
	(void) strcpy(db->db_name, catname);
	db->saved_locale = libc_strdup(curloc);
	if (db->saved_locale == NULL) {
		*err = 1;
		return (NULL);
	}
	db->flag = DB_OPEN;
	if (snprintf(pathname, sizeof (pathname),
	    _DFLT_LOC_PATH "%s" MESSAGES "%s",
	    db->saved_locale, db->db_name) >= sizeof (pathname)) {
		/*
		 * We won't set err here, because an invalid locale is not
		 * the fatal condition, but we can fall back to "C"
		 * locale.
		 */
		return (NULL);
	}
	if ((fd = open(pathname, O_RDONLY)) != -1 &&
	    fstat64(fd, &sb) != -1 &&
	    (addr = mmap(0, (size_t)sb.st_size, PROT_READ, MAP_SHARED,
	    fd, 0)) != MAP_FAILED) {
		db->flag |= DB_EXIST;
		db->addr = (uintptr_t)addr;
		db->length = (size_t)sb.st_size;
	}
	if (fd != -1)
		(void) close(fd);
	return (db);
}