⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 T-kernel 的extension源代码
💻 C
字号:
/* *---------------------------------------------------------------------- *    T-Kernel / Standard Extension * *    Copyright (C) 2006 by Ken Sakamura. All rights reserved. *    T-Kernel / Standard Extension is distributed  *      under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* *	main.c (crttkse) * *	Process startup */#include <basic.h>#include <extension/extension.h>#include <alloca.h>#include <sys/msghdr.h>#define TSD_EMH_RTN_2	2/* * Initialization and loading of shared library (crt1[fs].o) */IMPORT	ER	(*__initloading)( void );/* * Compiler-dependent initialization processing */IMPORT	void	_init_compiler( void );/* * Initialization of library */IMPORT	void	_init_library( void );/* * Error occurred during startup processing */EXPORT	ER	_StartupError = E_OK;/* ------------------------------------------------------------------------ */EXPORT	FUNCP	_MsgHandlers[N_MsgHandlers];	/* Message handler definitions */EXPORT	jmp_buf	_MsgHdrJmpBuf;			/* Return position of message handler *//* * Processing of message handler */#if ALLOCA_NOSPTIMPORT	WER	_exec_msghdr( W fexcode, W msgsz );EXPORT	WER	__exec_msghdr( W fexcode, W msgsz, MESSAGE *msgbuf ){#elseLOCAL	WER	_exec_msghdr( W fexcode, W msgsz );LOCAL WER _exec_msghdr( W fexcode, W msgsz ){	MESSAGE	*msgbuf = alloca((size_t)MSGSIZE((UW)msgsz));#endif	FUNCP	hdr;	W	pid;	pid = tkse_rcv_msg((W)MSGMASK(fexcode), msgbuf, (W)MSGSIZE((UW)msgsz), (W)((UW)CLR | (UW)NOWAIT));	if ( pid < E_OK ) {		if ( (pid == E_PAR) && (msgbuf->msg_size > DefaultMessageSize) ) {			/* Shortage of message buffer size */			return msgbuf->msg_size;		}		return pid;	}	hdr = _MsgHandlers[fexcode - 1];	if ( hdr == MH_TERM ) {		return 0;		/* Abnormal termination */	}	if ( (hdr == MH_BREAK) || (hdr == MH_NONE) || (hdr == NULL) ) {		return TSD_EMH_RTN_2;			/* Break */	}	if ( setjmp(_MsgHdrJmpBuf) == 0 ) {		/* Execute message handler */		(*hdr)(pid, msgbuf);	}	return TSD_EMH_RTN_2;			/* Terminate message handler */}/* * Task forced exception handler *	fexcode = 0	Task termination request *	fexcode = 1-31	Start message handler */EXPORT void _C_fexchdr( W fexcode ){	W	n;	if ( fexcode == 0 ) {		/* Terminate task */		tkse_ext_tsk();		/* no return */	}	/* Repeat while messages are left in the queue. */	do {		n = _exec_msghdr(fexcode, DefaultMessageSize);		if ( n > DefaultMessageSize ) {			n = _exec_msghdr(fexcode, n);		}		if ( (n < 0) || (n > DefaultMessageSize) ) {			n = 1;		}	} while ( (fexcode = tkse_RetMsgHdr(n)) > 0 );}/* * Task forced exception handler startup routine */IMPORT void _fexchdr( void );/* ------------------------------------------------------------------------ */IMPORT W MAIN( MESSAGE* );IMPORT void exit(int status);/* * Process startup */#if ALLOCA_NOSPTEXPORT void _proc_startup( W msgsz, MESSAGE *msg ){#elseEXPORT void _C_startup( W msgsz ){	/* Reserve for one extra word. */	MESSAGE	*msg = alloca((size_t)(msgsz + (W)sizeof(W)));#endif	W	i;	/* Clear message handler */	for ( i = 0; i < N_MsgHandlers; ++i ) {		_MsgHandlers[i] = 0;	}	/* Initial setting of task forced exception handler */	tkse_DefMsgHdr(1, (FUNCP)_fexchdr, NULL);	/* Receive startup message */	tkse_rcv_msg(MM_ALL, msg, msgsz, (W)((UW)STARTMSG | (UW)CLR | (UW)WAIT));#ifdef SO_SUPPORT	/* Initialization and loading of shared library	 *	Note that before a shared library is loaded here,	 *	linked shared libraries cannot be called.	 */	i = (*__initloading)();	if ( i < E_OK ) {		_StartupError = i;	}#endif	/* Initialization of library */	_init_library();	/* Compiler-dependent initialization processing (such as execution of C++ constructor) */	_init_compiler();	/* Execution of MAIN() */	i = MAIN(msg);	/* Termination including compiler-dependent termination processing (such as execution of C++ destructor) */	exit(i);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -