Exemplo n.º 1
0
int main(int argc, char ** argv) {
    entropy_context entropy;
    // initialize our AES context
    aes_init(&aes);
    entropy_init(&entropy);

    //int ret;

    if (argc != 2) {
        printf("usage: %s client\n", argv[0]);
        return 0;
    }

    if(__init()) {
        printf("  * Exiting \n");
        goto exit;
    }

    if(kvstore_dhm(pfd, &aes, argv[1], enckey, KVSTORE_AESKEY_LEN)) {
        printf("\n  ! DHM failed... Exiting");
        goto exit;
    }

    // to derive the IV, we just hash the key
    // assumed safe, the key IV is updated on each encryption
    entropy_func(&entropy, iv, KVSTORE_AESIV_LEN);

    send_commands();
exit:
    aes_free(&aes);
    printf("\n");
    return 0;
}
Exemplo n.º 2
0
void
_startup (void)
{
  _asm
    // Initialize the stack pointer
    lfsr 1, _stack
    lfsr 2, _stack

    clrf TBLPTRU, 0 // 1st silicon doesn't do this on POR

    bcf __FPFLAGS,RND,0 // Initialize rounding flag for floating point libs
    
    _endasm 
    _do_cinit ();

loop:

  // If user defined __init is not found, the one in clib.lib will be used
  __init ();

  // Call the user's main routine
  main ();

  goto loop;
}                               /* end _startup() */
Exemplo n.º 3
0
Arquivo: crt0.c Projeto: bingos/bitrig
void
___start(int argc, char **argv, char **envp, void *aux, void (*cleanup)(void))
{
	char *s;

	environ = envp;

	if ((__progname = argv[0]) != NULL) {   /* NULL ptr if argc = 0 */
		if ((__progname = _strrchr(__progname, '/')) == NULL)
			__progname = argv[0];
		else
			__progname++;
		for (s = __progname_storage; *__progname &&
		   s < &__progname_storage[sizeof __progname_storage - 1]; )
			*s++ = *__progname++;
		*s = '\0';
		__progname = __progname_storage;
	}

	if (cleanup)
		atexit(cleanup);

#ifdef MCRT0
	atexit(_mcleanup);
	monstartup((u_long)&_eprol, (u_long)&_etext);
#endif

#ifndef SCRT0
	__init();
#endif

	exit(main(argc, argv, environ));
}
Exemplo n.º 4
0
void *
realloc(void *ptr, size_t size)
{
    size_t   usable;
    void    *p;

    while (real_realloc == NULL){
        if (!initializing){
            initializing = 1;
            __init();
            initializing = 0;
        }
        sched_yield();
    }

    if (size == 0){
        /* size=0,ptr is not NULL => free(ptr); */
        free(ptr);
        return NULL;
    }

    ptr = real_realloc(ptr, size + SIZEOF_F_RZ + SIZEOF_SIZE);
    usable = malloc_usable_size(ptr);
    /* corner cases */

    /* ptr is NULL => malloc(size); */
    p = ptr + size; /* end of user region */
    memset(p, MAGIC_BYTE, SIZEOF_RZ(usable, size));
    p += SIZEOF_RZ(usable,size); /* end of redzone */
    *(size_t *)p = size;
    OFC_DUMP(ptr, usable, size);
    return ptr;
}
Exemplo n.º 5
0
void
_startup (void)
{
  _asm
    // Initialize the stack pointer
    lfsr 1, _stack
    lfsr 2, _stack

    clrf TBLPTRU, 0 // 1st silicon doesn't do this on POR

    bcf __FPFLAGS,RND,0
    
    // call the part specific module to zero the memory
    call __zero_memory, 0

    _endasm _do_cinit ();

loop:

  // If user defined __init is not found, the one in clib.lib will be used
  __init ();

  // Call the user's main routine
  main ();

  goto loop;
}                               /* end _startup() */
Exemplo n.º 6
0
void
___start(int argc, char **argv, char **envp, void *ps_strings,
	const void *obj, void (*cleanup)(void))
{
	char *s;

 	environ = envp;

	if ((__progname = argv[0]) != NULL) {   /* NULL ptr if argc = 0 */
		if ((__progname = _strrchr(__progname, '/')) == NULL)
			__progname = argv[0];
		else
			__progname++;
		for (s = __progname_storage; *__progname &&
		    s < &__progname_storage[sizeof __progname_storage - 1]; )
			*s++ = *__progname++;
		*s = '\0';
		__progname = __progname_storage;
	}

#if 0
	atexit(cleanup);
#endif
#ifdef MCRT0
	atexit(_mcleanup);
	monstartup((u_long)&_eprol, (u_long)&_etext);
#endif	/* MCRT0 */

#ifndef SCRT0
        __init();
#endif

__asm("__callmain:");		/* Defined for the benefit of debuggers */
	exit(main(argc, argv, envp));
}
Exemplo n.º 7
0
void *
malloc(size_t size)
{
    size_t      usable;
    void       *ptr, *p;

    while(real_malloc == NULL){
        if(!initializing){
            initializing = 1;
            __init();
            initializing = 0;
        }
        sched_yield();
    }

    ptr = real_malloc(size + SIZEOF_F_RZ + SIZEOF_SIZE);
    usable = malloc_usable_size(ptr);

    p = ptr + size; /* end of user region */
    memset(p, MAGIC_BYTE, SIZEOF_RZ(usable, size));

    p += SIZEOF_RZ(usable,size); /* end of redzone */
    *(size_t *)p = size;

    OFC_DUMP(ptr, usable, size);

    return ptr;
}
Exemplo n.º 8
0
int
posix_memalign(void **memptr, size_t alignment, size_t size)
{
    size_t      usable;
    void       *p;
    int         ret;

    while(real_posix_memalign == NULL){
        if(!initializing){
            initializing = 1;
            __init();
            initializing = 0;
        }
        sched_yield();
    }


    ret = real_posix_memalign(memptr, alignment,
                              size + SIZEOF_F_RZ + SIZEOF_SIZE);
    if (ret != 0)
        return ret;

    usable = malloc_usable_size(*memptr);
    p = *memptr + size; /* end of user region */
    memset(p, MAGIC_BYTE, SIZEOF_RZ(usable, size));
    p += SIZEOF_RZ(usable,size); /* end of redzone */
    *(size_t *)p = size;
    OFC_DUMP(*memptr, usable, size);
    return 0;
}
Exemplo n.º 9
0
void *
calloc(size_t nmemb, size_t size)
{
    size_t   newNmemb,newSize,usable;
    void    *ptr, *p;

    while(real_calloc == NULL){
        if(!initializing){
            initializing = 1;
            __init();
            initializing = 0;
        }
        sched_yield();
    }

    if ((size * nmemb) == 0){
        /* corner cases */
        /* When size=0 or nmemb=0, */
        /* malloc() maybe return minimum block, */
        newSize = SIZEOF_F_RZ + SIZEOF_SIZE;
        newNmemb = 1;
    }else{
        newSize = size;
        newNmemb = nmemb + ((SIZEOF_F_RZ + SIZEOF_SIZE - 1) / size + 1);
    }
    ptr = real_calloc(newNmemb ,newSize);
    usable = malloc_usable_size(ptr);
    p = ((char*)ptr + (size * nmemb)); /* end of user region */
    memset(p, MAGIC_BYTE, SIZEOF_RZ(usable, size * nmemb));
    p += SIZEOF_RZ(usable,size * nmemb); /* end of redzone */
    *(size_t *)p = size * nmemb;
    OFC_DUMP(ptr, usable, size * nmemb);
    return ptr;
}
Exemplo n.º 10
0
WaveformView*
waveform_view_new (Waveform* waveform)
{
	PF;
	int width = 256, height = 128;

	g_return_val_if_fail(glconfig || __init(), NULL);

	WaveformView* view = construct ();
	GtkWidget* widget = (GtkWidget*)view;

	view->waveform = waveform ? g_object_ref(waveform) : NULL;

	gtk_widget_set_can_focus(widget, TRUE);
	gtk_widget_set_size_request(widget, width, height);

	gboolean waveform_view_load_new_on_idle(gpointer _view)
	{
		WaveformView* view = _view;
		g_return_val_if_fail(view, IDLE_STOP);
		if(!canvas_init_done){
			waveform_view_init_drawable(view);
			gtk_widget_queue_draw((GtkWidget*)view); //testing.
		}
		return IDLE_STOP;
	}
Exemplo n.º 11
0
int main(int argc, char* argv[])
{
    cuInit(0);
    int devs = 0;
    cuDeviceGetCount(&devs);
    assert(devs > 0);
    CUdevice dev;
    CUresult status;
    CUcontext ctx = 0;
    cuDeviceGet(&dev, 0);
    cuCtxCreate(&ctx, 0, dev);
    {
        size_t f = 0, t = 0;
        CUresult r = cuMemGetInfo(&f, &t);
        fprintf( stderr, "Do cuMemGetInfo: %d, %zu/%zu\n", r, f, t );
    }
    
    __init("\n");
 
    printf("\nPress any key to exit...");
    char c;
    scanf("%c", &c);
 
    return 0;
}
Exemplo n.º 12
0
/**
 * 装载TTA音乐文件 
 *
 * @param spath 短路径名
 * @param lpath 长路径名
 *
 * @return 成功时返回0
 */
static int tta_load(const char *spath, const char *lpath)
{
	__init();

	if (tta_read_tag(spath) != 0) {
		__end();
		return -1;
	}

	if (g_buff != NULL) {
		free(g_buff);
		g_buff = NULL;
	}
	g_buff = calloc(TTA_BUFFER_SIZE, sizeof(*g_buff));
	if (g_buff == NULL) {
		__end();
		return -1;
	}

	if (open_tta_file(spath, &ttainfo, 0, g_io_buffer_size) < 0) {
		dbg_printf(d, "TTA Decoder Error - %s", get_error_str(ttainfo.STATE));
		close_tta_file(&ttainfo);
		return -1;
	}

	if (player_init(&ttainfo) != 0) {
		__end();
		return -1;
	}

	if (ttainfo.BPS == 0) {
		__end();
		return -1;
	}

	g_info.samples = ttainfo.DATALENGTH;
	g_info.duration = (double) ttainfo.LENGTH;
	g_info.sample_freq = ttainfo.SAMPLERATE;
	g_info.channels = ttainfo.NCH;
	g_info.filesize = ttainfo.FILESIZE;

	if (xAudioInit() < 0) {
		__end();
		return -1;
	}

	if (xAudioSetFrequency(ttainfo.SAMPLERATE) < 0) {
		__end();
		return -1;
	}

	xAudioSetChannelCallback(0, tta_audiocallback, NULL);

	generic_lock();
	g_status = ST_LOADED;
	generic_unlock();

	return 0;
}
Exemplo n.º 13
0
		AVIRenderer*				AVIRenderer::load(const SPtr<AVIReader>& reader)
		{
			__init();

			if(!reader->video_header() || !reader->video_format())
				return NULL;

			if(!_map_fcc_codecid.count(((AVISTREAMHEADER*)reader->video_header())->fccHandler) && !_map_fcc_codecid.count(((BITMAPINFO*)reader->video_format())->bmiHeader.biCompression))
			{
				// handle in another way, custom rgba 32-bit raw or png
				if(((BITMAPINFO*)reader->video_format())->bmiHeader.biCompression != *(DWORD*)"PNG " && ((BITMAPINFO*)reader->video_format())->bmiHeader.biCompression != 0)
					return NULL;
				if(((BITMAPINFO*)reader->video_format())->bmiHeader.biBitCount != 32 && ((BITMAPINFO*)reader->video_format())->bmiHeader.biBitCount != 24 )
					return NULL;
				AVIRenderer* renderer = new AVIRenderer();
				renderer->_reader = reader;
				((AVIRendererInternal*)renderer->_internal)->fip.setSize(FIT_BITMAP, (WORD)((BITMAPINFO*)reader->video_format())->bmiHeader.biWidth, (WORD)((BITMAPINFO*)reader->video_format())->bmiHeader.biHeight, ((BITMAPINFO*)reader->video_format())->bmiHeader.biBitCount);
				return renderer;
			}
			unsigned long fcc = ((AVISTREAMHEADER*)reader->video_header())->fccHandler;
			if(!(_map_fcc_codecid.count(fcc) && avcodec_find_decoder((CodecID)_map_fcc_codecid[fcc])))
			{
				fcc = ((BITMAPINFO*)reader->video_format())->bmiHeader.biCompression;
				if(!(_map_fcc_codecid.count(fcc) && avcodec_find_decoder((CodecID)_map_fcc_codecid[fcc])))
					return NULL;
			}
			AVCodec* codec = avcodec_find_decoder((CodecID)_map_fcc_codecid[fcc]);
			AVCodecContext* ctx = avcodec_alloc_context();

			ctx->stream_codec_tag = ((AVISTREAMHEADER*)reader->video_header())->fccHandler;
			ctx->width = ((BITMAPINFO*)reader->video_format())->bmiHeader.biWidth;
			ctx->height = ((BITMAPINFO*)reader->video_format())->bmiHeader.biHeight;
			ctx->codec_tag = ((AVISTREAMHEADER*)reader->video_header())->fccHandler;
			// handle this carefully, is BITMAPINFOHEADER, not BITMAPINFO (which includes at least one RGBQUAD)
			ctx->extradata = (uint8_t*)((BITMAPINFOHEADER*)reader->video_format()+1);
			ctx->extradata_size = ((BITMAPINFO*)reader->video_format())->bmiHeader.biSize-sizeof(BITMAPINFOHEADER);

			if(avcodec_open(ctx,codec) != 0)
			{
				avcodec_close(ctx);
				return NULL;
			}

			AVIRenderer* renderer = new AVIRenderer();
			renderer->_reader = reader;
			AVIRendererInternal* intn = (AVIRendererInternal*)renderer->_internal;
			intn->ctx = ctx;
			intn->src = avcodec_alloc_frame();
			intn->dst = avcodec_alloc_frame();
			intn->fip.setSize(FIT_BITMAP, (WORD)ctx->width, (WORD)ctx->height, 24);
			avpicture_fill((AVPicture*)(intn->dst), intn->fip.accessPixels(), PIX_FMT_BGR24, ctx->width, ctx->height);
			intn->dst->linesize[0] = intn->fip.getScanWidth();

			SwsParams p;
			memset(&p, 0, sizeof(p));
			intn->sws = sws_getContext(ctx->width, ctx->height, csp_ffdshow2mplayer(csp_lavc2ffdshow(ctx->pix_fmt)), intn->fip.getWidth(), intn->fip.getHeight(), csp_ffdshow2mplayer(csp_lavc2ffdshow(PIX_FMT_BGR24)), &p, NULL, NULL, NULL);

			return renderer;
		}
strstreambuf::strstreambuf(char* __gnext, streamsize __n, char* __pbeg)
    : __strmode_(),
      __alsize_(__default_alsize),
      __palloc_(nullptr),
      __pfree_(nullptr)
{
    __init(__gnext, __n, __pbeg);
}
Exemplo n.º 15
0
strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
    : __strmode_(__constant),
      __alsize_(__default_alsize),
      __palloc_(nullptr),
      __pfree_(nullptr)
{
    __init((char*)__gnext, __n, nullptr);
}
strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
    : __strmode_(__constant),
      __alsize_(__default_alsize),
      __palloc_(nullptr),
      __pfree_(nullptr)
{
    __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
}
Exemplo n.º 17
0
PulseProcessor::PulseProcessor(double dT_ms, ProcessType type)
{
    switch(type){
        case HeartRate:
            __init(7500.0, 400.0, 350.0, dT_ms, type);
            break;
    }
}
Exemplo n.º 18
0
 MapControl::MapControl(QSize size, MouseMode mousemode, bool showScale, bool showCrosshairs, QWidget * parent, Qt::WindowFlags windowFlags)
     :   QWidget( parent, windowFlags ),
         size(size),
         mymousemode(mousemode),
         scaleVisible(showScale),
         crosshairsVisible(showCrosshairs)
 {
     __init();
 }
Exemplo n.º 19
0
int startPLC(int argc,char **argv)
{
	if(__init(argc,argv) == 0){
		PLC_SetTimer(0, common_ticktime__);
		return 0;
	}else{
		return 1;
	}
}
Exemplo n.º 20
0
 MapControl::MapControl (QWidget * parent, Qt::WindowFlags windowFlags)
     :   QWidget( parent, windowFlags ),
         size(100,100),
         mymousemode(Panning),
         scaleVisible(false),
         crosshairsVisible(true)
 {
     __init();
 }
Exemplo n.º 21
0
	CurlWrapper()
	{
		memset(__error_buffer, 0, sizeof(__error_buffer));
		__handle = curl_easy_init();
		if (!__handle)
		{
			fatal2(__("unable to create a Curl handle"));
		}
		__init();
	}
Exemplo n.º 22
0
// Constructors
SWIPLContainer::SWIPLContainer(const QStringList &args)
{
    char *av[args.size()+1];

    for(int i = 0; i < args.size(); i++) {
        av[i] = (char *)((const char *) args.at(i).toAscii());
    }
    av[args.size()] = NULL;

    __init(args.size(), av);
}
Exemplo n.º 23
0
void DeviceMatrixCommon::__open() throw(string)
{
	if(_fd != -1)
		throw(string("DeviceMatrixCommon::__open: device not closed"));

	if((_fd = ::open(_device_node.c_str(), O_RDWR | O_NOCTTY | O_EXCL, 0)) < 0)
		throw(string("DeviceMatrixCommon::DeviceMatrixCommon::open(") + _device_node + ")");

	ioctl(_fd, TIOCEXCL, 1);

	_initserial();
	__init();
}
Exemplo n.º 24
0
void _start(int argc, char **argv)
{
   memoryInitialize();
   __init();
   fsdev_init();

   int ret = main(argc, argv);

   fsdev_exit();
//   __fini();
   memoryRelease();
   SYSRelaunchTitle(0, 0);
   exit(0);
}
Exemplo n.º 25
0
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
	if(fdwReason == DLL_PROCESS_ATTACH)
	{
		WSADATA wsadata;
		WSAStartup(MAKEWORD(2,1),&wsadata);
		__init();

	}else if (fdwReason == DLL_PROCESS_DETACH)
	{
		__finit();
		WSACleanup();
	}
}
Exemplo n.º 26
0
 //! prepare for capacity
 explicit map( size_t n, const as_capacity_t & ) :
 itmax(n),
 slots( htable::compute_slots_for(itmax) ),
 klist(),
 kpool(0,0),
 hslot(0),
 hpool(0,0),
 wlen(0),
 wksp(0),
 hash(),
 hmem()
 {
     __init();
 }
