- Timestamp:
- Sep 12, 2000, 6:29:59 AM (25 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winexebase.cpp
r3483 r4236 1 /* $Id: winexebase.cpp,v 1. 9 2000-05-02 20:53:14 sandervlExp $ */1 /* $Id: winexebase.cpp,v 1.10 2000-09-12 04:29:58 bird Exp $ */ 2 2 3 3 /* … … 48 48 //****************************************************************************** 49 49 //****************************************************************************** 50 Win32ExeBase::Win32ExeBase(HINSTANCE hInstance) 50 Win32ExeBase::Win32ExeBase(HINSTANCE hInstance) 51 51 : Win32ImageBase(hInstance), 52 52 fConsoleApp(FALSE), … … 62 62 Win32DllBase *dll; 63 63 64 //First delete all dlls loaded by LoadLibrary 64 //First delete all dlls loaded by LoadLibrary 65 65 //Then delete all dlls that were loaded by the exe 66 66 //(NOTE: This is what NT does; first delete loadlib dlls in LIFO order and … … 138 138 //****************************************************************************** 139 139 //****************************************************************************** 140 void Win32ExeBase::setCommandLine(char *cline)141 {142 ULONG cmdlength = strlen(cline) + 1;143 144 cmdLineA = (LPSTR)malloc(cmdlength);145 strcpy(cmdLineA, cline);146 cmdLineW = (LPWSTR)malloc(cmdlength*sizeof(WCHAR));147 AsciiToUnicode(cmdLineA, cmdLineW);148 }149 //******************************************************************************150 //****************************************************************************** -
trunk/src/kernel32/winexebase.h
r3059 r4236 1 /* $Id: winexebase.h,v 1. 1 2000-03-09 19:03:22 sandervlExp $ */1 /* $Id: winexebase.h,v 1.2 2000-09-12 04:29:58 bird Exp $ */ 2 2 3 3 /* … … 24 24 virtual ~Win32ExeBase(); 25 25 26 void setCommandLine(char *cline);27 LPSTR getCommandLineA() { return cmdLineA; };28 LPWSTR getCommandLineW() { return cmdLineW; };29 30 26 BOOL isConsoleApp() { return fConsoleApp; }; 31 27 -
trunk/src/kernel32/winexelx.cpp
r3375 r4236 1 /* $Id: winexelx.cpp,v 1. 6 2000-04-14 22:35:27 sandervlExp $ */1 /* $Id: winexelx.cpp,v 1.7 2000-09-12 04:29:58 bird Exp $ */ 2 2 3 3 /* … … 66 66 67 67 if(winexe) { 68 char *cmdline; 69 int cmdlen = strlen(ppib->pib_pchcmd); 70 71 cmdlen += strlen(ppib->pib_pchcmd+cmdlen+1); 72 cmdline = (char *)malloc(cmdlen+2); //term. 0 + space 73 strcpy(cmdline, ppib->pib_pchcmd); 74 strcat(cmdline, " "); 75 strcat(cmdline, ppib->pib_pchcmd+strlen(ppib->pib_pchcmd)+1); 76 winexe->setCommandLine(cmdline); 77 free(cmdline); 68 InitCommandLine(FALSE); 78 69 winexe->setEntryPoint((ULONG)EntryPoint); 79 70 winexe->start(); … … 88 79 //****************************************************************************** 89 80 //****************************************************************************** 90 Win32LxExe::Win32LxExe(HINSTANCE hInstance, PVOID pResData) 81 Win32LxExe::Win32LxExe(HINSTANCE hInstance, PVOID pResData) 91 82 : Win32ImageBase(hInstance), 92 83 Win32LxImage(hInstance, pResData), -
trunk/src/kernel32/winexepeldr.cpp
r3501 r4236 1 /* $Id: winexepeldr.cpp,v 1. 9 2000-05-09 18:56:09 sandervlExp $ */1 /* $Id: winexepeldr.cpp,v 1.10 2000-09-12 04:29:59 bird Exp $ */ 2 2 3 3 /* … … 47 47 //Called by ring 3 pe loader to create win32 executable 48 48 //****************************************************************************** 49 BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine, ULONG reservedMem) 49 BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine, ULONG reservedMem) 50 50 { 51 51 APIRET rc; … … 67 67 } 68 68 69 //exe length + space + (possibly) 2x'"' + cmd line length + 0 terminator 70 szFullCmdLine = (char *)malloc(strlen(szFileName) + 3 + strlen(szCmdLine) + 1); 71 //Enclose executable name in quotes if it (or it's directory) contains spaces 72 if(strchr(szFileName, ' ') != NULL) { 73 sprintf(szFullCmdLine, "\"%s\"", szFileName); 74 } 75 else strcpy(szFullCmdLine, szFileName); 76 strcat(szFullCmdLine, " "); 77 strcat(szFullCmdLine, szCmdLine); 78 WinExe->setCommandLine(szFullCmdLine); 79 dprintf(("Cmd line: %s", szFullCmdLine)); 80 free(szFullCmdLine); 69 /* Initiate the commandline. 70 * (Since PE.EXE takes no options we'll currently just skip the 71 * first parameter and used the passed in executable name.) 72 */ 73 szCmdLine = szCmdLine; /* ignored */ 74 InitCommandLine(szFileName); 81 75 82 76 if(getenv("WIN32_IOPL2")) { … … 95 89 return FALSE; 96 90 } 91 97 92 OS2UnsetExceptionHandler(&exceptFrame); 98 93 if(WinExe->isConsoleApp()) { … … 112 107 //****************************************************************************** 113 108 //****************************************************************************** 114 Win32PeLdrExe::Win32PeLdrExe(char *szFileName) : 115 Win32ImageBase(-1), 109 Win32PeLdrExe::Win32PeLdrExe(char *szFileName) : 110 Win32ImageBase(-1), 116 111 Win32ExeBase(-1), 117 112 Win32PeLdrImage(szFileName, TRUE) -
trunk/src/kernel32/wprocess.cpp
r4229 r4236 1 /* $Id: wprocess.cpp,v 1.9 0 2000-09-09 08:59:55 sandervlExp $ */1 /* $Id: wprocess.cpp,v 1.91 2000-09-12 04:29:59 bird Exp $ */ 2 2 3 3 /* … … 35 35 #include "odin32validate.h" 36 36 #include "exceptutil.h" 37 #include "oslibdos.h" 37 38 #include "oslibmisc.h" 38 39 #include "oslibdebug.h" … … 50 51 51 52 52 //****************************************************************************** 53 //****************************************************************************** 54 BOOL fIsOS2Image = FALSE; //TRUE -> Odin32 OS/2 application (not converted!) 55 //FALSE -> otherwise 56 BOOL fExitProcess = FALSE; 53 /******************************************************************************* 54 * Global Variables * 55 *******************************************************************************/ 56 BOOL fIsOS2Image = FALSE; /* TRUE -> Odin32 OS/2 application (not converted!) */ 57 /* FALSE -> otherwise */ 58 BOOL fExitProcess = FALSE; 59 60 //Commandlines 61 PCSTR pszCmdLineA; /* ASCII/ANSII commandline. */ 62 PCWSTR pszCmdLineW; /* Unicode commandline. */ 57 63 58 64 //Process database 59 PDB 60 USHORT 61 DWORD 65 PDB ProcessPDB = {0}; 66 USHORT ProcessTIBSel = 0; 67 DWORD *TIBFlatPtr = 0; 62 68 63 69 //list of thread database structures … … 78 84 PSID *pSid); 79 85 static HINSTANCE hInstNTDll = 0; 86 80 87 //****************************************************************************** 81 88 //****************************************************************************** … … 233 240 RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &thdb->threadinfo.SidUser.User.Sid); 234 241 thdb->threadinfo.SidUser.User.Attributes = 0; //????????? 235 242 236 243 thdb->threadinfo.pTokenGroups = (TOKEN_GROUPS*)malloc(sizeof(TOKEN_GROUPS)); 237 244 thdb->threadinfo.pTokenGroups->GroupCount = 1; … … 786 793 if(pModule) 787 794 { 788 795 789 796 if(pModule->isLxDll()) 790 797 { … … 1047 1054 return 0; 1048 1055 } 1049 //****************************************************************************** 1050 //****************************************************************************** 1051 LPCSTR WIN32API GetCommandLineA() 1052 { 1053 LPTSTR cmdline = NULL; 1054 1055 if(WinExe) { 1056 cmdline = WinExe->getCommandLineA(); 1057 } 1058 if(cmdline == NULL) //not used for converted exes 1059 cmdline = O32_GetCommandLine(); 1060 1061 dprintf(("KERNEL32: GetCommandLine %s\n", cmdline)); 1062 dprintf(("KERNEL32: FS = %x\n", GetFS())); 1063 return(cmdline); 1064 } 1065 //****************************************************************************** 1066 //****************************************************************************** 1056 1057 1058 /** 1059 * Internal function which gets the commandline. 1060 * @returns OS/2 / Windows return code 1061 * On successful return (NO_ERROR) the global variables 1062 * pszCmdLineA and pszCmdLineW are set. 1063 * 1064 * @param pszPeExe Pass in the name of the PE exe of this process. We'll 1065 * us this as exename and skip the first argument (ie. argv[1]). 1066 * If NULL we'll use the commandline from OS/2 as it is. 1067 * @status Completely implemented and tested. 1068 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 1069 */ 1070 ULONG InitCommandLine(const char *pszPeExe) 1071 { 1072 PCHAR pib_pchcmd; /* PIB pointer to commandline. */ 1073 CHAR szFilename[CCHMAXPATH]; /* Filename buffer used to get the exe filename in. */ 1074 ULONG cch; /* Commandline string length. (including terminator) */ 1075 PSZ psz; /* Temporary string pointer. */ 1076 PSZ psz2; /* Temporary string pointer. */ 1077 APIRET rc; /* OS/2 return code. */ 1078 BOOL fQuotes; /* Flag used to remember if the exe filename should be in quotes. */ 1079 1080 /** @sketch 1081 * Get commandline from the PIB. 1082 */ 1083 pib_pchcmd = (PCHAR)OSLibGetPIB(PIB_PCHCMD); 1084 1085 /** @sketch 1086 * Two methods of making the commandline: 1087 * (1) The first argument is skipped and the second is used as exe filname. 1088 * This applies to PE.EXE launched processes only. 1089 * (2) No skipping. First argument is the exe filename. 1090 * This applies to all but PE.EXE launched processes. 1091 * 1092 * Note: We could do some code size optimization here. Much of the code for 1093 * the two methods are nearly identical. 1094 * 1095 */ 1096 if (pszPeExe) 1097 { 1098 PSZ pszArg2; /* Pointer to into pib_pchcmd to the second argument. */ 1099 1100 /** @sketch Method (1): 1101 * First we'll have to determin the size of the commandline. 1102 * 1103 * If the commandline string don't have any arguments we'll fail. 1104 * Skip argument pointer to the second argument (ie. argv[2]). 1105 */ 1106 if (pib_pchcmd == NULL /* CPREF states that if may be NULL. */ 1107 || pib_pchcmd[cch = strlen(pib_pchcmd) + 1] == '\0' /* No arguments */ 1108 ) 1109 { 1110 dprintf(("KERNEL32: InitCommandLine(%p): No arguments!\n", pszPeExe)); 1111 return ERROR_BAD_ARGUMENTS; 1112 } 1113 1114 psz2 = pib_pchcmd + cch; /* skip exe name (PE.EXE) */ 1115 while (*psz2 == ' ') 1116 psz2++; 1117 fQuotes = *psz2 == '"'; 1118 if (fQuotes) 1119 { 1120 psz2++; 1121 psz = strchr(psz2, '"'); 1122 } 1123 else 1124 psz = strchr(psz2, ' '); 1125 if (psz != NULL) 1126 { 1127 pszArg2 = psz2 += psz - psz2 + 1; /* + 1: space or quote. */ 1128 while (*psz2 == ' ') /* skip blanks after argv[1]. */ 1129 psz2++; 1130 } 1131 else 1132 pszArg2 = psz2 += strlen(psz2) + 1; /* no arguments, skip to next string. */ 1133 1134 /** @sketch 1135 * Use passed in executable name. 1136 * Check if the exe filename needs to be put in quotes. 1137 * Determin the length of the executable name including quotes and '\0'-terminator. 1138 * Count the length of the arguments. (We here count's all argument strings.) 1139 */ 1140 #ifdef DEBUG 1141 if (pszPeExe[0] == '\0') 1142 { 1143 dprintf(("KERNEL32: InitCommandLine(%p): pszPeExe was empty string\n", pszPeExe)); 1144 return ERROR_BAD_ARGUMENTS; 1145 } 1146 #endif 1147 1148 fQuotes = strchr(pszPeExe, ' ') != NULL; 1149 cch = strlen(pszPeExe) + fQuotes*2 + 1; 1150 1151 while (*psz2 != '\0') 1152 { 1153 register int cchTmp = strlen(psz2) + 1; /* + 1 is for terminator (psz2) and space (cch). */ 1154 psz2 += cchTmp; 1155 cch += cchTmp; 1156 } 1157 1158 /** @sketch 1159 * Allocate memory for the commandline. 1160 * Build commandline: 1161 * Copy exe filename. 1162 * Add arguments. 1163 */ 1164 pszCmdLineA = psz = (PSZ)malloc(cch); 1165 if (psz == NULL) 1166 { 1167 dprintf(("KERNEL32: InitCommandLine(%p): malloc(%d) failed\n", pszPeExe, cch)); 1168 return ERROR_NOT_ENOUGH_MEMORY; 1169 } 1170 1171 if (fQuotes) 1172 *psz++ = '"'; 1173 strcpy(psz, pszPeExe); 1174 psz += strlen(psz); 1175 if (fQuotes) 1176 { 1177 *psz++ = '"'; 1178 *psz = '\0'; 1179 } 1180 1181 psz2 = pszArg2; 1182 while (*psz2 != '\0') 1183 { 1184 register int cchTmp = strlen(psz2) + 1; /* + 1 is for terminator (psz). */ 1185 *psz++ = ' '; /* add space */ 1186 memcpy(psz, psz2, cchTmp); 1187 psz2 += cchTmp; 1188 psz += cchTmp - 1; 1189 } 1190 rc = NO_ERROR; 1191 } 1192 else 1193 { 1194 /** @sketch Method (2): 1195 * First we'll have to determin the size of the commandline. 1196 * 1197 * As we don't assume that OS/2 allways puts a fully qualified EXE name 1198 * as the first string, we'll check if it's empty - and get the modulename 1199 * in that case - and allways get the fully qualified filename. 1200 */ 1201 if (pib_pchcmd == NULL || pib_pchcmd[0] == '\0') 1202 { 1203 rc = OSLibDosQueryModuleName(OSLibGetPIB(PIB_HMTE), sizeof(szFilename), szFilename); 1204 if (rc != NO_ERROR) 1205 { 1206 dprintf(("KERNEL32: InitCommandLine(%p): OSLibQueryModuleName(0x%x,...) failed with rc=%d\n", 1207 pszPeExe, OSLibGetPIB(PIB_HMTE), rc)); 1208 return rc; 1209 } 1210 } 1211 else 1212 { 1213 rc = OSLibDosQueryPathInfo(pib_pchcmd, FIL_QUERYFULLNAME, szFilename, sizeof(szFilename)); 1214 if (rc != NO_ERROR) 1215 { 1216 dprintf(("KERNEL32: InitCommandLine(%p): (info) OSLibDosQueryPathInfo failed with rc=%d\n", pszPeExe, rc)); 1217 strcpy(szFilename, pib_pchcmd); 1218 rc = NO_ERROR; 1219 } 1220 } 1221 1222 /** @sketch 1223 * We're still measuring the size of the commandline: 1224 * Check if we have to quote the exe filename. 1225 * Determin the length of the executable name including quotes and '\0'-terminator. 1226 * Count the length of the arguments. (We here count's all argument strings.) 1227 */ 1228 fQuotes = strchr(szFilename, ' ') != NULL; 1229 cch = strlen(szFilename) + fQuotes*2 + 1; 1230 if (pib_pchcmd != NULL) 1231 { 1232 psz2 = pib_pchcmd + strlen(pib_pchcmd) + 1; 1233 while (*psz2 != '\0') 1234 { 1235 register int cchTmp = strlen(psz2) + 1; /* + 1 is for terminator (psz2) and space (cch). */ 1236 psz2 += cchTmp; 1237 cch += cchTmp; 1238 } 1239 } 1240 1241 /** @sketch 1242 * Allocate memory for the commandline. 1243 * Build commandline: 1244 * Copy exe filename. 1245 * Add arguments. 1246 */ 1247 pszCmdLineA = psz = (PSZ)malloc(cch); 1248 if (psz == NULL) 1249 { 1250 dprintf(("KERNEL32: InitCommandLine(%p): malloc(%d) failed\n", pszPeExe, cch)); 1251 return ERROR_NOT_ENOUGH_MEMORY; 1252 } 1253 1254 if (fQuotes) 1255 *psz++ = '"'; 1256 strcpy(psz, szFilename); 1257 psz += strlen(psz); 1258 if (fQuotes) 1259 { 1260 *psz++ = '"'; 1261 *psz = '\0'; 1262 } 1263 1264 if (pib_pchcmd != NULL) 1265 { 1266 psz2 = pib_pchcmd + strlen(pib_pchcmd) + 1; 1267 while (*psz2 != '\0') 1268 { 1269 register int cchTmp = strlen(psz2) + 1; /* + 1 is for terminator (psz). */ 1270 *psz++ = ' '; /* add space */ 1271 memcpy(psz, psz2, cchTmp); 1272 psz2 += cchTmp; 1273 psz += cchTmp - 1; 1274 } 1275 } 1276 } 1277 1278 /** @sketch 1279 * If successfully build ASCII commandline then convert it to UniCode. 1280 */ 1281 if (rc == NO_ERROR) 1282 { 1283 pszCmdLineW = (WCHAR*)malloc(cch * 2); 1284 if (pszCmdLineW != NULL) 1285 AsciiToUnicode(pszCmdLineA, (WCHAR*)pszCmdLineW); 1286 else 1287 { 1288 dprintf(("KERNEL32: InitCommandLine(%p): malloc(%d) failed (2)\n", pszPeExe, cch)); 1289 rc = ERROR_NOT_ENOUGH_MEMORY; 1290 } 1291 } 1292 1293 return rc; 1294 } 1295 1296 /** 1297 * Gets the command line of the current process. 1298 * @returns On success: 1299 * Command line of the current process. One single string. 1300 * The first part of the command line string is the executable filename 1301 * of the current process. It might be in quotes if it contains spaces. 1302 * The rest of the string is arguments. 1303 * 1304 * On error: 1305 * NULL. Last error set. (does Win32 set last error this?) 1306 * @sketch IF not inited THEN 1307 * Init commandline assuming !PE.EXE 1308 * IF init failes THEN set last error. 1309 * ENDIF 1310 * return ASCII/ANSI commandline. 1311 * @status Completely implemented and tested. 1312 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 1313 * @remark The Ring-3 PeLdr is resposible for calling InitCommandLine before anyone 1314 * is able to call this function. 1315 */ 1316 LPCSTR WIN32API GetCommandLineA(VOID) 1317 { 1318 /* 1319 * Check if the commandline is initiated. 1320 * If not we'll have to do it. 1321 * ASSUMES that if not inited this isn't a PE.EXE lauched process. 1322 */ 1323 if (pszCmdLineA == NULL) 1324 { 1325 APIRET rc; 1326 rc = InitCommandLine(NULL); 1327 if (rc != NULL) 1328 SetLastError(rc); 1329 } 1330 1331 dprintf(("KERNEL32: GetCommandLineA: %s\n", pszCmdLineA)); 1332 return pszCmdLineA; 1333 } 1334 1335 1336 /** 1337 * Gets the command line of the current process. 1338 * @returns On success: 1339 * Command line of the current process. One single string. 1340 * The first part of the command line string is the executable filename 1341 * of the current process. It might be in quotes if it contains spaces. 1342 * The rest of the string is arguments. 1343 * 1344 * On error: 1345 * NULL. Last error set. (does Win32 set last error this?) 1346 * @sketch IF not inited THEN 1347 * Init commandline assuming !PE.EXE 1348 * IF init failes THEN set last error. 1349 * ENDIF 1350 * return Unicode commandline. 1351 * @status Completely implemented and tested. 1352 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 1353 * @remark The Ring-3 PeLdr is resposible for calling InitCommandLine before anyone 1354 * is able to call this function. 1355 */ 1067 1356 LPCWSTR WIN32API GetCommandLineW(void) 1068 1357 { 1069 static WCHAR *UnicodeCmdLine = NULL; 1070 char *asciicmdline = NULL; 1071 1072 dprintf(("KERNEL32: FS = %x\n", GetFS())); 1073 1074 if(UnicodeCmdLine) 1075 return(UnicodeCmdLine); //already called before 1076 1077 if(WinExe) { 1078 if(WinExe->getCommandLineW()) 1079 return WinExe->getCommandLineW(); 1080 } 1081 if(asciicmdline == NULL) //not used for converted exes 1082 asciicmdline = O32_GetCommandLine(); 1083 1084 if(asciicmdline) { 1085 UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2); 1086 AsciiToUnicode(asciicmdline, UnicodeCmdLine); 1087 dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline)); 1088 return(UnicodeCmdLine); 1089 } 1090 dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n")); 1091 return NULL; 1092 } 1093 //****************************************************************************** 1094 //****************************************************************************** 1358 /* 1359 * Check if the commandline is initiated. 1360 * If not we'll have to do it. 1361 * ASSUMES that if not inited this isn't a PE.EXE lauched process. 1362 */ 1363 if (pszCmdLineW == NULL) 1364 { 1365 APIRET rc; 1366 rc = InitCommandLine(NULL); 1367 if (rc != NULL) 1368 SetLastError(rc); 1369 } 1370 1371 dprintf(("KERNEL32: GetCommandLineW: %s\n", pszCmdLineA)); 1372 return pszCmdLineW; 1373 } 1374 1375 1095 1376 DWORD WIN32API GetModuleFileNameA(HMODULE hinstModule, LPTSTR lpszPath, DWORD cchPath) 1096 1377 { … … 1154 1435 else hMod = -1; 1155 1436 } 1156 else 1437 else 1157 1438 { 1158 1439 strcpy(szModule, OSLibStripPath((char *)lpszModule));
Note:
See TracChangeset
for help on using the changeset viewer.