示例#1
0
文件: memory.c 项目: onukore/radium
void *talloc_atomic_uncollectable__(size_t size, const char *filename, int linenumber){
	void *ret;

	ret=tracker_alloc__(size,GC_malloc_atomic_uncollectable, filename, linenumber);

	if(ret!=NULL) return ret;

#if 0
	if(tmemoryisused==0){
		tmemoryisused=1;
		GC_free(tmemory);
		tmemory=NULL;
	}

#ifndef DISABLE_BDWGC
 	ret=GC_malloc_atomic_uncollectable(size);
#else
	ret=OS_getmem(size);		// For debugging. (wrong use of GC_malloced memory could be very difficult to trace)
#endif

#endif

        RWarning("Out of memory. I'll try to continue by allocating a different way, but you should save and quit now.\n");
        ret = calloc(1,size);
        
	if(ret!=NULL) return ret;


        RWarning("Didn't succeed. Out of memory. Quitting. (atomic_uncollectable allocator)\n");
	ShutDownYepp();
	return NULL;
}
示例#2
0
void *scheme_malloc_eternal(size_t n)
{
#ifdef USE_SENORA_GC
  return GC_malloc_atomic_uncollectable(n);
#else
  void *s;

  s = MALLOC(n);
  if (!s) {
    if (GC_out_of_memory)
      GC_out_of_memory();
    else {
      if (scheme_console_printf)
	scheme_console_printf("out of memory\n");
      else
	printf("out of memory\n");
      exit(1);
    }
  }
	

  memset(s, 0, n);

  return s;
#endif
}
示例#3
0
  GC_API GC_ATTR_MALLOC void * GC_CALL
        GC_debug_malloc_atomic_uncollectable(size_t lb, GC_EXTRA_PARAMS)
  {
    void * result = GC_malloc_atomic_uncollectable(
                                SIZET_SAT_ADD(lb, UNCOLLECTABLE_DEBUG_BYTES));

    return store_debug_info(result, lb,
                            "GC_debug_malloc_atomic_uncollectable",
                            OPT_RA s, i);
  }
示例#4
0
void* GE_raw_calloc_atomic_uncollectable(size_t nelem, size_t elsize)
{
    void* new_p;

    new_p = GC_malloc_atomic_uncollectable(nelem * elsize);
    if (new_p) {
        memset(new_p, 0, nelem * elsize);
    }
    return new_p;
}
示例#5
0
文件: memory.c 项目: paurkedal/culibs
void *
(cu_uallocz_atomic)(size_t size)
{
#ifdef CUCONF_HAVE_GC_MALLOC_ATOMIC_UNCOLLECTABLE
    void *p = GC_malloc_atomic_uncollectable(size);
#else
    void *p = malloc(size);
#endif
    if (!p) cu_raise_out_of_memory(size);
    memset(p, 0, size);
    return p;
}
示例#6
0
文件: memory.c 项目: paurkedal/culibs
void *
cuD_ualloc_atomic(size_t size, char const *file, int line)
{
#ifdef CUCONF_HAVE_GC_MALLOC_ATOMIC_UNCOLLECTABLE
    void *p = GC_malloc_atomic_uncollectable(size);
#else
    void *p = malloc(size);
#endif
    if (p == NULL)
	cu_raise_out_of_memory(size);
    return p;
}
示例#7
0
文件: dbg_mlc.c 项目: Amaury/Trantor
  GC_API void * GC_CALL GC_debug_malloc_atomic_uncollectable(size_t lb,
                                                             GC_EXTRA_PARAMS)
  {
    void * result =
        GC_malloc_atomic_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);

    if (result == 0) {
        GC_err_printf("GC_debug_malloc_atomic_uncollectable(%lu)"
                      " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
        return(0);
    }
    if (!GC_debugging_started) {
        GC_start_debugging();
    }
    ADD_CALL_CHAIN(result, ra);
    return (GC_store_debug_info(result, (word)lb, s, i));
  }