Exemplo n.º 27
0
/* HBL elf entry point */
int __entry_menu(int argc, char **argv)
{
   InitFunctionPointers();
   memoryInitialize();
   __init();
   fsdev_init();

   int ret = main(argc, argv);

   fsdev_exit();
//   __fini();
   memoryRelease();
   return ret;
}
Exemplo n.º 28
0
void    __interrupt() __frame() Reset_Handler( void )
{
                                                /* Set flash wait states to 3 */
        PREF_FCON = (PREF_FCON & 0xFFFFFFF0) | 0x00000003;
        SCU_GCU_PEFLAG =0xFFFFFFFF;             /* Clear existing parity errors if any */
        SCU_GCU_PEEN = 0;                       /* Disable parity */

        /*
         *      Anticipate possible ROM/RAM remapping
         *      by loading the 'real' program address.
         */
        __remap_pc();
        /*
         *      Initialize stack pointer.
         */
        __setsp( _lc_ub_stack );
        /*
         *      Call a user function which initializes hardware,
         *      such as ROM/RAM re-mapping or MMU configuration.
         */
        SystemInit();
        /*
         *      Copy initialized sections from ROM to RAM
         *      and clear uninitialized data sections in RAM.
         */
        __init();
        __asm( "_cptable_handled:" );                                   /* symbol may be used by debugger       */

        /*
         * Load VTOR register with the actual vector table
         * start address
         */
        VTOR = (unsigned int)_lc_vtor_value;
        
#ifdef __POSIX__
        __setsp( _posix_boot_stack_top );
#endif
#if  __PROF_ENABLE__
        __prof_init();
#endif
#ifdef __POSIX__
        exit( posix_main() );
#elif defined __USE_ARGC_ARGV
        exit( main( _argcv( argcv, __ARGCV_BUFSIZE ), (char **)argcv ) );
#else
        exit( main( 0, NULL ) );
#endif
        return;
}
Exemplo n.º 29
0
SWIPLContainer::SWIPLContainer()
{
    // Run with empty params by default
    char *argv[] = {
#ifdef Q_OS_WIN
        (char*) "",
#else
        (char*) QCoreApplication::argv()[0],
#endif
        (char*) "-g",
        (char*) "true",
        NULL
    };
    __init(3, argv);
}
Exemplo n.º 30
0
 //! copy ctor
 explicit map( const map &other ) :
 itmax(other.size()),
 slots(htable::compute_slots_for(itmax)),
 klist(),
 kpool(0,0),
 hslot(0),
 hpool(0,0),
 wlen(0),
 wksp(0),
 hash(),
 hmem()
 {
     __init();
     try { other.__duplicate_into( *this ); }
     catch(...) {__release(); throw;        }
 }