示例#1
0
文件: MSGC.c 项目: myoan/minikonoha
static GcManager *Arena_Init(KonohaContext *kctx)
{
    GcManager *mng = (GcManager *)do_malloc(sizeof(GcManager));
    size_t i = 0;
    for(; i < ARENA_COUNT; ++i) {
        MSGC(i).arena_table.table = (ObjectPageTable_t *)do_malloc(ArenaTable_InitSize * sizeof(ObjectPageTable_t));
        MSGC(i).arena_table.size = 0;
        MSGC(i).arena_table.capacity = ArenaTable_InitSize;
    }
    return mng;
}
示例#2
0
文件: MSGC.c 项目: myoan/minikonoha
static void *Kmalloc(KonohaContext *kctx, size_t s, KTraceInfo *trace)
{
    size_t *p = (size_t *)do_malloc(s
#ifdef MEMORY_DEBUG
                                    + sizeof(size_t)
#endif
                                   );
    if(unlikely(p == NULL)) {
        KTraceApi(trace, SystemFault|UserFault, "malloc",
                  LogUint("size", s), LogUint("UsedMemorySize", klib_malloced));
        THROW_OutOfMemory(kctx, s);
    }
#if GCDEBUG
    OLDTRACE_SWITCH_TO_KTrace(LOGPOL_DEBUG,
                              LogText("@", "malloc"),
                              KeyValue_p("from", p),
                              KeyValue_p("to", ((char *)p)+s),
                              LogUint("size", s));
#endif
    klib_malloced += s;
#ifdef MEMORY_DEBUG
    p[0] = s;
    p += 1;
#endif
    return (void *)p;
}
示例#3
0
//  This function shall allocate a __cxa_dependent_exception and
//  return a pointer to it. (Really to the object, not past its' end).
//  Otherwise, it will work like __cxa_allocate_exception.
void * __cxa_allocate_dependent_exception () {
    size_t actual_size = sizeof(__cxa_dependent_exception);
    void *ptr = do_malloc(actual_size);
    if (NULL == ptr)
        std::terminate();
    std::memset(ptr, 0, actual_size);
    return ptr;
}
示例#4
0
//  Allocate a __cxa_exception object, and zero-fill it.
//  Reserve "thrown_size" bytes on the end for the user's exception
//  object. Zero-fill the object. If memory can't be allocated, call
//  std::terminate. Return a pointer to the memory to be used for the
//  user's exception object.
void * __cxa_allocate_exception (size_t thrown_size) throw() {
    size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
    __cxa_exception* exception_header = static_cast<__cxa_exception*>(do_malloc(actual_size));
    if (NULL == exception_header)
        std::terminate();
    std::memset(exception_header, 0, actual_size);
    return thrown_object_from_cxa_exception(exception_header);
}
示例#5
0
static void *
do_calloc (size_t nmemb, size_t size)
{
	int total = nmemb * size;
	void *result = do_malloc (total, 2);

	if (result)
		memset (result, 0, total);
	
	return result;
}
示例#6
0
文件: MSGC.c 项目: myoan/minikonoha
static MarkStack *mstack_Init(MarkStack *mstack)
{
    if(mstack->capacity == 0) {
        mstack->capacity_log2 = 12;
        mstack->capacity = (1 << mstack->capacity_log2) - 1;
        DBG_ASSERT(K_PAGESIZE == 1 << 12);
        mstack->stack = (kObject**)do_malloc(sizeof(kObject *)*(mstack->capacity + 1));
    }
    mstack->tail = 0;
    return mstack;
}
示例#7
0
文件: mkfs.c 项目: colyli/cmfs
static void
format_superblock(State *s, SystemFileDiskRecord *rec,
		  SystemFileDiskRecord *root_rec, SystemFileDiskRecord *sys_rec)
{
	struct cmfs_dinode *di;
	uint64_t super_off = rec->fe_off;

	di = do_malloc(s, s->blocksize);
	memset(di, 0, s->blocksize);

	strcpy((char *)di->i_signature, CMFS_SUPER_BLOCK_SIGNATURE);
	di->i_generation = s->vol_generation;
	di->i_fs_generation = s->vol_generation;

	di->i_atime = 0;
	di->i_ctime = s->format_time;
	di->i_mtime = s->format_time;
	di->i_blkno = super_off >> s->blocksize_bits;
	di->i_flags = CMFS_VALID_FL | CMFS_SYSTEM_FL | CMFS_SUPER_BLOCK_FL;
	di->i_clusters = s->volume_size_in_clusters;
	di->id2.i_super.s_major_rev_level = CMFS_MAJOR_REV_LEVEL;
	di->id2.i_super.s_minor_rev_level = CMFS_MINOR_REV_LEVEL;
	di->id2.i_super.s_root_blkno = root_rec->fe_off >> s->blocksize_bits;
	di->id2.i_super.s_system_dir_blkno = sys_rec->fe_off >> s->blocksize_bits;
	di->id2.i_super.s_mnt_count = 0;
	di->id2.i_super.s_max_mnt_count = CMFS_DFL_MAX_MNT_COUNT;
	di->id2.i_super.s_state = 0;
	di->id2.i_super.s_errors = 0;
	di->id2.i_super.s_lastcheck = s->format_time;
	di->id2.i_super.s_checkinterval = CMFS_DFL_CHECKINTERVAL;
	di->id2.i_super.s_creator_os = CMFS_OS_LINUX;
	di->id2.i_super.s_blocksize_bits = s->blocksize_bits;
	di->id2.i_super.s_clustersize_bits = s->cluster_size_bits;


	/* We clear the "backup_sb" here since it should be written by
	 * format_backup_super(), not by us. And we have already set the
	 * "s->no_backup_super" according to the features in get_state(),
	 * so it's safe to clear the flag here.
	 */
	s->feature_flags.opt_compat &= ~CMFS_FEATURE_COMPAT_BACKUP_SB;

	di->id2.i_super.s_feature_incompat = s->feature_flags.opt_incompat;
	di->id2.i_super.s_feature_compat = s->feature_flags.opt_compat;
	di->id2.i_super.s_feature_ro_compat = s->feature_flags.opt_ro_compat;

	strcpy((char *)di->id2.i_super.s_label, s->vol_label);
	memcpy(di->id2.i_super.s_uuid, s->uuid, CMFS_VOL_UUID_LEN);

	mkfs_swap_inode_from_cpu(s, di);
	mkfs_compute_meta_ecc(s, di, &di->i_check);
	do_pwrite(s, di, s->blocksize, super_off);
	free(di);
}
示例#8
0
void level4(int t)
{
  if (t == Malloc)
    do_malloc();
  else if (t == Div0)
    do_div0();
  else if (t == Assert)
    do_assert();
  else
    do_crash();
}
示例#9
0
文件: mkfs.c 项目: colyli/cmfs
/* If src is NULL, we write cleaned buf out. */
static void
write_metadata(State *s, SystemFileDiskRecord *rec, void *src)
{
	void *buf;

	buf = do_malloc(s, rec->extent_len);

	if (!buf) {
		fprintf(stderr, "%s:%d: do_malloc failed.",
			__func__, __LINE__);
		exit(1);
	}
		
	memset(buf, 0, rec->extent_len);
	if (src)
		memcpy(buf, src, rec->file_size);

	do_pwrite(s, buf, rec->extent_len, rec->extent_off);

	free(buf);
}
示例#10
0
文件: mkfs.c 项目: colyli/cmfs
static void format_leading_space(State *s)
{
	int num_blocks, size;
	struct cmfs_vol_disk_hdr *hdr;
	struct cmfs_vol_label *lbl;
	void *buf;
	char *p;

	num_blocks = 2;
	size = num_blocks << s->blocksize_bits;
	p = buf = do_malloc(s, size);
	memset(buf, 0, size);

	hdr = (struct cmfs_vol_disk_hdr *)buf;
	strcpy((char *)hdr->signature, "this is a cmfs volume");
	strcpy((char *)hdr->mount_point, "this is a cmfs volume");

	p += 512;
	lbl = (struct cmfs_vol_label *)p;
	strcpy((char *)lbl->label, "this is a cmfs volume");

	do_pwrite(s, buf, size, 0);
	free(buf);
}
示例#11
0
void *
malloc (size_t size)
{
	return do_malloc (size, 1);
}
示例#12
0
void *
__libc_malloc (size_t size)
{
	return do_malloc (size, 1);
}
示例#13
0
static int init_spectral_bin (int chan, Spectral_Bin_Type *sb)
{
   double en, emin, emax, sigma;
   unsigned int min_line, max_line;
   unsigned int num, i;
   double sum, last;
   float *energies, *cum_strengths, *strengths;

   if (Have_Line_List == 0)
     {
	sb->cum_strengths = NULL;
	sb->energies = NULL;
	sb->num_energies = 0;
	sb->pi_chan = chan;
	return 0;
     }

   en = channel_to_kev (chan);
   sigma = compute_ccd_sigma (en);
   emin = en - 3 * sigma;
   emax = en + 3 * sigma;

   if (emin < 0.0) emin = 0.0;
   min_line = JDMbinary_search_f (emin, Energy_Line_List, Num_Lines);
   max_line = JDMbinary_search_f (emax, Energy_Line_List, Num_Lines);

   if (min_line == Num_Lines-1)
     {
	sb->cum_strengths = NULL;
	sb->energies = NULL;
	sb->num_energies = 0;
	return 0;
     }

   num = max_line - min_line + 1;
   if (NULL == (cum_strengths = (float *) do_malloc (num * sizeof (float))))
     return -1;

   sb->cum_strengths = cum_strengths;
   sb->energies = energies = Energy_Line_List + min_line;
   sb->num_energies = num;
   strengths = Line_Strengths + min_line;

   if (num == 1)
     {
	cum_strengths[0] = 1;
	return 0;
     }

   sigma *= sqrt(2);
   sum = 0.0;
   last = JDMerf ((energies[0] - en)/sigma);
   for (i = 1; i < num; i++)
     {
	double next = JDMerf ((energies[i] - en)/sigma);
	sum += (next - last) * strengths[i-1];
	cum_strengths[i-1] = sum;
	last = next;
     }

   if (sum == 0.0)
     {
	for (i = 1; i < num; i++)
	  {
	     sum += 1.0;
	     cum_strengths[i-1] = sum;
	  }
     }

   num--;
   for (i = 0; i < num; i++)
     cum_strengths[i] /= sum;

   return 0;
}
示例#14
0
文件: sysinit.c 项目: 2asoft/freebsd
int
main(int argc, char **argv)
{
	struct sysinit_data **sipp;
	int c;
	int entries;
	off_t off;

	while ((c = getopt(argc, argv, "k:s:i:o:Rh")) != -1) {
		switch (c) {
		case 'i':
			input_f = optarg;
			break;
		case 'o':
			output_f = optarg;
			break;
		case 'R':
			opt_R = 1;
			break;
		case 'k':
			keyword = optarg;
			break;
		case 's':
			struct_name = optarg;
			break;
		default:
			usage();
		}
	}

	if (input_f == NULL || output_f == NULL ||
	    struct_name == NULL || keyword == NULL)
		usage();

	atexit(&cleanup);

	cleanup();

	input_file = open(input_f, O_RDONLY);
	if (input_file < 0)
		err(EX_SOFTWARE, "Could not open input file: %s", input_f);

	output_file = open(output_f, O_TRUNC | O_CREAT | O_RDWR, 0600);
	if (output_file < 0)
		err(EX_SOFTWARE, "Could not open output file: %s", output_f);

	off = lseek(input_file, 0, SEEK_END);

	input_ptr = do_malloc(off);
	input_len = off;

	if (input_len % (uint32_t)sizeof(struct sysinit_data)) {
		errx(EX_SOFTWARE, "Input file size is not divisible by %u",
		    (unsigned int)sizeof(struct sysinit_data));
	}
	off = lseek(input_file, 0, SEEK_SET);
	if (off < 0)
		err(EX_SOFTWARE, "Could not seek to start of input file");

	if (read(input_file, input_ptr, input_len) != input_len)
		err(EX_SOFTWARE, "Could not read input file");

	entries = input_len / (uint32_t)sizeof(struct sysinit_data);

	start = do_malloc(sizeof(void *) * entries);
	stop = start + entries;

	for (c = 0; c != entries; c++)
		start[c] = &((struct sysinit_data *)input_ptr)[c];

	if (start != stop)
		endian32 = (*start)->dw_endian32;

	/* switch all fields to host endian order */
	for (sipp = start; sipp < stop; sipp++) {
		(*sipp)->dw_lsb_value = read32((*sipp)->dw_lsb_value);
		(*sipp)->dw_msb_value = read32((*sipp)->dw_msb_value);
		(*sipp)->dw_file_line = read32((*sipp)->dw_file_line);
	}

	if (opt_R == 0) {
		/* sort entries, rising numerical order */
		qsort(start, entries, sizeof(void *), &compare);
	} else {
		/* sort entries, falling numerical order */
		qsort(start, entries, sizeof(void *), &compare_R);
	}

	/* safe all strings */
	for (sipp = start; sipp < stop; sipp++) {
		(*sipp)->b_keyword_name[sizeof((*sipp)->b_keyword_name) - 1] = 0;
		(*sipp)->b_global_type[sizeof((*sipp)->b_global_type) - 1] = 0;
		(*sipp)->b_global_name[sizeof((*sipp)->b_global_name) - 1] = 0;
		(*sipp)->b_file_name[sizeof((*sipp)->b_file_name) - 1] = 0;
		(*sipp)->b_debug_info[sizeof((*sipp)->b_debug_info) - 1] = 0;
	}

	if (strcmp(keyword, "sysinit") == 0)
		do_sysinit();
	else if (strcmp(keyword, "sysuninit") == 0)
		do_sysinit();
	else
		errx(EX_USAGE, "Unknown keyword '%s'", keyword);

	success = 1;

	return (0);
}
示例#15
0
/*************************************************
* Locking_Allocator's Allocation                 *
*************************************************/
void* Locking_Allocator::alloc_block(u32bit n)
   {
   return do_malloc(n, true);
   }
示例#16
0
/*************************************************
* Malloc_Allocator's Allocation                  *
*************************************************/
void* Malloc_Allocator::allocate(u32bit n)
   {
   return do_malloc(n, false);
   }