示例#8
0
static int riva_load(module_t *Module, const char *FileName) {
	riva_t *Riva = unew(riva_t); // This really should be new...
	module_setup(Module, Riva, (module_importer)riva_import);

	gzFile File = gzopen(FileName, "rb");
	char *LoadPath;
	for (int I = strlen(FileName) - 1; I >= 0; --I) {
		if (FileName[I] == PATHCHR) {
			strncpy(LoadPath = (char *)GC_malloc_atomic(I + 2), FileName, I + 1);
			break;
		};
	};
	module_set_path(Module, LoadPath);

	uint32_t Magic; gzread(File, &Magic, 4);
	if (Magic != 0x41564952) {
		log_errorf("Error: %s is not a valid riva module\n", FileName);
		return 0;
	};

	uint32_t NoOfSections; gzread(File, &NoOfSections, 4);
	uint32_t NoOfExports; gzread(File, &NoOfExports, 4);
	uint32_t NoOfRequires; gzread(File, &NoOfRequires, 4);

	jmp_buf OnError[1];

	if (setjmp(OnError)) return 0;
	section_t **Sections = (Riva->Sections = (section_t **)GC_malloc(NoOfSections * sizeof(section_t *)));
	for (int I = 0; I < NoOfSections; ++I) Sections[I] = new(section_t);
	for (int I = 0; I < NoOfSections; ++I) {
		section_t *Section = Sections[I];
		uint8_t Type; gzread(File, &Type, 1);
		switch (Type) {
		case SECT_CODE: {
			Section->Fixup = fixup_code_section;
			gzread(File, &Section->Flags, 1);
			uint32_t Length; gzread(File, &Length, 4);
			uint32_t NoOfRelocs; gzread(File, &NoOfRelocs, 4);
			Section->NoOfRelocs = NoOfRelocs;
			reloc_t *Relocs = (Section->Relocs = (reloc_t *)GC_malloc_uncollectable(NoOfRelocs * sizeof(reloc_t)));
			if (Section->Flags & FLAG_GC) {
				Section->Data = GC_malloc_uncollectable(Length);
			} else {
				Section->Data = GC_malloc_atomic_uncollectable(Length);
			};
			gzread(File, Section->Data, Length);
			for (int J = 0; J < NoOfRelocs; ++J) {
				reloc_t *Reloc = &Relocs[J];
				gzread(File, &Reloc->Size, 1);
				gzread(File, &Reloc->Flags, 1);
				gzread(File, &Reloc->Position, 4);
				uint32_t Index; gzread(File, &Index, 4);
				Reloc->Section = Sections[Index];
			};
		break;};
		case SECT_LIBRARY: {
			Section->Fixup = fixup_library_section;
			gzread(File, &Section->Flags, 1);
			uint32_t Length; gzread(File, &Length, 4);
			gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length);
			Section->Name[Length] = 0;
			if (Section->Flags == LIBRARY_ABS) {
				Section->Path = 0;
			} else if (Section->Flags == LIBRARY_REL) {
				Section->Path = LoadPath;
			};
			for (char *P = Section->Name; *P; ++P) if (*P == '/') *P = PATHCHR;
		break;};
		case SECT_IMPORT: {
			Section->Fixup = fixup_import_section;
			gzread(File, &Section->Flags, 1);
			uint32_t Index; gzread(File, &Index, 4);
			Section->Library = Sections[Index];
			uint32_t Length; gzread(File, &Length, 4);
			gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length);
			Section->Name[Length] = 0;
		break;};
		case SECT_BSS: {
			Section->Fixup = fixup_bss_section;
			gzread(File, &Section->Flags, 1);
			uint32_t Size; gzread(File, &Size, 4);
			Section->Data = (uint8_t *)GC_malloc(Size);
		break;};
		case SECT_SYMBOL: {
			Section->Fixup = fixup_symbol_section;
			gzread(File, &Section->Flags, 1);
			uint32_t Length; gzread(File, &Length, 4);
			gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length);
			Section->Name[Length] = 0;
		break;};
		};
	};
	for (int I = 0; I < NoOfExports; ++I) {
		export_t *Export = new(export_t);
		gzread(File, &Export->Flags, 1);
		uint32_t Index; gzread(File, &Index, 4);
		Export->Section = Sections[Index];
		gzread(File, &Export->Offset, 4);
		uint32_t Length; gzread(File, &Length, 4);
		char *Name = (char *)GC_malloc_atomic(Length + 1);
		gzread(File, Name, Length);
		Name[Length] = 0;
		stringtable_put(Riva->Exports, Name, Export);
	};
	for (int I = 0; I < NoOfRequires; ++I) {
		uint8_t Flags; gzread(File, &Flags, 1);
		uint32_t Length; gzread(File, &Length, 4);
		char *Name = (char *)GC_malloc_atomic(Length + 1);
		char *Path = 0;
		gzread(File, Name, Length);
		Name[Length] = 0;
		if (Flags == LIBRARY_REL) Path = LoadPath;
		for (char *P = Name; *P; ++P) if (*P == '/') *P = PATHCHR;
		module_load(Path, Name);
	};
	gzclose(File);

	void (*__init)(module_t *) = check_import(Riva, "__init", OnError);
 	if (__init) __init(Module);
 	void *Methods = check_import(Riva, "__methods", OnError);
 	if (Methods) add_methods(Methods);
	return 1;
};