Changeset 3819 for trunk/src/kernel32/HandleManager.cpp
- Timestamp:
- Jul 12, 2000, 8:21:45 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r3678 r3819 1 /* $Id: HandleManager.cpp,v 1.4 1 2000-06-08 18:08:54sandervl Exp $ */1 /* $Id: HandleManager.cpp,v 1.42 2000-07-12 18:21:40 sandervl Exp $ */ 2 2 3 3 /* … … 59 59 #include "HMToken.h" 60 60 #include "HMThread.h" 61 #include "HMNPipe.h" 61 62 #include <vmutex.h> 62 63 … … 133 134 HMDeviceHandler *pHMToken; /* security tokens */ 134 135 HMDeviceHandler *pHMThread; 136 HMDeviceHandler *pHMNamedPipe; 135 137 136 138 ULONG ulHandleLast; /* index of last used handle */ … … 363 365 HMGlobals.pHMToken = new HMDeviceTokenClass("\\\\TOKEN\\"); 364 366 HMGlobals.pHMThread = new HMDeviceThreadClass("\\\\THREAD\\"); 367 HMGlobals.pHMNamedPipe = new HMDeviceNamedPipeClass("\\\\PIPE\\"); 365 368 } 366 369 return (NO_ERROR); … … 3408 3411 return (lpResult); /* deliver return code */ 3409 3412 } 3413 3414 /***************************************************************************** 3415 * Name : HMPeekNamedPipe 3416 * Purpose : 3417 * Parameters: 3418 * Variables : 3419 * Result : 3420 * Remark : 3421 * Status : 3422 * 3423 * Author : Przemyslaw Dobrowolski 3424 *****************************************************************************/ 3425 BOOL HMPeekNamedPipe(HANDLE hPipe, 3426 LPVOID lpvBuffer, 3427 DWORD cbBuffer, 3428 LPDWORD lpcbRead, 3429 LPDWORD lpcbAvail, 3430 LPDWORD lpcbMessage) 3431 { 3432 int iIndex; /* index into the handle table */ 3433 BOOL lpResult; /* result from the device handler's API */ 3434 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3435 3436 SetLastError(ERROR_SUCCESS); 3437 /* validate handle */ 3438 iIndex = _HMHandleQuery(hPipe); /* get the index */ 3439 if (-1 == iIndex) /* error ? */ 3440 { 3441 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3442 return FALSE; /* signal failure */ 3443 } 3444 3445 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3446 lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 3447 lpvBuffer, 3448 cbBuffer, 3449 lpcbRead, 3450 lpcbAvail, 3451 lpcbMessage); 3452 3453 return (lpResult); /* deliver return code */ 3454 } 3455 3456 /***************************************************************************** 3457 * Name : HMCreateNamedPipe 3458 * Purpose : 3459 * Parameters: 3460 * Variables : 3461 * Result : 3462 * Remark : 3463 * Status : 3464 * 3465 * Author : Przemyslaw Dobrowolski 3466 *****************************************************************************/ 3467 DWORD HMCreateNamedPipe(LPCTSTR lpName, 3468 DWORD dwOpenMode, 3469 DWORD dwPipeMode, 3470 DWORD nMaxInstances, 3471 DWORD nOutBufferSize, 3472 DWORD nInBufferSize, 3473 DWORD nDefaultTimeOut, 3474 LPSECURITY_ATTRIBUTES lpSecurityAttributes) 3475 { 3476 int iIndex; /* index into the handle table */ 3477 int iIndexNew; /* index into the handle table */ 3478 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 3479 PHMHANDLEDATA pHMHandleData; 3480 HANDLE rc; /* API return code */ 3481 3482 SetLastError(ERROR_SUCCESS); 3483 3484 pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */ 3485 3486 iIndexNew = _HMHandleGetFree(); /* get free handle */ 3487 if (-1 == iIndexNew) /* oops, no free handles ! */ 3488 { 3489 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3490 return 0; 3491 } 3492 3493 /* initialize the complete HMHANDLEDATA structure */ 3494 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 3495 pHMHandleData->dwType = FILE_TYPE_PIPE; 3496 pHMHandleData->dwAccess = 0; 3497 pHMHandleData->dwShare = 0; 3498 pHMHandleData->dwCreation = 0; 3499 pHMHandleData->dwFlags = 0; 3500 pHMHandleData->lpHandlerData = NULL; 3501 3502 /* we've got to mark the handle as occupied here, since another device */ 3503 /* could be created within the device handler -> deadlock */ 3504 3505 /* write appropriate entry into the handle table if open succeeded */ 3506 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 3507 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 3508 3509 /* call the device handler */ 3510 3511 rc = pDeviceHandler->CreateNamedPipe(&TabWin32Handles[iIndexNew].hmHandleData, 3512 lpName,dwOpenMode, 3513 dwPipeMode,nMaxInstances, 3514 nOutBufferSize,nInBufferSize, 3515 nDefaultTimeOut,lpSecurityAttributes); 3516 3517 if (rc == 0) /* oops, creation failed within the device handler */ 3518 { 3519 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3520 return 0; /* signal error */ 3521 } 3522 3523 dprintf(("Win32 Handle -> %08x",iIndexNew)); 3524 3525 return iIndexNew; 3526 } 3527 3528 /***************************************************************************** 3529 * Name : HMConnectNamedPipe 3530 * Purpose : 3531 * Parameters: 3532 * Variables : 3533 * Result : 3534 * Remark : 3535 * Status : 3536 * 3537 * Author : Przemyslaw Dobrowolski 3538 *****************************************************************************/ 3539 BOOL HMConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED lpOverlapped) 3540 { 3541 int iIndex; /* index into the handle table */ 3542 BOOL lpResult; /* result from the device handler's API */ 3543 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3544 3545 SetLastError(ERROR_SUCCESS); 3546 /* validate handle */ 3547 iIndex = _HMHandleQuery(hPipe); /* get the index */ 3548 if (-1 == iIndex) /* error ? */ 3549 { 3550 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3551 return FALSE; /* signal failure */ 3552 } 3553 3554 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3555 lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 3556 lpOverlapped); 3557 3558 return (lpResult); /* deliver return code */ 3559 } 3560 3561 /***************************************************************************** 3562 * Name : HMDisconnectNamedPipe 3563 * Purpose : 3564 * Parameters: 3565 * Variables : 3566 * Result : 3567 * Remark : 3568 * Status : 3569 * 3570 * Author : Przemyslaw Dobrowolski 3571 *****************************************************************************/ 3572 BOOL HMDisconnectNamedPipe(HANDLE hPipe) 3573 { 3574 int iIndex; /* index into the handle table */ 3575 BOOL lpResult; /* result from the device handler's API */ 3576 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3577 3578 SetLastError(ERROR_SUCCESS); 3579 /* validate handle */ 3580 iIndex = _HMHandleQuery(hPipe); /* get the index */ 3581 if (-1 == iIndex) /* error ? */ 3582 { 3583 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3584 return FALSE; /* signal failure */ 3585 } 3586 3587 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3588 lpResult = pHMHandle->pDeviceHandler->DisconnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData); 3589 3590 return (lpResult); /* deliver return code */ 3591 } 3592 3593 /***************************************************************************** 3594 * Name : HMGetNamedPipeHandleState 3595 * Purpose : 3596 * Parameters: 3597 * Variables : 3598 * Result : 3599 * Remark : 3600 * Status : 3601 * 3602 * Author : Przemyslaw Dobrowolski 3603 *****************************************************************************/ 3604 BOOL HMGetNamedPipeHandleState(HANDLE hPipe, 3605 LPDWORD lpState, 3606 LPDWORD lpCurInstances, 3607 LPDWORD lpMaxCollectionCount, 3608 LPDWORD lpCollectDataTimeout, 3609 LPTSTR lpUserName, 3610 DWORD nMaxUserNameSize) 3611 { 3612 int iIndex; /* index into the handle table */ 3613 BOOL lpResult; /* result from the device handler's API */ 3614 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3615 3616 SetLastError(ERROR_SUCCESS); 3617 /* validate handle */ 3618 iIndex = _HMHandleQuery(hPipe); /* get the index */ 3619 if (-1 == iIndex) /* error ? */ 3620 { 3621 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3622 return FALSE; /* signal failure */ 3623 } 3624 3625 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3626 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData, 3627 lpState, 3628 lpCurInstances, 3629 lpMaxCollectionCount, 3630 lpCollectDataTimeout, 3631 lpUserName, 3632 nMaxUserNameSize); 3633 3634 3635 return (lpResult); /* deliver return code */ 3636 } 3637 3638 /***************************************************************************** 3639 * Name : HMGetNamedPipeInfo 3640 * Purpose : 3641 * Parameters: 3642 * Variables : 3643 * Result : 3644 * Remark : 3645 * Status : 3646 * 3647 * Author : Przemyslaw Dobrowolski 3648 *****************************************************************************/ 3649 BOOL HMGetNamedPipeInfo(HANDLE hPipe, 3650 LPDWORD lpFlags, 3651 LPDWORD lpOutBufferSize, 3652 LPDWORD lpInBufferSize, 3653 LPDWORD lpMaxInstances) 3654 { 3655 int iIndex; /* index into the handle table */ 3656 BOOL lpResult; /* result from the device handler's API */ 3657 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3658 3659 SetLastError(ERROR_SUCCESS); 3660 /* validate handle */ 3661 iIndex = _HMHandleQuery(hPipe); /* get the index */ 3662 if (-1 == iIndex) /* error ? */ 3663 { 3664 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3665 return FALSE; /* signal failure */ 3666 } 3667 3668 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3669 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeInfo(&TabWin32Handles[iIndex].hmHandleData, 3670 lpFlags, 3671 lpOutBufferSize, 3672 lpInBufferSize, 3673 lpMaxInstances); 3674 3675 return (lpResult); /* deliver return code */ 3676 } 3677 3678 /***************************************************************************** 3679 * Name : HMTransactNamedPipe 3680 * Purpose : 3681 * Parameters: 3682 * Variables : 3683 * Result : 3684 * Remark : 3685 * Status : 3686 * 3687 * Author : Przemyslaw Dobrowolski 3688 *****************************************************************************/ 3689 DWORD HMTransactNamedPipe(HANDLE hPipe, 3690 LPVOID lpvWriteBuf, 3691 DWORD cbWriteBuf, 3692 LPVOID lpvReadBuf, 3693 DWORD cbReadBuf, 3694 LPDWORD lpcbRead, 3695 LPOVERLAPPED lpo) 3696 { 3697 int iIndex; /* index into the handle table */ 3698 DWORD lpResult; /* result from the device handler's API */ 3699 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3700 3701 SetLastError(ERROR_SUCCESS); 3702 /* validate handle */ 3703 iIndex = _HMHandleQuery(hPipe); /* get the index */ 3704 if (-1 == iIndex) /* error ? */ 3705 { 3706 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3707 return FALSE; /* signal failure */ 3708 } 3709 3710 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3711 lpResult = pHMHandle->pDeviceHandler->TransactNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 3712 lpvWriteBuf, 3713 cbWriteBuf, 3714 lpvReadBuf, 3715 cbReadBuf, 3716 lpcbRead, 3717 lpo); 3718 3719 return (lpResult); /* deliver return code */ 3720 } 3721 3722 /***************************************************************************** 3723 * Name : HMSetNamedPipeHandleState 3724 * Purpose : 3725 * Parameters: 3726 * Variables : 3727 * Result : 3728 * Remark : 3729 * Status : 3730 * 3731 * Author : Przemyslaw Dobrowolski 3732 *****************************************************************************/ 3733 BOOL HMSetNamedPipeHandleState(HANDLE hPipe, 3734 LPDWORD lpdwMode, 3735 LPDWORD lpcbMaxCollect, 3736 LPDWORD lpdwCollectDataTimeout) 3737 { 3738 int iIndex; /* index into the handle table */ 3739 BOOL lpResult; /* result from the device handler's API */ 3740 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3741 3742 SetLastError(ERROR_SUCCESS); 3743 /* validate handle */ 3744 iIndex = _HMHandleQuery(hPipe); /* get the index */ 3745 if (-1 == iIndex) /* error ? */ 3746 { 3747 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3748 return FALSE; /* signal failure */ 3749 } 3750 3751 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3752 lpResult = pHMHandle->pDeviceHandler->SetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData, 3753 lpdwMode, 3754 lpcbMaxCollect, 3755 lpdwCollectDataTimeout); 3756 3757 return (lpResult); /* deliver return code */ 3758 } 3759 3760 /***************************************************************************** 3761 * Name : HMCreatePipe 3762 * Purpose : 3763 * Parameters: 3764 * Variables : 3765 * Result : 3766 * Remark : 3767 * Status : NOT TESTED! 3768 * 3769 * Author : Przemyslaw Dobrowolski 3770 *****************************************************************************/ 3771 BOOL HMCreatePipe(PHANDLE phRead, 3772 PHANDLE phWrite, 3773 LPSECURITY_ATTRIBUTES lpsa, 3774 DWORD cbPipe) 3775 { 3776 int iIndex; /* index into the handle table */ 3777 int iIndexNewRead; /* index into the handle table */ 3778 int iIndexNewWrite; /* index into the handle table */ 3779 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 3780 PHMHANDLEDATA pHMHandleData; 3781 HANDLE rc; /* API return code */ 3782 3783 SetLastError(ERROR_SUCCESS); 3784 3785 pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */ 3786 3787 iIndexNewRead = _HMHandleGetFree(); /* get free handle */ 3788 if (-1 == iIndexNewRead) /* oops, no free handles ! */ 3789 { 3790 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3791 return 0; 3792 } 3793 3794 iIndexNewWrite = _HMHandleGetFree(); /* get free handle */ 3795 if (-1 == iIndexNewWrite) /* oops, no free handles ! */ 3796 { 3797 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3798 return 0; 3799 } 3800 3801 3802 /* initialize the complete HMHANDLEDATA structure */ 3803 pHMHandleData = &TabWin32Handles[iIndexNewRead].hmHandleData; 3804 pHMHandleData->dwType = FILE_TYPE_PIPE; 3805 pHMHandleData->dwAccess = 0; 3806 pHMHandleData->dwShare = 0; 3807 pHMHandleData->dwCreation = 0; 3808 pHMHandleData->dwFlags = 0; 3809 pHMHandleData->lpHandlerData = NULL; 3810 3811 /* we've got to mark the handle as occupied here, since another device */ 3812 /* could be created within the device handler -> deadlock */ 3813 3814 /* write appropriate entry into the handle table if open succeeded */ 3815 TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = iIndexNewRead; 3816 TabWin32Handles[iIndexNewRead].pDeviceHandler = pDeviceHandler; 3817 3818 /* initialize the complete HMHANDLEDATA structure */ 3819 pHMHandleData = &TabWin32Handles[iIndexNewWrite].hmHandleData; 3820 pHMHandleData->dwType = FILE_TYPE_PIPE; 3821 pHMHandleData->dwAccess = 0; 3822 pHMHandleData->dwShare = 0; 3823 pHMHandleData->dwCreation = 0; 3824 pHMHandleData->dwFlags = 0; 3825 pHMHandleData->lpHandlerData = NULL; 3826 3827 /* we've got to mark the handle as occupied here, since another device */ 3828 /* could be created within the device handler -> deadlock */ 3829 3830 /* write appropriate entry into the handle table if open succeeded */ 3831 TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = iIndexNewWrite; 3832 TabWin32Handles[iIndexNewWrite].pDeviceHandler = pDeviceHandler; 3833 /* call the device handler */ 3834 3835 rc = pDeviceHandler->CreatePipe(&TabWin32Handles[iIndexNewRead].hmHandleData, 3836 &TabWin32Handles[iIndexNewWrite].hmHandleData, 3837 lpsa, 3838 cbPipe); 3839 3840 if (rc == 0) /* oops, creation failed within the device handler */ 3841 { 3842 TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3843 TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3844 return FALSE; /* signal error */ 3845 } 3846 3847 *phRead = iIndexNewRead; 3848 *phWrite = iIndexNewWrite; 3849 3850 return TRUE; 3851 }
Note:
See TracChangeset
for help on using the changeset viewer.