예제 #1
0
hash_manager::pointer_page::pointer_page(const char buffer[hash_manager::page_size]) : page(buffer) {
	std::bitset<n_pointers> ptr_bitmap(chars_to_int(&buffer[9]));
	int j = 0;
	for (int i=13 ; i<page_size-3 ; i+=4) {
		if (ptr_bitmap[j++]) add_ptr(chars_to_int(&buffer[i]));
	}
}
예제 #2
0
파일: bits.c 프로젝트: ftk/XXLDDRace
void *malloc_db (uint32_t size)
{
    if (size)
        return add_ptr (malloc (size));
    else
        return NULL;
}
예제 #3
0
inline
void* operator new(std::size_t sz) {
    void* ptr = std::malloc(sz);
    add_ptr(ptr,sz);
    total_bytes_allocated += sz;
    high_water_mark_bytes = std::max(high_water_mark_bytes, total_bytes_allocated);
    return ptr;
}
예제 #4
0
파일: bits.c 프로젝트: ftk/XXLDDRace
void *realloc_db (void *ptr, uint32_t size)
{
    if (ptr && size)
        return add_ptr (realloc (del_ptr (ptr), size));
    else if (size)
        return malloc_db (size);
    else
        free_db (ptr);

    return NULL;
}
예제 #5
0
파일: readskel.c 프로젝트: ChrisDodd/btyacc
static void add_string(char *s)
{
int	len = strlen(s)+1;

    if (len > cp_end - cp) {
	int size = len > CHUNK ? len : CHUNK;
	if (!(cp = malloc(size)))
	    no_space();
	cp_end = cp + size; }
    memcpy(cp, s, len);
    add_ptr(cp);
    cp += len;
}
예제 #6
0
파일: system.cpp 프로젝트: psi29a/thirdeye
ULONG *read_file(BYTE *filename, void *dest) {
	WORD i;
	FILE *handle;
	ULONG len;
	ULONG *buf, *mem;

	len = file_size(filename);
	if (len == -1L) {
		system_err = FILE_NOT_FOUND;
		return (NULL);
	}

	buf = mem = (dest == NULL) ? (ULONG*) mem_alloc(len) : (ULONG*) dest;

	handle = fopen(filename, "rb");
	if (handle == NULL) {
		mem_free(mem);
		system_err = FILE_NOT_FOUND;
		return (NULL);
	}

	while (len >= 4096L) {
		i = fread(buf, 1, 4096, handle);
		if (i != 4096) {
			mem_free(mem);
			system_err = CANT_READ_FILE;
			return (NULL);
		}
		len -= 4096L;
		buf = (ULONG*) add_ptr(buf, 4096L);
	}

	i = fread(buf, 1, (UWORD) len, handle);
	if (i != (UWORD) len) {
		mem_free(mem);
		system_err = CANT_READ_FILE;
		return (NULL);
	}

	fclose(handle);
	return (mem);
}
예제 #7
0
void *__ckd_malloc__(size_t size,
                     char *caller_file, int caller_line)
{
    void *mem;

    mem = debug ? mycalloc (size) : malloc(size);
    if (mem == NULL) {
        E_FATAL("malloc(%d) failed %s(%d)\n", size,
                caller_file, caller_line);
    }

#if defined(MEM_DEBUG)
    add_ptr(mem, caller_file, caller_line);
    printf ("ckd_malloc from %s(%d): %d = %08x\n",
            caller_file, caller_line, size, mem);
    fflush (stdout);
#endif

    return mem;
}
예제 #8
0
파일: system.cpp 프로젝트: psi29a/thirdeye
WORD append_file(BYTE *filename, void *buf, ULONG len) {
	WORD i;
	FILE *handle;

	handle = fopen(filename, "a+b");
	if (handle == NULL) {
		system_err = FILE_NOT_FOUND;
		return (0);
	}

	while (len >= 4096L) {
		i = fwrite(buf, 1, 4096, handle);
		if (i == -1) {
			system_err = CANT_WRITE_FILE;
			return (0);
		}
		if (i != 4096) {
			system_err = DISK_FULL;
			return (0);
		}
		len -= 4096L;
		buf = add_ptr(buf, 4096L);
	}

	i = fwrite(buf, 1, (UWORD) len, handle);
	if (i == -1) {
		system_err = CANT_WRITE_FILE;
		return (0);
	}
	if (i != (UWORD) len) {
		system_err = DISK_FULL;
		return (0);
	}

	fclose(handle);

	return (1);
}
예제 #9
0
void *__ckd_realloc__(void *ptr, size_t new_size,
                      char *caller_file, int caller_line)
{
    void *mem;

#if defined(MEM_DEBUG)
    del_ptr(ptr);
#endif

    mem = debug ? myrealloc(ptr, new_size) : realloc(ptr, new_size);
    if (mem == NULL) {
        E_FATAL("realloc(%d) failed from %s(%d)\n", new_size,
                caller_file, caller_line);
    }

#if defined(MEM_DEBUG)
    add_ptr(mem, caller_file, caller_line);
    printf ("ckd_realloc from %s(%d): %08x %d = %08x\n",
            caller_file, caller_line, ptr, new_size, mem);
    fflush (stdout);
#endif

    return mem;
}
예제 #10
0
ULONG RES_store_resource(RF_class *RF, ULONG entry, void *source,
		RF_entry_hdr *RHDR, UWORD type) {
	WORD file;
	UBYTE *ptr;
	ULONG len;
	WORD err;

	err = 0;

	r_write(RF->file, RHDR, sizeof(RF_entry_hdr));

	len = RHDR->data_size;
	if (!len)
		return (entry);

	if (RHDR->data_attrib & DA_PLACEHOLDER)
		return (entry);

	switch (type) {
	case RTYP_HOUSECLEAN:
		file = *(WORD *) source;
		ptr = (UBYTE*) mem_alloc(BLK_SIZE);

		while (len > BLK_SIZE) {
			r_read(file, ptr, (UWORD) BLK_SIZE);
			r_write(RF->file, ptr, (UWORD) BLK_SIZE);
			len -= BLK_SIZE;
		}
		r_read(file, ptr, (UWORD) len);
		r_write(RF->file, ptr, (UWORD) len);

		mem_free(ptr);
		break;

	case RTYP_DICTIONARY:
	case RTYP_RAW_MEM:
		ptr = (UBYTE*) source;

		while (len > BLK_SIZE) {
			r_write(RF->file, ptr, (UWORD) BLK_SIZE);
			len -= BLK_SIZE;
			ptr = (UBYTE*) add_ptr(ptr, BLK_SIZE);
		}
		r_write(RF->file, ptr, (UWORD) len);
		break;

	case RTYP_RAW_FILE:
		file = open((BYTE*) source, O_RDWR);
		ptr = (UBYTE*) mem_alloc(BLK_SIZE);

		while (len > BLK_SIZE) {
			r_read(file, ptr, (UWORD) BLK_SIZE);
			r_write(RF->file, ptr, (UWORD) BLK_SIZE);
			len -= BLK_SIZE;
		}
		r_read(file, ptr, (UWORD) len);
		r_write(RF->file, ptr, (UWORD) len);

		mem_free(ptr);
		close(file);
		break;
	}

	if (!err)
		return (entry);
	else
		return ((ULONG) -1);
}
예제 #11
0
void *_memory_calloc(size_t num, size_t size) {
	void *ptr = calloc(num, size);
	assert(ptr != NULL);
	add_ptr(ptr);
	return ptr;
}
예제 #12
0
파일: atomic.hpp 프로젝트: netroby/jdk9-dev
inline size_t Atomic::add(size_t add_value, volatile size_t* dest) {
    return (size_t) add_ptr((intptr_t) add_value, (volatile intptr_t*) dest);
}
예제 #13
0
inline void Atomic::dec_ptr(volatile void*     dest) {
    (void)add_ptr(-1, dest);
}
예제 #14
0
inline void Atomic::inc_ptr(volatile void*     dest) {
    (void)add_ptr(1, dest);
}
inline void Atomic::inc_ptr(volatile intptr_t* dest)
{
 add_ptr(1, dest);
}
inline void*    Atomic::add_ptr(intptr_t add_value, volatile void*     dest) {
  return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest);
}
예제 #17
0
void *_memory_alloc(size_t size) {
	void *ptr = malloc(size);
	assert(ptr != NULL);
	add_ptr(ptr);
	return ptr;
}
예제 #18
0
ULONG DICT_save(DICT_class *DICT, RF_class *RF, ULONG entry) {
	RF_entry_hdr RHDR;
	ULONG saved, total_len, nchains;
	UWORD i;
	DICT_entry *cur;
	DI_class *DI;
	BYTE *ptr, *base;
	ULONG *offset;

	nchains = 0L;
	for (i = 0; i < DICT->hash_size; i++)
		if (DICT->root[i] != NULL)
			++nchains;

	total_len = nchains * (ULONG) sizeof(UWORD);

	DI = DI_construct(DICT);

	total_len += ((ULONG) sizeof(UWORD)) + ((ULONG) sizeof(UWORD))
			+ ((ULONG) DICT->hash_size * (ULONG) sizeof(ULONG));

	while ((cur = DI_fetch(DI)) != NULL) {
		total_len += (ULONG) ((strlen(cur->tag) + 1) + (2 * sizeof(UWORD)));
		if (cur->def != NULL)
			total_len += (ULONG) (strlen((BYTE*) cur->def) + 1);
	}

	DI_destroy(DI);

	ptr = base = (BYTE*) mem_alloc(total_len);

	*(UWORD *) ptr = DICT->hash_size;
	ptr += sizeof(UWORD);

	offset = (ULONG *) ptr;
	ptr = (BYTE*) add_ptr(ptr,
			((ULONG) sizeof(ULONG) * (ULONG) DICT->hash_size));

	for (i = 0; i < DICT->hash_size; i++) {
		cur = DICT->root[i];

		if (cur == NULL) {
			offset[i] = 0L;
			continue;
		}

		offset[i] = ptr_dif((ULONG*) ptr, (ULONG*) base);

		while (cur != NULL) {
			*(UWORD *) ptr = (strlen(cur->tag) + 1);
			ptr += sizeof(UWORD);

			strcpy(ptr, cur->tag);
			ptr += (strlen(cur->tag) + 1);

			if (cur->def == NULL) {
				*(UWORD *) ptr = 0;
				ptr += sizeof(UWORD);
			} else {
				*(UWORD *) ptr = (strlen((BYTE*) cur->def) + 1);
				ptr += sizeof(UWORD);

				strcpy(ptr, (BYTE*) cur->def);
				ptr += (strlen((BYTE*) cur->def) + 1);
			}

			cur = cur->next;
			ptr = (BYTE*) norm(ptr);
		}

		*(UWORD *) ptr = 0;
		ptr += sizeof(UWORD);
	}

	*(UWORD *) ptr = 0;
	ptr += sizeof(UWORD);

	RHDR.data_size = total_len;
	RHDR.data_attrib = DA_TEMPORARY;

	if (entry == (ULONG) -1)
		saved = RF_new_entry(RF, base, &RHDR, RTYP_DICTIONARY);
	else
		RF_write_entry(RF, saved = entry, base, &RHDR, RTYP_DICTIONARY);

	mem_free(base);

	return (saved);
}
inline void Atomic::dec_ptr(volatile intptr_t* dest)
{
 add_ptr(-1, dest);
}