void SysInit( void ) { AllocTag = AllocateResourceTag( (void *)GetNLMHandle(), (BYTE *)"Open Watcom Sampler Work Area", AllocSignature ); SwitchModeTag = AllocateResourceTag( (void*)GetNLMHandle(), (BYTE *)"Open Watcom Sampler ModeSwitchMon", EventSignature); }
static int wsa_startup_with_handle (WORD wVersionRequested, LPWSADATA data, void *handle) { APP_DATA *app_data; if (!(app_data = (APP_DATA*) get_app_data(gLibId))) return APR_EGENERAL; app_data->gs_startup_rtag = AllocateResourceTag(handle, "WinSock Start-up", WS_LOAD_ENTRY_SIGNATURE); app_data->gs_socket_rtag = AllocateResourceTag(handle, "WinSock socket()", WS_SKT_SIGNATURE); app_data->gs_lookup_rtag = AllocateResourceTag(handle, "WinSock Look-up", WS_LOOKUP_SERVICE_SIGNATURE); app_data->gs_event_rtag = AllocateResourceTag(handle, "WinSock Event", WS_WSAEVENT_SIGNATURE); app_data->gs_pcp_rtag = AllocateResourceTag(handle, "WinSock C-Port", WS_CPORT_SIGNATURE); return WSAStartupRTags(wVersionRequested, data, app_data->gs_startup_rtag, app_data->gs_socket_rtag, app_data->gs_lookup_rtag, app_data->gs_event_rtag, app_data->gs_pcp_rtag); }
static int InstallConsoleHandler(void) { /* Our command line handler interfaces the system operator with this NLM */ NX_WRAP_INTERFACE(CommandLineInterpreter, 2, (void*)&(ConsoleHandler.parser)); ConsoleHandler.rTag = AllocateResourceTag(getnlmhandle(), "Command Line Processor", ConsoleCommandSignature); if (!ConsoleHandler.rTag) { printf("Error on allocate resource tag\n"); return 1; } RegisterConsoleCommand(&ConsoleHandler); /* The Remove procedure unregisters the console handler */ return 0; }
int _NonAppStart ( void *NLMHandle, void *errorScreen, const char *cmdLine, const char *loadDirPath, size_t uninitializedDataLength, void *NLMFileHandle, int (*readRoutineP)( int conn, void *fileHandle, size_t offset, size_t nbytes, size_t *bytesRead, void *buffer ), size_t customDataOffset, size_t customDataSize, int messageCount, const char **messages ) { #pragma unused(cmdLine) #pragma unused(loadDirPath) #pragma unused(uninitializedDataLength) #pragma unused(NLMFileHandle) #pragma unused(readRoutineP) #pragma unused(customDataOffset) #pragma unused(customDataSize) #pragma unused(messageCount) #pragma unused(messages) // register for down server event rtag_t rt = AllocateResourceTag(NLMHandle, "Apache2 Down Server Callback", EventSignature); NX_WRAP_INTERFACE((void *)ap_down_server_cb, 2, (void **)&ref); NX_WRAP_INTERFACE((void *)ap_dummy_cb, 2, (void **)&dum); eh = RegisterForEventNotification(rt, EVENT_DOWN_SERVER, EVENT_PRIORITY_APPLICATION, ref, dum, NULL); // clean-up NXVmRegisterExitHandler(ap_cb_destroy, NULL); }
/***************************************************************************** // Initialise runtime environemnt. Equivalent of old prelude *****************************************************************************/ int __init_environment( void * reserved ) { int rc = -1; if(NULL == (NLMHandle = getnlmhandle())) return -1; if(NULL == (AllocRTag = AllocateResourceTag( NLMHandle, "OpenWatcom CLIB Memory", AllocSignature ))) return -1; _saved_DS = __DS(); /* // Call initialisation routines where priority is <= 1 and set the // initialisation finish level to 1 */ __InitRtns( INIT_PRIORITY_THREAD ); InitFiniLevel = INIT_PRIORITY_THREAD; /* // Initialise multiple thread support */ if(__CreateFirstThreadData()) { __InitMultipleThread(); /* // Call initiliation routines at priority 255 (all) and the set the // initialisation finish level to 255 */ __InitRtns( 255 ); InitFiniLevel = 255; /* // Environment initialised. */ rc = 0; } return( rc ); }
int _NonAppStart( void *NLMHandle, void *errorScreen, const char *cmdLine, const char *loadDirPath, size_t uninitializedDataLength, void *NLMFileHandle, int (*readRoutineP)( int conn, void *fileHandle, size_t offset, size_t nbytes, size_t *bytesRead, void *buffer ), size_t customDataOffset, size_t customDataSize, int messageCount, const char **messages ) { NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0); #ifndef __GNUC__ #pragma unused(cmdLine) #pragma unused(loadDirPath) #pragma unused(uninitializedDataLength) #pragma unused(NLMFileHandle) #pragma unused(readRoutineP) #pragma unused(customDataOffset) #pragma unused(customDataSize) #pragma unused(messageCount) #pragma unused(messages) #endif /* ** Here we process our command line, post errors (to the error screen), ** perform initializations and anything else we need to do before being able ** to accept calls into us. If we succeed, we return non-zero and the NetWare ** Loader will leave us up, otherwise we fail to load and get dumped. */ gAllocTag = AllocateResourceTag(NLMHandle, "<library-name> memory allocations", AllocSignature); if(!gAllocTag) { OutputToScreen(errorScreen, "Unable to allocate resource tag for " "library memory allocations.\n"); return -1; } gLibId = register_library(DisposeLibraryData); if(gLibId < -1) { OutputToScreen(errorScreen, "Unable to register library with kernel.\n"); return -1; } gLibHandle = NLMHandle; gLibLock = NXMutexAlloc(0, 0, &liblock); if(!gLibLock) { OutputToScreen(errorScreen, "Unable to allocate library data lock.\n"); return -1; } return 0; }
char *ParsePortSpec( const char **spec ) { const char *parm; int port; int com_num; int rc; int hardware_type; int board_number; int num; int *var; parm = (spec == NULL) ? "" : *spec; board_number = AIO_BOARD_NUMBER_WILDCARD; port = -1; com_num = 1; for( ;; ) { if( *parm == 'b' ) { var = &board_number; ++parm; } else if( *parm == 'p' ) { var = &port; ++parm; } else if( !(*parm >= '0' && *parm <= '9') ) { break; } else { var = &com_num; } if( !(*parm >= '0' && *parm <= '9') ) { return( TRP_ERR_invalid_serial_port_number ); } num = 0; do { num = num * 10 + (*parm - '0'); ++parm; } while( *parm >= '0' && *parm <= '9' ); *var = num; } if( *parm != '\0' && *parm != '.' ) return( TRP_ERR_invalid_serial_port_number ); if( spec != NULL ) *spec = parm; if( PortNumber != -1 ) { AIOReleasePort( ComPortHandle ); } if( SerialTag == 0 ) { SerialTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"Debug Server Serial IO", ASYNCIOSignature ); } if( port == -1 ) port = com_num - 1; num = port; hardware_type = AIO_COMX_TYPE; switch( rc = AIOAcquirePortWithRTag( &hardware_type, &board_number, &port, &ComPortHandle, (LONG)SerialTag ) ) { case AIO_SUCCESS: break; case AIO_QUALIFIED_SUCCESS: if( port == num ) break; case AIO_TYPE_NUMBER_INVALID: case AIO_BOARD_NUMBER_INVALID: case AIO_PORT_NUMBER_INVALID: case AIO_RTAG_INVALID: case AIO_PORT_NOT_AVAILABLE: case AIO_FAILURE: return( TRP_ERR_serial_port_not_available ); default: { #undef static static char num[2]; rc = -rc; num[0] = rc / 10 + '0'; num[1] = rc % 10; num[2] = 0; return( num ); } } PortNumber = port; return( NULL ); }
extern "C" LONG f_nlmEntryPoint( struct LoadDefinitionStructure * moduleHandle, struct ScreenStruct * initScreen, char * commandLine, char * loadDirectoryPath, LONG uninitializedDataLength, LONG fileHandle, LONG (*ReadRoutine) (LONG handle, LONG offset, char * buffer, LONG length), LONG customDataOffset, LONG customDataSize) { char * pszTmp; char * pszArgStart; int iArgC; int iTotalArgChars; int iArgSize; char ** ppszArgV = NULL; char * pszArgs = NULL; char * pszDestArg; bool bFirstPass = true; char cEnd; ARG_DATA * pArgData = NULL; LONG sdRet = 0; char * pszThreadName; char * pszModuleName; int iModuleNameLen; int iThreadNameLen; int iLoadDirPathSize; void * hThread = NULL; (void)initScreen; (void)uninitializedDataLength; (void)fileHandle; (void)ReadRoutine; (void)customDataOffset; (void)customDataSize; if( f_atomicInc( &gv_NetWareStartupCount) != 1) { goto Exit; } gv_MyModuleHandle = moduleHandle; gv_bUnloadCalled = FALSE; // Allocate the needed resource tags if( (gv_lAllocRTag = AllocateResourceTag( gv_MyModuleHandle, "FLAIM Memory", AllocSignature)) == NULL) { sdRet = 1; goto Exit; } // Syncronized start if (moduleHandle->LDFlags & 4) { gv_lFlmSyncSem = kSemaphoreAlloc( (BYTE *)"FLAIM_SYNC", 0); } // Initialize NSS if( RC_BAD( f_nssInitialize())) { sdRet = 1; goto Exit; } pszModuleName = (char *)(&moduleHandle->LDFileName[ 1]); iModuleNameLen = (int)(moduleHandle->LDFileName[ 0]); // First pass: Count the arguments in the command line // and determine how big of a buffer we will need. // Second pass: Put argments into allocated buffer. Parse_Args: iTotalArgChars = 0; iArgC = 0; iLoadDirPathSize = f_strlen( (const char *)loadDirectoryPath); iArgSize = iLoadDirPathSize + iModuleNameLen; if( !bFirstPass) { ppszArgV[ iArgC] = pszDestArg; f_memcpy( pszDestArg, loadDirectoryPath, iLoadDirPathSize); f_memcpy( &pszDestArg[ iLoadDirPathSize], pszModuleName, iModuleNameLen); pszDestArg[ iArgSize] = 0; pszDestArg += (iArgSize + 1); } iArgC++; iTotalArgChars += iArgSize; pszTmp = commandLine; for (;;) { // Skip leading blanks. while( *pszTmp && *pszTmp == ' ') { pszTmp++; } if( *pszTmp == 0) { break; } if( *pszTmp == '"' || *pszTmp == '\'') { cEnd = *pszTmp; pszTmp++; } else { cEnd = ' '; } pszArgStart = pszTmp; iArgSize = 0; // Count the characters in the parameter. while( *pszTmp && *pszTmp != cEnd) { iArgSize++; pszTmp++; } if( !iArgSize && cEnd == ' ') { break; } // If 2nd pass, save the argument. if( !bFirstPass) { ppszArgV[ iArgC] = pszDestArg; if( iArgSize) { f_memcpy( pszDestArg, pszArgStart, iArgSize); } pszDestArg[ iArgSize] = 0; pszDestArg += (iArgSize + 1); } iArgC++; iTotalArgChars += iArgSize; // Skip trailing quote or blank. if( *pszTmp) { pszTmp++; } } if( bFirstPass) { if ((ppszArgV = (char **)Alloc( sizeof( char *) * iArgC, gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } if( (pszArgs = (char *)Alloc( iTotalArgChars + iArgC, gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } pszDestArg = pszArgs; bFirstPass = false; goto Parse_Args; } iThreadNameLen = (int)(moduleHandle->LDName[ 0]); if( (pszThreadName = (char *)Alloc( iThreadNameLen + 1, gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } f_memcpy( pszThreadName, (char *)(&moduleHandle->LDName[ 1]), iThreadNameLen); pszThreadName[ iThreadNameLen] = 0; if( (pArgData = (ARG_DATA *)Alloc( sizeof( ARG_DATA), gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } pArgData->ppszArgV = ppszArgV; pArgData->pszArgs = pszArgs; pArgData->iArgC = iArgC; pArgData->moduleHandle = moduleHandle; pArgData->pszThreadName = pszThreadName; gv_bMainRunning = TRUE; if( (hThread = kCreateThread( (BYTE *)"FTK main", f_nlmMainStub, NULL, 32768, (void *)pArgData)) == NULL) { gv_bMainRunning = FALSE; sdRet = 2; goto Exit; } if( kSetThreadLoadHandle( hThread, (LONG)moduleHandle) != 0) { (void)kDestroyThread( hThread); gv_bMainRunning = FALSE; sdRet = 2; goto Exit; } if( kScheduleThread( hThread) != 0) { (void)kDestroyThread( hThread); gv_bMainRunning = FALSE; sdRet = 2; goto Exit; } // Synchronized start if( moduleHandle->LDFlags & 4) { (void)kSemaphoreWait( gv_lFlmSyncSem); } Exit: if( sdRet != 0) { f_atomicDec( &gv_NetWareStartupCount); if( ppszArgV) { Free( ppszArgV); } if( pszArgs) { Free( pszArgs); } if( pszThreadName) { Free( pszThreadName); } if( pArgData) { Free( pArgData); } if( gv_lFlmSyncSem) { kSemaphoreFree( gv_lFlmSyncSem); gv_lFlmSyncSem = 0; } if( !gv_bUnloadCalled) { KillMe( moduleHandle); } } return( sdRet); }
int __init_environment(void * reserved){ #ifdef DEBUG_ME char *cmdLineP = Command; if( cmdLineP[0] == '?' || ( cmdLineP[0] == '-' && cmdLineP[1] == 'h' ) ) { OutputToScreen( systemConsoleScreen, "Use -d[options]\r\n" ); OutputToScreen( systemConsoleScreen, " options are:\r\n" ); OutputToScreen( systemConsoleScreen, " b = initial break\r\n" ); OutputToScreen( systemConsoleScreen, " a = all\r\n" ); OutputToScreen( systemConsoleScreen, " t = threads\r\n" ); OutputToScreen( systemConsoleScreen, " d = debug regs\r\n" ); OutputToScreen( systemConsoleScreen, " e = events\r\n" ); OutputToScreen( systemConsoleScreen, " i = IO\r\n" ); OutputToScreen( systemConsoleScreen, " x = network events\r\n" ); OutputToScreen( systemConsoleScreen, " m = misc\r\n" ); OutputToScreen( systemConsoleScreen, " r = requests\r\n" ); OutputToScreen( systemConsoleScreen, " o = errors\r\n" ); return( -1 ); } if( cmdLineP[0] == '-' && lower( cmdLineP[1] ) == 'd' ) { DebugMode = 1; cmdLineP += 2; while( isalpha( *cmdLineP ) ) { switch( lower( *cmdLineP ) ) { case 'b': BreakPoint(); break; case 'a': DebugClasses = -1; break; case 'r': DebugClasses |= D_REQ; break; case 'o': DebugClasses |= D_ERROR; break; case 't': DebugClasses |= D_THREAD; break; case 'd': DebugClasses |= D_DR; break; case 'e': DebugClasses |= D_EVENT; break; case 'i': DebugClasses |= D_IO; break; case 'x': DebugClasses |= D_NET; break; case 'm': DebugClasses |= D_MISC; break; } ++cmdLineP; } while( *cmdLineP == ' ' ) ++cmdLineP; } #endif ScreenTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"Debug server screens", ScreenSignature ); AllocTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"Debug server work area", AllocSignature ); SemaphoreTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"Debug server semaphores", SemaphoreSignature ); ProcessTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"Debug server processes", ProcessSignature ); TimerTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"Debugger time out", TimerSignature ); InterruptTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"Debugger interrupts", InterruptSignature ); DebugTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"WVIDEO Debugger", DebuggerSignature ); BreakTag = AllocateResourceTag( MyNLMHandle, (BYTE *)"WVIDEO Break Points", BreakpointSignature ); if( OpenScreen( TRP_The_WATCOM_Debugger, ScreenTag, &screenID ) != 0 ) { screenID = 0; } debugScreen = 0; #ifdef DEBUG_ME if( DebugMode ) { if( OpenScreen( TRP_The_WATCOM_Debugger, ScreenTag, &debugScreen ) != 0 ) { debugScreen = 0; } } #endif if( screenID == 0 || ( DebugMode && ( debugScreen == 0 ) ) ) { OutputToScreen( systemConsoleScreen, TRP_NLM_no_screen ); OutputToScreen( systemConsoleScreen, "\r\n" ); } else { EnableInputCursor( screenID ); } return 0; }