儲存庫 kBuild 的更動 2307
- 時間撮記:
- 2009-3-1 上午09:48:04 (16 年 以前)
- 位置:
- trunk/src/kash
- 檔案:
-
- 修改 2 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/kash/shfile.c
r2303 r2307 84 84 # define FDEV 0x40 85 85 # define FTEXT 0x80 86 #endif 86 87 # define MY_ObjectBasicInformation 0 88 typedef LONG (NTAPI * PFN_NtQueryObject)(HANDLE, int, void *, size_t, size_t *); 89 90 typedef struct MY_OBJECT_BASIC_INFORMATION 91 { 92 ULONG Attributes; 93 ACCESS_MASK GrantedAccess; 94 ULONG HandleCount; 95 ULONG PointerCount; 96 ULONG PagedPoolUsage; 97 ULONG NonPagedPoolUsage; 98 ULONG Reserved[3]; 99 ULONG NameInformationLength; 100 ULONG TypeInformationLength; 101 ULONG SecurityDescriptorLength; 102 LARGE_INTEGER CreateTime; 103 } MY_OBJECT_BASIC_INFORMATION; 104 105 #endif /* K_OS_WINDOWS */ 87 106 88 107 … … 117 136 * @param pfdtab The file descriptor table. 118 137 * @param native The native file handle. 119 * @param flags The flags the it was created with. 138 * @param oflags The flags the it was opened/created with. 139 * @param shflags The shell file flags. 120 140 * @param fdMin The minimum file descriptor number, pass -1 if any is ok. 121 141 * @param who Who we're doing this for (for logging purposes). 122 142 */ 123 static int shfile_insert(shfdtab *pfdtab, intptr_t native, unsigned flags, int fdMin, const char *who)143 static int shfile_insert(shfdtab *pfdtab, intptr_t native, unsigned oflags, unsigned shflags, int fdMin, const char *who) 124 144 { 125 145 shmtxtmp tmp; … … 164 184 { 165 185 new_tab[i].fd = -1; 166 new_tab[i].flags = 0; 186 new_tab[i].oflags = 0; 187 new_tab[i].shflags = 0; 167 188 new_tab[i].native = -1; 168 189 } … … 183 204 { 184 205 pfdtab->tab[fd].fd = fd; 185 pfdtab->tab[fd]. flags =flags;186 pfdtab->tab[fd]. cloexec = 0;206 pfdtab->tab[fd].oflags = oflags; 207 pfdtab->tab[fd].shflags = shflags; 187 208 pfdtab->tab[fd].native = native; 188 209 } 189 210 else 190 shfile_native_close(native, flags);211 shfile_native_close(native, oflags); 191 212 192 213 shmtx_leave(&pfdtab->mtx, &tmp); … … 305 326 306 327 # if K_OS == K_OS_WINDOWS 328 307 329 /** 308 330 * Converts a DOS(/Windows) error code to errno, … … 364 386 return -1; 365 387 } 388 389 DWORD shfile_query_handle_access_mask(HANDLE h, PACCESS_MASK pMask) 390 { 391 static PFN_NtQueryObject s_pfnNtQueryObject = NULL; 392 MY_OBJECT_BASIC_INFORMATION BasicInfo; 393 LONG Status; 394 395 if (!s_pfnNtQueryObject) 396 { 397 s_pfnNtQueryObject = (PFN_NtQueryObject)GetProcAddress(GetModuleHandle("NTDLL"), "NtQueryObject"); 398 if (!s_pfnNtQueryObject) 399 return ERROR_NOT_SUPPORTED; 400 } 401 402 Status = s_pfnNtQueryObject(h, MY_ObjectBasicInformation, &BasicInfo, sizeof(BasicInfo), NULL); 403 if (Status >= 0) 404 { 405 *pMask = BasicInfo.GrantedAccess; 406 return NO_ERROR; 407 } 408 if (Status != STATUS_INVALID_HANDLE) 409 return ERROR_GEN_FAILURE; 410 return ERROR_INVALID_HANDLE; 411 } 412 366 413 # endif /* K_OS == K_OS_WINDOWS */ 367 414 … … 397 444 { 398 445 DWORD dwStdHandle; 399 unsigned f lags;446 unsigned fFlags; 400 447 } aStdHandles[3] = 401 448 { … … 404 451 { STD_ERROR_HANDLE, _O_WRONLY } 405 452 }; 406 unsigned i; 407 STARTUPINFO Info; 453 int i; 454 STARTUPINFO Info; 455 ACCESS_MASK Mask; 456 DWORD dwErr; 408 457 409 458 rc = 0; … … 415 464 memset(&Info, 0, sizeof(Info)); 416 465 } 417 if ( Info.cbReserved2 <= sizeof(int) 466 467 if ( Info.cbReserved2 > sizeof(int) 418 468 && (uintptr_t)Info.lpReserved2 >= 0x1000 419 && *(int *)Info.lpReserved2 * (sizeof(int) + sizeof(intptr_t)) + 4 <= Info.cbReserved2 420 && *(int *)Info.lpReserved2 <= 2048 421 && *(int *)Info.lpReserved2 >= 1) 469 && (i = *(int *)Info.lpReserved2) >= 1 470 && i <= 2048 471 && ( Info.cbReserved2 == i * 5 + 4 472 //|| Info.cbReserved2 == i * 5 + 1 - check the cygwin sources. 473 || Info.cbReserved2 == i * 9 + 4)) 422 474 { 423 unsigned c = *(int *)Info.lpReserved2; 424 char *aosfile = (char *)Info.lpReserved2 + sizeof(int); 425 intptr_t *aosfhnd = (intptr_t *)(aosfile + c); 426 427 /** @todo process */ 428 475 uint8_t *paf = (uint8_t *)Info.lpReserved2 + sizeof(int); 476 int dwPerH = 1 + (Info.cbReserved2 == i * 9 + 4); 477 DWORD *ph = (DWORD *)(paf + i) + dwPerH * i; 478 HANDLE aStdHandles2[3]; 479 int j; 480 481 //if (Info.cbReserved2 == i * 5 + 1) - check the cygwin sources. 482 // i--; 483 484 for (j = 0; j < 3; j++) 485 aStdHandles2[j] = GetStdHandle(aStdHandles[j].dwStdHandle); 486 487 while (i-- > 0) 488 { 489 ph -= dwPerH; 490 491 if ( (paf[i] & (FOPEN | FNOINHERIT)) == FOPEN 492 && *ph != (uint32_t)INVALID_HANDLE_VALUE) 493 { 494 HANDLE h = (HANDLE)(intptr_t)*ph; 495 int fd2; 496 int fFlags; 497 int fFlags2; 498 499 if ( h == aStdHandles2[j = 0] 500 || h == aStdHandles2[j = 1] 501 || h == aStdHandles2[j = 2]) 502 fFlags = aStdHandles[j].fFlags; 503 else 504 { 505 dwErr = shfile_query_handle_access_mask(h, &Mask); 506 if (dwErr == ERROR_INVALID_HANDLE) 507 continue; 508 else if (dwErr == NO_ERROR) 509 { 510 fFlags = 0; 511 if ( (Mask & (GENERIC_READ | FILE_READ_DATA)) 512 && (Mask & (GENERIC_WRITE | FILE_WRITE_DATA | FILE_APPEND_DATA))) 513 fFlags |= O_RDWR; 514 else if (Mask & (GENERIC_READ | FILE_READ_DATA)) 515 fFlags |= O_RDONLY; 516 else if (Mask & (GENERIC_WRITE | FILE_WRITE_DATA | FILE_APPEND_DATA)) 517 fFlags |= O_WRONLY; 518 else 519 fFlags |= O_RDWR; 520 if ((Mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) == FILE_APPEND_DATA) 521 fFlags |= O_APPEND; 522 } 523 else 524 fFlags = O_RDWR; 525 } 526 527 if (paf[i] & FPIPE) 528 fFlags2 = SHFILE_FLAGS_PIPE; 529 else if (paf[i] & FDEV) 530 fFlags2 = SHFILE_FLAGS_TTY; 531 else 532 fFlags2 = 0; 533 534 fd2 = shfile_insert(pfdtab, (intptr_t)h, fFlags, fFlags2, i, "shtab_init"); 535 assert(fd2 == i); (void)fd2; 536 if (fd2 != i) 537 rc = -1; 538 } 539 } 429 540 } 430 541 431 542 /* Check the three standard handles. */ 432 543 for (i = 0; i < 3; i++) 433 { 434 HANDLE hFile = GetStdHandle(aStdHandles[i].dwStdHandle); 435 if ( hFile != INVALID_HANDLE_VALUE 436 && ( (unsigned)i >= pfdtab->size 437 || pfdtab->tab[i].fd == -1)) 544 if ( (unsigned)i >= pfdtab->size 545 || pfdtab->tab[i].fd == -1) 438 546 { 439 int fd2 = shfile_insert(pfdtab, (intptr_t)hFile, aStdHandles[i].flags, i, "shtab_init"); 440 assert(fd2 == i); (void)fd2; 441 if (fd2 != i) 442 rc = -1; 547 HANDLE hFile = GetStdHandle(aStdHandles[i].dwStdHandle); 548 if (hFile != INVALID_HANDLE_VALUE) 549 { 550 int fd2 = shfile_insert(pfdtab, (intptr_t)hFile, aStdHandles[i].fFlags, 0, i, "shtab_init"); 551 assert(fd2 == i); (void)fd2; 552 if (fd2 != i) 553 rc = -1; 554 } 443 555 } 444 }445 556 # else 446 557 # endif … … 486 597 HANDLE hFile = (HANDLE)pfdtab->tab[i].native; 487 598 if (set) 488 TRACE2((NULL, " #%d: native=%#x flags=%#x cloexec=%d\n",489 i, pfdtab->tab[i]. flags, hFile, pfdtab->tab[i].cloexec));599 TRACE2((NULL, " #%d: native=%#x oflags=%#x shflags=%#x\n", 600 i, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags, hFile)); 490 601 if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, fFlag)) 491 602 { … … 538 649 ? pfdtab->size 539 650 : (0x10000-4) / (1 + sizeof(HANDLE)); 651 while (count > 3 && pfdtab->tab[count].fd == -1) 652 count--; 540 653 541 654 if (prepare) … … 552 665 { 553 666 if ( pfdtab->tab[i].fd == i 554 && ! pfdtab->tab[i].cloexec)667 && !(pfdtab->tab[i].shflags & SHFILE_FLAGS_CLOSE_ON_EXEC)) 555 668 { 556 669 HANDLE hFile = (HANDLE)pfdtab->tab[i].native; 557 TRACE2((NULL, " #%d: native=%#x flags=%#x\n",558 i, pfdtab->tab[i]. flags, hFile));670 TRACE2((NULL, " #%d: native=%#x oflags=%#x shflags=%#x\n", 671 i, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags, hFile)); 559 672 560 673 if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) … … 564 677 } 565 678 paf[i] = FOPEN; 566 if (pfdtab->tab[i].flags & _O_APPEND) 567 paf[i] = FAPPEND; 568 if (pfdtab->tab[i].flags & _O_TEXT) 569 paf[i] = FTEXT; 679 if (pfdtab->tab[i].oflags & _O_APPEND) 680 paf[i] |= FAPPEND; 681 if (pfdtab->tab[i].oflags & _O_TEXT) 682 paf[i] |= FTEXT; 683 switch (pfdtab->tab[i].shflags & SHFILE_FLAGS_TYPE_MASK) 684 { 685 case SHFILE_FLAGS_TTY: paf[i] |= FDEV; break; 686 case SHFILE_FLAGS_PIPE: paf[i] |= FPIPE; break; 687 } 570 688 pah[i] = hFile; 571 689 } … … 597 715 { 598 716 if ( pfdtab->tab[i].fd == i 599 && ! pfdtab->tab[i].cloexec)717 && !(pfdtab->tab[i].shflags & SHFILE_FLAGS_CLOSE_ON_EXEC)) 600 718 { 601 719 HANDLE hFile = (HANDLE)pfdtab->tab[i].native; … … 689 807 NULL /* hTemplateFile */); 690 808 if (hFile != INVALID_HANDLE_VALUE) 691 fd = shfile_insert(pfdtab, (intptr_t)hFile, flags, -1, "shfile_open");809 fd = shfile_insert(pfdtab, (intptr_t)hFile, flags, 0, -1, "shfile_open"); 692 810 else 693 811 fd = shfile_dos2errno(GetLastError()); … … 706 824 errno = s; 707 825 if (native != -1) 708 fd = shfile_insert(pfdtab, native, flags, -1, "shfile_open");826 fd = shfile_insert(pfdtab, native, flags, 0, -1, "shfile_open"); 709 827 else 710 828 fd = -1; … … 739 857 if (CreatePipe(&hRead, &hWrite, &SecurityAttributes, 4096)) 740 858 { 741 fds[0] = shfile_insert(pfdtab, (intptr_t)hRead, O_RDONLY, -1, "shfile_pipe");859 fds[0] = shfile_insert(pfdtab, (intptr_t)hRead, O_RDONLY, SHFILE_FLAGS_PIPE, -1, "shfile_pipe"); 742 860 if (fds[0] != -1) 743 861 { 744 fds[1] = shfile_insert(pfdtab, (intptr_t)hWrite, O_WRONLY, -1, "shfile_pipe");862 fds[1] = shfile_insert(pfdtab, (intptr_t)hWrite, O_WRONLY, SHFILE_FLAGS_PIPE, -1, "shfile_pipe"); 745 863 if (fds[1] != -1) 746 864 rc = 0; … … 753 871 if (!pipe(native_fds)) 754 872 { 755 fds[0] = shfile_insert(pfdtab, native_fds[0], O_RDONLY, -1, "shfile_pipe");873 fds[0] = shfile_insert(pfdtab, native_fds[0], O_RDONLY, SHFILE_FLAGS_PIPE, -1, "shfile_pipe"); 756 874 if (fds[0] != -1) 757 875 { 758 fds[1] = shfile_insert(pfdtab, native_fds[1], O_WRONLY, -1, "shfile_pipe");876 fds[1] = shfile_insert(pfdtab, native_fds[1], O_WRONLY, SHFILE_FLAGS_PIPE, -1, "shfile_pipe"); 759 877 if (fds[1] != -1) 760 878 rc = 0; … … 770 888 rc = fds[0]; 771 889 pfdtab->tab[rc].fd = -1; 772 pfdtab->tab[rc].flags = 0; 890 pfdtab->tab[rc].oflags = 0; 891 pfdtab->tab[rc].shflags = 0; 773 892 pfdtab->tab[rc].native = -1; 774 893 shmtx_leave(&pfdtab->mtx, &tmp); … … 822 941 if (file) 823 942 { 824 shfile_native_close(file->native, file-> flags);943 shfile_native_close(file->native, file->oflags); 825 944 826 945 file->fd = -1; 827 file->flags = 0; 946 file->oflags = 0; 947 file->shflags = 0; 828 948 file->native = -1; 829 949 … … 951 1071 { 952 1072 case F_GETFL: 953 rc = file-> flags;1073 rc = file->oflags; 954 1074 break; 955 1075 … … 966 1086 mask |= O_SYNC; 967 1087 # endif 968 if ((file-> flags & mask) == (arg & mask))1088 if ((file->oflags & mask) == (arg & mask)) 969 1089 rc = 0; 970 1090 else … … 994 1114 FALSE /* bInheritHandle */, 995 1115 DUPLICATE_SAME_ACCESS)) 996 rc = shfile_insert(pfdtab, (intptr_t)hNew, file-> flags, arg, "shfile_fcntl");1116 rc = shfile_insert(pfdtab, (intptr_t)hNew, file->oflags, file->shflags, arg, "shfile_fcntl"); 997 1117 else 998 1118 rc = shfile_dos2errno(GetLastError()); … … 1000 1120 int nativeNew = fcntl(file->native F_DUPFD, SHFILE_UNIX_MIN_FD); 1001 1121 if (nativeNew != -1) 1002 rc = shfile_insert(pfdtab, nativeNew, file-> flags, arg, "shfile_fcntl");1122 rc = shfile_insert(pfdtab, nativeNew, file->oflags, file->shflags, arg, "shfile_fcntl"); 1003 1123 # endif 1004 1124 break; … … 1204 1324 if (file) 1205 1325 { 1206 file->cloexec = !!(closeit); 1326 if (closeit) 1327 file->shflags |= SHFILE_FLAGS_CLOSE_ON_EXEC; 1328 else 1329 file->shflags &= ~SHFILE_FLAGS_CLOSE_ON_EXEC; 1207 1330 shfile_put(pfdtab, file, &tmp); 1208 1331 } -
trunk/src/kash/shfile.h
r2303 r2307 102 102 { 103 103 int fd; /**< The shell file descriptor number. */ 104 int flags;/**< Open flags. */105 unsigned cloexec : 1; /**< Close on exec flag. */104 unsigned oflags; /**< Open flags. */ 105 unsigned shflags; /**< The shell file descriptor flags. */ 106 106 intptr_t native; /**< The native file descriptor number. */ 107 107 } shfile; 108 109 /** @name shfile::shflags values. 110 * @{ 111 */ 112 #define SHFILE_FLAGS_CLOSE_ON_EXEC 0x0001 113 #define SHFILE_FLAGS_TYPE_MASK 0x00f0 114 #define SHFILE_FLAGS_FILE 0x0000 115 #define SHFILE_FLAGS_PIPE 0x0010 116 #define SHFILE_FLAGS_DIR 0x0020 117 #define SHFILE_FLAGS_TTY 0x0030 118 /** @} */ 108 119 109 120 /**
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器