Win32OperatingSystem.st
changeset 8792 6852892b27cd
parent 8783 41f53c93fb79
child 8800 b1762fb45942
equal deleted inserted replaced
8791:1171ee15fa9c 8792:6852892b27cd
  3228 	    fprintf(stderr, "stdin %x\n", lpsiStartInfo.hStdInput);
  3228 	    fprintf(stderr, "stdin %x\n", lpsiStartInfo.hStdInput);
  3229 	    fprintf(stderr, "stdout %x\n",lpsiStartInfo.hStdOutput);
  3229 	    fprintf(stderr, "stdout %x\n",lpsiStartInfo.hStdOutput);
  3230 	    fprintf(stderr, "stderr %x\n",lpsiStartInfo.hStdError);
  3230 	    fprintf(stderr, "stderr %x\n",lpsiStartInfo.hStdError);
  3231 #endif
  3231 #endif
  3232 	} else {
  3232 	} else {
  3233 	    fprintf(stderr, "Win32OS: bad fd arg in createProcess\n");
  3233 	    fprintf(stderr, "Win32OS [warning]: bad fd arg in createProcess\n");
  3234 	}
  3234 	}
  3235 
  3235 
  3236 	if (doFork == true) {
  3236 	if (doFork == true) {
  3237 #ifdef PROCESSDEBUGWIN32
  3237 #ifdef PROCESSDEBUGWIN32
  3238 	    fprintf(stderr, "create process cmdPath:<%s> cmdLine:<%s> in <%s>\n", cmdPath, cmdLine, dir);
  3238 	    fprintf(stderr, "create process cmdPath:<%s> cmdLine:<%s> in <%s>\n", cmdPath, cmdLine, dir);
  3365     "low level close of a filedescriptor"
  3365     "low level close of a filedescriptor"
  3366 
  3366 
  3367 %{
  3367 %{
  3368     if (__isExternalAddressLike(anIntegerOrHandle) ) {
  3368     if (__isExternalAddressLike(anIntegerOrHandle) ) {
  3369        if( !CloseHandle( anIntegerOrHandle ) ) {
  3369        if( !CloseHandle( anIntegerOrHandle ) ) {
  3370 	   fprintf( stderr, "Could not close handle : %x\n", anIntegerOrHandle);
  3370 	   fprintf( stderr, "Win32OS [warning]: Could not close handle : %x\n", anIntegerOrHandle);
  3371        }
  3371        }
  3372        RETURN(self);
  3372        RETURN(self);
  3373     }
  3373     }
  3374     if (__isSmallInteger(anIntegerOrHandle)) {
  3374     if (__isSmallInteger(anIntegerOrHandle)) {
  3375 	close(__intVal(anIntegerOrHandle));
  3375 	close(__intVal(anIntegerOrHandle));
  3525     if (create == 0) {
  3525     if (create == 0) {
  3526 	fileHandle = nil;
  3526 	fileHandle = nil;
  3527 	argumentError = @symbol(missingCreateMode);
  3527 	argumentError = @symbol(missingCreateMode);
  3528 	goto badArgument;
  3528 	goto badArgument;
  3529     }
  3529     }
  3530 fprintf(stderr, "name:<%s> access:%x share:%x create:%x attr:%x\n",
  3530 #ifdef PROCESSDEBUGWIN32
       
  3531     fprintf(stderr, "name:<%s> access:%x share:%x create:%x attr:%x\n",
  3531 		name, access, share, create, attr);
  3532 		name, access, share, create, attr);
  3532 
  3533 #endif
  3533     h = CreateFile(name, access, share, 0 /* sa */, create, attr, 0 /* hTempl */);
  3534     h = CreateFile(name, access, share, 0 /* sa */, create, attr, 0 /* hTempl */);
  3534     if (h != INVALID_HANDLE_VALUE) {
  3535     if (h != INVALID_HANDLE_VALUE) {
  3535 	__externalAddressVal(fileHandle) = (void *)h;
  3536 	__externalAddressVal(fileHandle) = (void *)h;
  3536     } else {
  3537     } else {
  3537 	fileHandle = nil;
  3538 	fileHandle = nil;
  5097     "/ or not supported by OS
  5098     "/ or not supported by OS
  5098     "/
  5099     "/
  5099     ^ self primitiveFailed
  5100     ^ self primitiveFailed
  5100 !
  5101 !
  5101 
  5102 
  5102 terminateProcess:processId
  5103 terminateProcess:processHandle
  5103     "terminate a process.
  5104     "terminate a process.
  5104      The process has a chance to do some cleanup.
  5105      The process has a chance to do some cleanup.
  5105      WIN32:
  5106      WIN32:
  5106 	 Under unix, we have terminateProcess, which does a soft
  5107 	 Under unix, we have terminateProcess, which does a soft
  5107 	 terminate (giving the process a chance to cleanup) and
  5108 	 terminate (giving the process a chance to cleanup) and
  5112 	 Use it only in extreme circumstances. The state of
  5113 	 Use it only in extreme circumstances. The state of
  5113 	 global data maintained by dynamic-link libraries (DLLs)
  5114 	 global data maintained by dynamic-link libraries (DLLs)
  5114 	 may be compromised if TerminateProcess is used.
  5115 	 may be compromised if TerminateProcess is used.
  5115      TODO: send it a WM_QUIT instead, to allow for proper shutdown."
  5116      TODO: send it a WM_QUIT instead, to allow for proper shutdown."
  5116 
  5117 
  5117     self terminateProcess:processId exitCode:0
  5118     self terminateProcess:processHandle exitCode:0
  5118 !
  5119 !
  5119 
  5120 
  5120 terminateProcess:processId exitCode:exitCode
  5121 terminateProcess:processHandle exitCode:exitCode
  5121     "terminate a process.
  5122     "terminate a process.
  5122      The process should have a chance to do some cleanup.
  5123      The process should have a chance to do some cleanup.
  5123      WIN32:
  5124      WIN32:
  5124 	 Under unix, we have terminateProcess, which does a soft
  5125 	 Under unix, we have terminateProcess, which does a soft
  5125 	 terminate (giving the process a chance to cleanup) and
  5126 	 terminate (giving the process a chance to cleanup) and
  5131 	 global data maintained by dynamic-link libraries (DLLs)
  5132 	 global data maintained by dynamic-link libraries (DLLs)
  5132 	 may be compromised if TerminateProcess is used.
  5133 	 may be compromised if TerminateProcess is used.
  5133      TODO: send it a WM_QUIT instead, to allow for proper shutdown."
  5134      TODO: send it a WM_QUIT instead, to allow for proper shutdown."
  5134 
  5135 
  5135 %{
  5136 %{
  5136     if (__isExternalAddressLike(processId) ) {
  5137     if (__isExternalAddressLike(processHandle) ) {
  5137 	HANDLE hProcess = _HANDLEVal(processId);
  5138 	HANDLE hProcess = _HANDLEVal(processHandle);
  5138 
  5139 
  5139 #ifdef PROCESS1DEBUGWIN32
  5140 #ifdef PROCESS1DEBUGWIN32
  5140 	printf("TerminateProcess handle: %x\n", hProcess);
  5141 	printf("TerminateProcess handle: %x\n", hProcess);
  5141 #endif
  5142 #endif
  5142 	if (hProcess != 0) {
  5143 	if (hProcess != 0) {
  5143 	    TerminateProcess(hProcess, __intVal(exitCode));
  5144 	    TerminateProcess(hProcess, __intVal(exitCode));
  5144 	}
  5145 	} else {
  5145     }
  5146 	    fprintf(stderr, "Win32OS [warning]: wrong hProcess in TerminateProcess\n");
  5146 #ifdef PROCESS1DEBUGWIN32
  5147 	}
  5147     else {
  5148     } else {
  5148 	printf("TerminateProcess wrong handle\n");
  5149 	fprintf(stderr, "Win32OS [warning]: wrong processHandle in TerminateProcess\n");
  5149     }
  5150     }
  5150 #endif
       
  5151 %}
  5151 %}
  5152 
  5152 
  5153     "Modified: / 28.12.1995 / 15:05:37 / stefan"
  5153     "Modified: / 28.12.1995 / 15:05:37 / stefan"
  5154     "Modified: / 27.1.1998 / 20:05:47 / cg"
  5154     "Modified: / 27.1.1998 / 20:05:47 / cg"
  5155 !
  5155 !
  5156 
  5156 
  5157 terminateProcessGroup:processGroupHandle
  5157 terminateProcessGroup:processGroupHandle
  5158     "terminate a process group.
  5158     "terminate a process group.
  5159      The processes should have a chance to do some cleanup.
  5159      The processes should have a chance to do some cleanup.
  5160      WIN32:
  5160      WIN32:
  5161 	 The TerminateProcess function is used to unconditionally cause
  5161 	 The processGroup is terminated by sending it a CTRL-C
  5162 	 a process to exit.
  5162 	 using GenerateConsoleCtrlEvent."
  5163 	 Use it only in extreme circumstances. The state of
       
  5164 	 global data maintained by dynamic-link libraries (DLLs)
       
  5165 	 may be compromised if TerminateProcess is used.
       
  5166      Not implemented - TODO: enumerate all sub-processes and terminate them all ..."
       
  5167 
  5163 
  5168 %{
  5164 %{
  5169     if (__isExternalAddressLike(processGroupHandle) ) {
  5165     if (__isExternalAddressLike(processGroupHandle) ) {
  5170 	HANDLE hProcessGroup = _HANDLEVal(processGroupHandle);
  5166 	HANDLE hProcessGroup = _HANDLEVal(processGroupHandle);
  5171 	DWORD processGroupId = _HANDLEVal(processGroupHandle);
  5167 	DWORD processGroupId;
  5172 
  5168 
  5173 	processGroupId = __intVal( ((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(processGroupHandle))->pid );
  5169 	if (hProcessGroup != (HANDLE)0) {
       
  5170 	    processGroupId = __intVal( ((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(processGroupHandle))->pid );
  5174 
  5171 
  5175 #ifdef PROCESS1DEBUGWIN32
  5172 #ifdef PROCESS1DEBUGWIN32
  5176 	printf("TerminateProcessGroup processGroupHandle: %x (%d)\n", hProcessGroup, processGroupId);
  5173 	    printf("TerminateProcessGroup processGroupHandle: %x (%d)\n", hProcessGroup, processGroupId);
  5177 #endif
  5174 #endif
  5178 	if (hProcessGroup != 0) {
       
  5179 	    GenerateConsoleCtrlEvent(CTRL_C_EVENT, processGroupId);
  5175 	    GenerateConsoleCtrlEvent(CTRL_C_EVENT, processGroupId);
  5180 	}
  5176 	} else {
  5181     }
  5177 	    fprintf(stderr, "Win32OS [warning]: wrong hProcessGroup in TerminateProcessGroup \n");
  5182 #ifdef PROCESS1DEBUGWIN32
  5178 	}
  5183     else {
  5179     } else {
  5184 	printf("TerminateProcessGroup wrong processGroupHandle\n");
  5180 	fprintf(stderr, "Win32OS [warning]: wrong processGroupHandle in TerminateProcessGroup \n");
  5185     }
  5181     }
  5186 #endif
       
  5187 %}
  5182 %}
  5188 ! !
  5183 ! !
  5189 
  5184 
  5190 !Win32OperatingSystem class methodsFor:'ipc support'!
  5185 !Win32OperatingSystem class methodsFor:'ipc support'!
  5191 
  5186 
  7641 		__threadErrno = 0;
  7636 		__threadErrno = 0;
  7642 		@global(LastErrorNumber) = nil;
  7637 		@global(LastErrorNumber) = nil;
  7643 	    } else {
  7638 	    } else {
  7644 		__threadErrno = EBADF;
  7639 		__threadErrno = EBADF;
  7645 		if (@global(InfoPrinting) == true) {
  7640 		if (@global(InfoPrinting) == true) {
  7646 		    fprintf(stderr, "OS [info]: select errno = %d\n", __threadErrno);
  7641 		    fprintf(stderr, "Win32OS [info]: select errno = %d\n", __threadErrno);
  7647 		}
  7642 		}
  7648 		@global(LastErrorNumber) = __MKSMALLINT(__threadErrno);
  7643 		@global(LastErrorNumber) = __MKSMALLINT(__threadErrno);
  7649 	    }
  7644 	    }
  7650 	    RETURN ( nil );
  7645 	    RETURN ( nil );
  7651 	}
  7646 	}
  7682 	    if (fd < 20000) {
  7677 	    if (fd < 20000) {
  7683 		RETURN ( __ArrayInstPtr(writeFdArray)->a_element[fd-10000] );
  7678 		RETURN ( __ArrayInstPtr(writeFdArray)->a_element[fd-10000] );
  7684 	    }
  7679 	    }
  7685 	    RETURN ( __ArrayInstPtr(exceptFdArray)->a_element[fd-20000] );
  7680 	    RETURN ( __ArrayInstPtr(exceptFdArray)->a_element[fd-20000] );
  7686 	}
  7681 	}
  7687 	printf("wait Handles ret = %d error2 %d\n", ret, GetLastError());
  7682 	fprintf(stderr, "Win32OS [info]: wait Handles ret = %d error2 %d\n", ret, GetLastError());
  7688 	goto fail;
  7683 	goto fail;
  7689     } else {
  7684     } else {
  7690 
  7685 
  7691 polling:
  7686 polling:
  7692 
  7687 
  9296     libraries...
  9291     libraries...
  9297 "
  9292 "
  9298 !
  9293 !
  9299 
  9294 
  9300 version
  9295 version
  9301     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.176 2005-03-11 12:50:04 cg Exp $'
  9296     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.177 2005-03-16 22:28:50 cg Exp $'
  9302 ! !
  9297 ! !
  9303 
  9298 
  9304 !Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
  9299 !Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
  9305 
  9300 
  9306 closeFile
  9301 closeFile
  9323     I represent a generic HANDLE, which can be closed via CloseHandle.
  9318     I represent a generic HANDLE, which can be closed via CloseHandle.
  9324 "
  9319 "
  9325 !
  9320 !
  9326 
  9321 
  9327 version
  9322 version
  9328     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.176 2005-03-11 12:50:04 cg Exp $'
  9323     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.177 2005-03-16 22:28:50 cg Exp $'
  9329 ! !
  9324 ! !
  9330 
  9325 
  9331 !Win32OperatingSystem::Win32Handle methodsFor:'io'!
  9326 !Win32OperatingSystem::Win32Handle methodsFor:'io'!
  9332 
  9327 
  9333 readBytes:count into:aByteBuffer startingAt:firstIndex
  9328 readBytes:count into:aByteBuffer startingAt:firstIndex
 10343 ! !
 10338 ! !
 10344 
 10339 
 10345 !Win32OperatingSystem class methodsFor:'documentation'!
 10340 !Win32OperatingSystem class methodsFor:'documentation'!
 10346 
 10341 
 10347 version
 10342 version
 10348     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.176 2005-03-11 12:50:04 cg Exp $'
 10343     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.177 2005-03-16 22:28:50 cg Exp $'
 10349 ! !
 10344 ! !
 10350 
 10345 
 10351 Win32OperatingSystem initialize!
 10346 Win32OperatingSystem initialize!
 10352 Win32OperatingSystem::RegistryEntry initialize!
 10347 Win32OperatingSystem::RegistryEntry initialize!