예제 #1
0
void __libc_init(void)
{
    extern void (*__CTOR_LIST__[])();
    void (**pfunc)() = __CTOR_LIST__;

    if (ProcGetProcessInfo()->std_out != 0)
	ThrGetThreadInfo()->exception_handler = __libc_exception_handler;

    __malloc_lock_init();
    __malloc_debug_init();
    atexit(__malloc_lock_cleanup);
    __get_stdin();
    __get_stdout();
    __get_stderr();
    __setup_file_rec_list();

    while (*++pfunc)
	;
    while (--pfunc > __CTOR_LIST__)
	(*pfunc) ();
}
예제 #2
0
void *
malloc (size_t size)
{
  void *mem;
#ifdef MALLOC_DEBUGGING
  static smallint debugging_initialized;
  if (! debugging_initialized)
    {
      debugging_initialized = 1;
      __malloc_debug_init ();
    }
  if (__malloc_check)
    __heap_check (__malloc_heap, "malloc");
#endif

#ifdef __MALLOC_GLIBC_COMPAT__
  if (unlikely (size == 0))
    size++;
#else
  /* Some programs will call malloc (0).  Lets be strict and return NULL */
  if (unlikely (size == 0))
    goto oom;
#endif

  /* Check if they are doing something dumb like malloc(-1) */
  if (unlikely(((unsigned long)size > (unsigned long)(MALLOC_HEADER_SIZE*-2))))
    goto oom;

  mem = malloc_from_heap (size, &__malloc_heap, &__malloc_heap_lock);
  if (unlikely (!mem))
    {
    oom:
      __set_errno (ENOMEM);
      return 0;
    }

  return mem;
}