Exemplo n.º 1
0
/*
 *  xcalloc() - same as calloc(3).  Used for portability.
 *  Never returns NULL; fatal on error.
 */
void *
xcalloc(size_t n, size_t sz)
{
    void *p;

    if (n < 1)
	n = 1;
    if (sz < 1)
	sz = 1;
    if ((p = calloc(n, sz)) == NULL) {
	if (failure_notify) {
	    snprintf(msg, 128, "xcalloc: Unable to allocate %u blocks of %u bytes!\n",
		(unsigned int) n, (unsigned int) sz);
	    (*failure_notify) (msg);
	} else {
	    perror("xcalloc");
	}
	exit(1);
    }
#if XMALLOC_DEBUG
    check_malloc(p, sz * n);
#endif
#if XMALLOC_STATISTICS
    malloc_stat(sz * n);
#endif
#if XMALLOC_TRACE
    xmalloc_show_trace(p, 1);
#endif
#if MEM_GEN_TRACE
    if (tracefp)
	fprintf(tracefp, "c:%u:%u:%p\n", (unsigned int) n, (unsigned int) sz, p);
#endif
    return (p);
}
Exemplo n.º 2
0
/*
 *  xmalloc() - same as malloc(3).  Used for portability.
 *  Never returns NULL; fatal on error.
 */
void *
xmalloc(size_t sz)
{
    void *p;

    if (sz < 1)
	sz = 1;

    if ((p = malloc(sz)) == NULL) {
	if (failure_notify) {
	    snprintf(msg, 128, "xmalloc: Unable to allocate %d bytes!\n",
		(int) sz);
	    (*failure_notify) (msg);
	} else {
	    perror("malloc");
	}
	exit(1);
    }
#if XMALLOC_DEBUG
    check_malloc(p, sz);
#endif
#if XMALLOC_STATISTICS
    malloc_stat(sz);
#endif
#if XMALLOC_TRACE
    xmalloc_show_trace(p, 1);
#endif
#if MEM_GEN_TRACE
    if (tracefp)
	fprintf(tracefp, "m:%d:%p\n", sz, p);
#endif
    return (p);
}
Exemplo n.º 3
0
/*
 *  xrealloc() - same as realloc(3). Used for portability.
 *  Never returns NULL; fatal on error.
 */
void *
xrealloc(void *s, size_t sz)
{
    void *p;

    PROF_start(xrealloc);
#if XMALLOC_TRACE

    xmalloc_show_trace(s, -1);
#endif

    if (sz < 1)
        sz = 1;

#if XMALLOC_DEBUG

    if (s != NULL)
        check_free(s);

#endif

    if ((p = realloc(s, sz)) == NULL) {
        if (failure_notify) {
            snprintf(msg, 128, "xrealloc: Unable to reallocate %d bytes!\n",
                     (int) sz);
            (*failure_notify) (msg);
        } else {
            perror("realloc");
        }

        exit(1);
    }

#if XMALLOC_DEBUG
    check_malloc(p, sz);

#endif
#if XMALLOC_STATISTICS

    malloc_stat(sz);

#endif
#if XMALLOC_TRACE

    xmalloc_show_trace(p, 1);

#endif
#if MEM_GEN_TRACE

    if (tracefp)		/* new ptr, old ptr, new size */
        fprintf(tracefp, "r:%p:%p:%d\n", p, s, sz);

#endif

    PROF_stop(xrealloc);

    return (p);
}
Exemplo n.º 4
0
Arquivo: voot.c Projeto: quad/voot
static bool maybe_handle_command(uint8 command, uint32 option, voot_packet *packet)
{
    switch(command)
    {
        case VOOT_COMMAND_TYPE_DEBUG:
        {
            static char key[] = "vrcust.bin";

            voot_debug("Module: '%s'", (const char *) VOOT_MODULE_NAME);
            grep_memory(key, sizeof(key));

            break;
        }

        case VOOT_COMMAND_TYPE_TIME:
            voot_debug("%u", time());
            break;

        case VOOT_COMMAND_TYPE_VERSION:
        {
            uint32 freesize, max_freesize;

            malloc_stat(&freesize, &max_freesize);

            voot_debug("Netplay VOOT Extensions, BETA [%u/%u]", freesize, max_freesize);

            break;
        }

        case VOOT_COMMAND_TYPE_DUMPON:
        {
            dump_start(option);

            voot_debug("Processed DUMPON command. (%x)", option);

            break;
        }

        case VOOT_COMMAND_TYPE_DUMPOFF:
        {
            uint32 bytes;

            bytes = dump_stop();

            voot_debug("Processed DUMPOFF command. (%u)", bytes);

            break;
        }

        /* TODO: After taking a certain number of screenshots, it appears to
            crash the system. Maybe the dump_framebuffer() call should be
            moved into the heartbeat logic and some simple IPC be
            implemented? */

        case VOOT_COMMAND_TYPE_SCREEN:
            dump_framebuffer();
            break;

        case VOOT_COMMAND_TYPE_DUMPMEM:
            voot_dump_buffer((const uint8 *) SYS_MEM_START, SYS_MEM_END - SYS_MEM_START);
            break;

        case VOOT_COMMAND_TYPE_DUMPGAME:
            voot_dump_buffer((const uint8 *) VOOT_MEM_START, VOOT_MEM_END - VOOT_MEM_START);
            break;

        case VOOT_COMMAND_TYPE_DUMPSELECT:
            voot_dump_buffer((const uint8 *) option, 1024);
            break;

        default:
            break;
    }

    return FALSE;
}