/src/FreeRDP/winpr/libwinpr/handle/handle.h
Line | Count | Source |
1 | | /** |
2 | | * WinPR: Windows Portable Runtime |
3 | | * Handle Management |
4 | | * |
5 | | * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #ifndef WINPR_HANDLE_PRIVATE_H |
21 | | #define WINPR_HANDLE_PRIVATE_H |
22 | | |
23 | | #include <stdlib.h> |
24 | | |
25 | | #include <winpr/handle.h> |
26 | | #include <winpr/file.h> |
27 | | #include <winpr/interlocked.h> |
28 | | #include <winpr/synch.h> |
29 | | #include <winpr/winsock.h> |
30 | | |
31 | 0 | #define HANDLE_TYPE_NONE 0 |
32 | 71.8k | #define HANDLE_TYPE_PROCESS 1 |
33 | 286k | #define HANDLE_TYPE_THREAD 2 |
34 | 483k | #define HANDLE_TYPE_EVENT 3 |
35 | 35.9k | #define HANDLE_TYPE_MUTEX 4 |
36 | | #define HANDLE_TYPE_SEMAPHORE 5 |
37 | | #define HANDLE_TYPE_TIMER 6 |
38 | 0 | #define HANDLE_TYPE_NAMED_PIPE 7 |
39 | 0 | #define HANDLE_TYPE_ANONYMOUS_PIPE 8 |
40 | 0 | #define HANDLE_TYPE_ACCESS_TOKEN 9 |
41 | 0 | #define HANDLE_TYPE_FILE 10 |
42 | | #define HANDLE_TYPE_TIMER_QUEUE 11 |
43 | | #define HANDLE_TYPE_TIMER_QUEUE_TIMER 12 |
44 | 0 | #define HANDLE_TYPE_COMM 13 |
45 | | |
46 | | typedef BOOL (*pcIsHandled)(HANDLE handle); |
47 | | typedef BOOL (*pcCloseHandle)(HANDLE handle); |
48 | | typedef int (*pcGetFd)(HANDLE handle); |
49 | | typedef DWORD (*pcCleanupHandle)(HANDLE handle); |
50 | | typedef BOOL (*pcReadFile)(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, |
51 | | LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); |
52 | | typedef BOOL (*pcReadFileEx)(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, |
53 | | LPOVERLAPPED lpOverlapped, |
54 | | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); |
55 | | typedef BOOL (*pcReadFileScatter)(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[], |
56 | | DWORD nNumberOfBytesToRead, LPDWORD lpReserved, |
57 | | LPOVERLAPPED lpOverlapped); |
58 | | typedef BOOL (*pcWriteFile)(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, |
59 | | LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped); |
60 | | typedef BOOL (*pcWriteFileEx)(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, |
61 | | LPOVERLAPPED lpOverlapped, |
62 | | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); |
63 | | typedef BOOL (*pcWriteFileGather)(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[], |
64 | | DWORD nNumberOfBytesToWrite, LPDWORD lpReserved, |
65 | | LPOVERLAPPED lpOverlapped); |
66 | | typedef DWORD (*pcGetFileSize)(HANDLE handle, LPDWORD lpFileSizeHigh); |
67 | | typedef BOOL (*pcGetFileInformationByHandle)(HANDLE handle, |
68 | | LPBY_HANDLE_FILE_INFORMATION lpFileInformation); |
69 | | typedef BOOL (*pcFlushFileBuffers)(HANDLE hFile); |
70 | | typedef BOOL (*pcSetEndOfFile)(HANDLE handle); |
71 | | typedef DWORD (*pcSetFilePointer)(HANDLE handle, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, |
72 | | DWORD dwMoveMethod); |
73 | | typedef BOOL (*pcSetFilePointerEx)(HANDLE hFile, LARGE_INTEGER liDistanceToMove, |
74 | | PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod); |
75 | | typedef BOOL (*pcLockFile)(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, |
76 | | DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh); |
77 | | typedef BOOL (*pcLockFileEx)(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, |
78 | | DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, |
79 | | LPOVERLAPPED lpOverlapped); |
80 | | typedef BOOL (*pcUnlockFile)(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, |
81 | | DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh); |
82 | | typedef BOOL (*pcUnlockFileEx)(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, |
83 | | DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped); |
84 | | typedef BOOL (*pcSetFileTime)(HANDLE hFile, const FILETIME* lpCreationTime, |
85 | | const FILETIME* lpLastAccessTime, const FILETIME* lpLastWriteTime); |
86 | | |
87 | | typedef struct |
88 | | { |
89 | | pcIsHandled IsHandled; |
90 | | pcCloseHandle CloseHandle; |
91 | | pcGetFd GetFd; |
92 | | pcCleanupHandle CleanupHandle; |
93 | | pcReadFile ReadFile; |
94 | | pcReadFileEx ReadFileEx; |
95 | | pcReadFileScatter ReadFileScatter; |
96 | | pcWriteFile WriteFile; |
97 | | pcWriteFileEx WriteFileEx; |
98 | | pcWriteFileGather WriteFileGather; |
99 | | pcGetFileSize GetFileSize; |
100 | | pcFlushFileBuffers FlushFileBuffers; |
101 | | pcSetEndOfFile SetEndOfFile; |
102 | | pcSetFilePointer SetFilePointer; |
103 | | pcSetFilePointerEx SetFilePointerEx; |
104 | | pcLockFile LockFile; |
105 | | pcLockFileEx LockFileEx; |
106 | | pcUnlockFile UnlockFile; |
107 | | pcUnlockFileEx UnlockFileEx; |
108 | | pcSetFileTime SetFileTime; |
109 | | pcGetFileInformationByHandle GetFileInformationByHandle; |
110 | | } HANDLE_OPS; |
111 | | |
112 | | typedef struct |
113 | | { |
114 | | ULONG Type; |
115 | | ULONG Mode; |
116 | | HANDLE_OPS* ops; |
117 | | volatile LONG refCount; |
118 | | } WINPR_HANDLE; |
119 | | |
120 | | WINPR_ATTR_NODISCARD |
121 | | static inline BOOL WINPR_HANDLE_IS_HANDLED(HANDLE handle, ULONG type, BOOL invalidValue) |
122 | 286k | { |
123 | 286k | WINPR_HANDLE* pWinprHandle = (WINPR_HANDLE*)handle; |
124 | 286k | BOOL invalid = !pWinprHandle; |
125 | | |
126 | 286k | if (invalidValue) |
127 | 0 | { |
128 | 0 | if (INVALID_HANDLE_VALUE == pWinprHandle) |
129 | 0 | invalid = TRUE; |
130 | 0 | } |
131 | | |
132 | 286k | if (invalid || (pWinprHandle->Type != type)) |
133 | 0 | { |
134 | 0 | SetLastError(ERROR_INVALID_HANDLE); |
135 | 0 | return FALSE; |
136 | 0 | } |
137 | | |
138 | 286k | return TRUE; |
139 | 286k | } Unexecuted instantiation: process.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: critical.c:WINPR_HANDLE_IS_HANDLED event.c:WINPR_HANDLE_IS_HANDLED Line | Count | Source | 122 | 215k | { | 123 | 215k | WINPR_HANDLE* pWinprHandle = (WINPR_HANDLE*)handle; | 124 | 215k | BOOL invalid = !pWinprHandle; | 125 | | | 126 | 215k | if (invalidValue) | 127 | 0 | { | 128 | 0 | if (INVALID_HANDLE_VALUE == pWinprHandle) | 129 | 0 | invalid = TRUE; | 130 | 0 | } | 131 | | | 132 | 215k | if (invalid || (pWinprHandle->Type != type)) | 133 | 0 | { | 134 | 0 | SetLastError(ERROR_INVALID_HANDLE); | 135 | 0 | return FALSE; | 136 | 0 | } | 137 | | | 138 | 215k | return TRUE; | 139 | 215k | } |
Unexecuted instantiation: sleep.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: wait.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: generic.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: namedPipeClient.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: file.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: comm.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: comm_ioctl.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: comm_serial_sys.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: comm_sercx_sys.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: comm_sercx2_sys.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: pipe.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: shell.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: handle.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: nonehandle.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: apc.c:WINPR_HANDLE_IS_HANDLED thread.c:WINPR_HANDLE_IS_HANDLED Line | Count | Source | 122 | 71.6k | { | 123 | 71.6k | WINPR_HANDLE* pWinprHandle = (WINPR_HANDLE*)handle; | 124 | 71.6k | BOOL invalid = !pWinprHandle; | 125 | | | 126 | 71.6k | if (invalidValue) | 127 | 0 | { | 128 | 0 | if (INVALID_HANDLE_VALUE == pWinprHandle) | 129 | 0 | invalid = TRUE; | 130 | 0 | } | 131 | | | 132 | 71.6k | if (invalid || (pWinprHandle->Type != type)) | 133 | 0 | { | 134 | 0 | SetLastError(ERROR_INVALID_HANDLE); | 135 | 0 | return FALSE; | 136 | 0 | } | 137 | | | 138 | 71.6k | return TRUE; | 139 | 71.6k | } |
Unexecuted instantiation: nt.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: comm_io.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: io.c:WINPR_HANDLE_IS_HANDLED Unexecuted instantiation: sspicli.c:WINPR_HANDLE_IS_HANDLED |
140 | | |
141 | | static inline void WINPR_HANDLE_SET_TYPE_AND_MODE(void* _handle, ULONG _type, ULONG _mode) |
142 | 197k | { |
143 | 197k | WINPR_HANDLE* hdl = (WINPR_HANDLE*)_handle; |
144 | | |
145 | 197k | hdl->Type = _type; |
146 | 197k | hdl->Mode = _mode; |
147 | 197k | hdl->refCount = 1; |
148 | 197k | } Unexecuted instantiation: process.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: critical.c:WINPR_HANDLE_SET_TYPE_AND_MODE event.c:WINPR_HANDLE_SET_TYPE_AND_MODE Line | Count | Source | 142 | 179k | { | 143 | 179k | WINPR_HANDLE* hdl = (WINPR_HANDLE*)_handle; | 144 | | | 145 | 179k | hdl->Type = _type; | 146 | 179k | hdl->Mode = _mode; | 147 | 179k | hdl->refCount = 1; | 148 | 179k | } |
Unexecuted instantiation: sleep.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: wait.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: generic.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: namedPipeClient.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: file.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: comm.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: comm_ioctl.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: comm_serial_sys.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: comm_sercx_sys.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: comm_sercx2_sys.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: pipe.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: shell.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: handle.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: nonehandle.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: apc.c:WINPR_HANDLE_SET_TYPE_AND_MODE thread.c:WINPR_HANDLE_SET_TYPE_AND_MODE Line | Count | Source | 142 | 17.9k | { | 143 | 17.9k | WINPR_HANDLE* hdl = (WINPR_HANDLE*)_handle; | 144 | | | 145 | 17.9k | hdl->Type = _type; | 146 | 17.9k | hdl->Mode = _mode; | 147 | 17.9k | hdl->refCount = 1; | 148 | 17.9k | } |
Unexecuted instantiation: nt.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: comm_io.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: io.c:WINPR_HANDLE_SET_TYPE_AND_MODE Unexecuted instantiation: sspicli.c:WINPR_HANDLE_SET_TYPE_AND_MODE |
149 | | |
150 | | WINPR_ATTR_NODISCARD |
151 | | static inline BOOL winpr_Handle_GetInfo(HANDLE handle, ULONG* pType, WINPR_HANDLE** pObject) |
152 | 663k | { |
153 | 663k | WINPR_HANDLE* wHandle = nullptr; |
154 | | |
155 | 663k | if (handle == nullptr) |
156 | 0 | return FALSE; |
157 | | |
158 | | /* INVALID_HANDLE_VALUE is an invalid value for every handle, but it |
159 | | * confuses the clang scanbuild analyzer. */ |
160 | 663k | #ifndef __clang_analyzer__ |
161 | 663k | if (handle == INVALID_HANDLE_VALUE) |
162 | 0 | return FALSE; |
163 | 663k | #endif |
164 | | |
165 | 663k | wHandle = (WINPR_HANDLE*)handle; |
166 | | |
167 | 663k | *pType = wHandle->Type; |
168 | 663k | *pObject = wHandle; |
169 | | |
170 | 663k | return TRUE; |
171 | 663k | } Unexecuted instantiation: process.c:winpr_Handle_GetInfo Unexecuted instantiation: critical.c:winpr_Handle_GetInfo event.c:winpr_Handle_GetInfo Line | Count | Source | 152 | 89.6k | { | 153 | 89.6k | WINPR_HANDLE* wHandle = nullptr; | 154 | | | 155 | 89.6k | if (handle == nullptr) | 156 | 0 | return FALSE; | 157 | | | 158 | | /* INVALID_HANDLE_VALUE is an invalid value for every handle, but it | 159 | | * confuses the clang scanbuild analyzer. */ | 160 | 89.6k | #ifndef __clang_analyzer__ | 161 | 89.6k | if (handle == INVALID_HANDLE_VALUE) | 162 | 0 | return FALSE; | 163 | 89.6k | #endif | 164 | | | 165 | 89.6k | wHandle = (WINPR_HANDLE*)handle; | 166 | | | 167 | 89.6k | *pType = wHandle->Type; | 168 | 89.6k | *pObject = wHandle; | 169 | | | 170 | 89.6k | return TRUE; | 171 | 89.6k | } |
Unexecuted instantiation: sleep.c:winpr_Handle_GetInfo wait.c:winpr_Handle_GetInfo Line | Count | Source | 152 | 197k | { | 153 | 197k | WINPR_HANDLE* wHandle = nullptr; | 154 | | | 155 | 197k | if (handle == nullptr) | 156 | 0 | return FALSE; | 157 | | | 158 | | /* INVALID_HANDLE_VALUE is an invalid value for every handle, but it | 159 | | * confuses the clang scanbuild analyzer. */ | 160 | 197k | #ifndef __clang_analyzer__ | 161 | 197k | if (handle == INVALID_HANDLE_VALUE) | 162 | 0 | return FALSE; | 163 | 197k | #endif | 164 | | | 165 | 197k | wHandle = (WINPR_HANDLE*)handle; | 166 | | | 167 | 197k | *pType = wHandle->Type; | 168 | 197k | *pObject = wHandle; | 169 | | | 170 | 197k | return TRUE; | 171 | 197k | } |
Unexecuted instantiation: generic.c:winpr_Handle_GetInfo Unexecuted instantiation: namedPipeClient.c:winpr_Handle_GetInfo Unexecuted instantiation: file.c:winpr_Handle_GetInfo Unexecuted instantiation: comm.c:winpr_Handle_GetInfo Unexecuted instantiation: comm_ioctl.c:winpr_Handle_GetInfo Unexecuted instantiation: comm_serial_sys.c:winpr_Handle_GetInfo Unexecuted instantiation: comm_sercx_sys.c:winpr_Handle_GetInfo Unexecuted instantiation: comm_sercx2_sys.c:winpr_Handle_GetInfo Unexecuted instantiation: pipe.c:winpr_Handle_GetInfo Unexecuted instantiation: shell.c:winpr_Handle_GetInfo handle.c:winpr_Handle_GetInfo Line | Count | Source | 152 | 376k | { | 153 | 376k | WINPR_HANDLE* wHandle = nullptr; | 154 | | | 155 | 376k | if (handle == nullptr) | 156 | 0 | return FALSE; | 157 | | | 158 | | /* INVALID_HANDLE_VALUE is an invalid value for every handle, but it | 159 | | * confuses the clang scanbuild analyzer. */ | 160 | 376k | #ifndef __clang_analyzer__ | 161 | 376k | if (handle == INVALID_HANDLE_VALUE) | 162 | 0 | return FALSE; | 163 | 376k | #endif | 164 | | | 165 | 376k | wHandle = (WINPR_HANDLE*)handle; | 166 | | | 167 | 376k | *pType = wHandle->Type; | 168 | 376k | *pObject = wHandle; | 169 | | | 170 | 376k | return TRUE; | 171 | 376k | } |
Unexecuted instantiation: nonehandle.c:winpr_Handle_GetInfo Unexecuted instantiation: apc.c:winpr_Handle_GetInfo Unexecuted instantiation: thread.c:winpr_Handle_GetInfo Unexecuted instantiation: nt.c:winpr_Handle_GetInfo Unexecuted instantiation: comm_io.c:winpr_Handle_GetInfo Unexecuted instantiation: io.c:winpr_Handle_GetInfo Unexecuted instantiation: sspicli.c:winpr_Handle_GetInfo |
172 | | |
173 | | static inline void winpr_Handle_AddRef(HANDLE handle) |
174 | 0 | { |
175 | 0 | ULONG type = 0; |
176 | 0 | WINPR_HANDLE* hdl = nullptr; |
177 | 0 |
|
178 | 0 | if (!winpr_Handle_GetInfo(handle, &type, &hdl) || !hdl) |
179 | 0 | return; |
180 | 0 |
|
181 | 0 | InterlockedIncrement(&hdl->refCount); |
182 | 0 | } Unexecuted instantiation: process.c:winpr_Handle_AddRef Unexecuted instantiation: critical.c:winpr_Handle_AddRef Unexecuted instantiation: event.c:winpr_Handle_AddRef Unexecuted instantiation: sleep.c:winpr_Handle_AddRef Unexecuted instantiation: wait.c:winpr_Handle_AddRef Unexecuted instantiation: generic.c:winpr_Handle_AddRef Unexecuted instantiation: namedPipeClient.c:winpr_Handle_AddRef Unexecuted instantiation: file.c:winpr_Handle_AddRef Unexecuted instantiation: comm.c:winpr_Handle_AddRef Unexecuted instantiation: comm_ioctl.c:winpr_Handle_AddRef Unexecuted instantiation: comm_serial_sys.c:winpr_Handle_AddRef Unexecuted instantiation: comm_sercx_sys.c:winpr_Handle_AddRef Unexecuted instantiation: comm_sercx2_sys.c:winpr_Handle_AddRef Unexecuted instantiation: pipe.c:winpr_Handle_AddRef Unexecuted instantiation: shell.c:winpr_Handle_AddRef Unexecuted instantiation: handle.c:winpr_Handle_AddRef Unexecuted instantiation: nonehandle.c:winpr_Handle_AddRef Unexecuted instantiation: apc.c:winpr_Handle_AddRef Unexecuted instantiation: thread.c:winpr_Handle_AddRef Unexecuted instantiation: nt.c:winpr_Handle_AddRef Unexecuted instantiation: comm_io.c:winpr_Handle_AddRef Unexecuted instantiation: io.c:winpr_Handle_AddRef Unexecuted instantiation: sspicli.c:winpr_Handle_AddRef |
183 | | |
184 | | /* implemented in nonehandle.c: turns an already-released handle (see CloseHandle() in handle.c) |
185 | | * into a harmless placeholder, for as long as other references to the same struct remain. */ |
186 | | void winpr_Handle_ConvertToNone(HANDLE handle); |
187 | | |
188 | | /* decrements refCount and frees the struct once it reaches zero - does not touch the underlying |
189 | | * OS resource, that's the type's real CloseHandle op's job (see CloseHandle() in handle.c). |
190 | | * Returns TRUE if this was the last reference (the handle has been freed). */ |
191 | | static inline BOOL winpr_Handle_Release(HANDLE handle) |
192 | 179k | { |
193 | 179k | ULONG type = 0; |
194 | 179k | WINPR_HANDLE* hdl = nullptr; |
195 | | |
196 | 179k | if (!winpr_Handle_GetInfo(handle, &type, &hdl) || !hdl) |
197 | 0 | return FALSE; |
198 | | |
199 | 179k | if (InterlockedDecrement(&hdl->refCount) > 0) |
200 | 0 | return FALSE; |
201 | | |
202 | 179k | free(hdl); |
203 | 179k | return TRUE; |
204 | 179k | } Unexecuted instantiation: process.c:winpr_Handle_Release Unexecuted instantiation: critical.c:winpr_Handle_Release Unexecuted instantiation: event.c:winpr_Handle_Release Unexecuted instantiation: sleep.c:winpr_Handle_Release Unexecuted instantiation: wait.c:winpr_Handle_Release Unexecuted instantiation: generic.c:winpr_Handle_Release Unexecuted instantiation: namedPipeClient.c:winpr_Handle_Release Unexecuted instantiation: file.c:winpr_Handle_Release Unexecuted instantiation: comm.c:winpr_Handle_Release Unexecuted instantiation: comm_ioctl.c:winpr_Handle_Release Unexecuted instantiation: comm_serial_sys.c:winpr_Handle_Release Unexecuted instantiation: comm_sercx_sys.c:winpr_Handle_Release Unexecuted instantiation: comm_sercx2_sys.c:winpr_Handle_Release Unexecuted instantiation: pipe.c:winpr_Handle_Release Unexecuted instantiation: shell.c:winpr_Handle_Release handle.c:winpr_Handle_Release Line | Count | Source | 192 | 179k | { | 193 | 179k | ULONG type = 0; | 194 | 179k | WINPR_HANDLE* hdl = nullptr; | 195 | | | 196 | 179k | if (!winpr_Handle_GetInfo(handle, &type, &hdl) || !hdl) | 197 | 0 | return FALSE; | 198 | | | 199 | 179k | if (InterlockedDecrement(&hdl->refCount) > 0) | 200 | 0 | return FALSE; | 201 | | | 202 | 179k | free(hdl); | 203 | 179k | return TRUE; | 204 | 179k | } |
Unexecuted instantiation: nonehandle.c:winpr_Handle_Release Unexecuted instantiation: apc.c:winpr_Handle_Release Unexecuted instantiation: thread.c:winpr_Handle_Release Unexecuted instantiation: nt.c:winpr_Handle_Release Unexecuted instantiation: comm_io.c:winpr_Handle_Release Unexecuted instantiation: io.c:winpr_Handle_Release Unexecuted instantiation: sspicli.c:winpr_Handle_Release |
205 | | |
206 | | WINPR_ATTR_NODISCARD |
207 | | static inline int winpr_Handle_getFd(HANDLE handle) |
208 | 71.7k | { |
209 | 71.7k | WINPR_HANDLE* hdl = nullptr; |
210 | 71.7k | ULONG type = 0; |
211 | | |
212 | 71.7k | if (!winpr_Handle_GetInfo(handle, &type, &hdl)) |
213 | 0 | return -1; |
214 | | |
215 | 71.7k | if (!hdl || !hdl->ops || !hdl->ops->GetFd) |
216 | 0 | return -1; |
217 | | |
218 | 71.7k | return hdl->ops->GetFd(handle); |
219 | 71.7k | } Unexecuted instantiation: process.c:winpr_Handle_getFd Unexecuted instantiation: critical.c:winpr_Handle_getFd Unexecuted instantiation: event.c:winpr_Handle_getFd Unexecuted instantiation: sleep.c:winpr_Handle_getFd wait.c:winpr_Handle_getFd Line | Count | Source | 208 | 71.7k | { | 209 | 71.7k | WINPR_HANDLE* hdl = nullptr; | 210 | 71.7k | ULONG type = 0; | 211 | | | 212 | 71.7k | if (!winpr_Handle_GetInfo(handle, &type, &hdl)) | 213 | 0 | return -1; | 214 | | | 215 | 71.7k | if (!hdl || !hdl->ops || !hdl->ops->GetFd) | 216 | 0 | return -1; | 217 | | | 218 | 71.7k | return hdl->ops->GetFd(handle); | 219 | 71.7k | } |
Unexecuted instantiation: generic.c:winpr_Handle_getFd Unexecuted instantiation: namedPipeClient.c:winpr_Handle_getFd Unexecuted instantiation: file.c:winpr_Handle_getFd Unexecuted instantiation: comm.c:winpr_Handle_getFd Unexecuted instantiation: comm_ioctl.c:winpr_Handle_getFd Unexecuted instantiation: comm_serial_sys.c:winpr_Handle_getFd Unexecuted instantiation: comm_sercx_sys.c:winpr_Handle_getFd Unexecuted instantiation: comm_sercx2_sys.c:winpr_Handle_getFd Unexecuted instantiation: pipe.c:winpr_Handle_getFd Unexecuted instantiation: shell.c:winpr_Handle_getFd Unexecuted instantiation: handle.c:winpr_Handle_getFd Unexecuted instantiation: nonehandle.c:winpr_Handle_getFd Unexecuted instantiation: apc.c:winpr_Handle_getFd Unexecuted instantiation: thread.c:winpr_Handle_getFd Unexecuted instantiation: nt.c:winpr_Handle_getFd Unexecuted instantiation: comm_io.c:winpr_Handle_getFd Unexecuted instantiation: io.c:winpr_Handle_getFd Unexecuted instantiation: sspicli.c:winpr_Handle_getFd |
220 | | |
221 | | WINPR_ATTR_NODISCARD |
222 | | static inline DWORD winpr_Handle_cleanup(HANDLE handle) |
223 | 53.7k | { |
224 | 53.7k | WINPR_HANDLE* hdl = nullptr; |
225 | 53.7k | ULONG type = 0; |
226 | | |
227 | 53.7k | if (!winpr_Handle_GetInfo(handle, &type, &hdl)) |
228 | 0 | return WAIT_FAILED; |
229 | | |
230 | 53.7k | if (!hdl || !hdl->ops) |
231 | 0 | return WAIT_FAILED; |
232 | | |
233 | | /* If there is no cleanup function, assume all ok. */ |
234 | 53.7k | if (!hdl->ops->CleanupHandle) |
235 | 17.9k | return WAIT_OBJECT_0; |
236 | | |
237 | 35.8k | return hdl->ops->CleanupHandle(handle); |
238 | 53.7k | } Unexecuted instantiation: process.c:winpr_Handle_cleanup Unexecuted instantiation: critical.c:winpr_Handle_cleanup Unexecuted instantiation: event.c:winpr_Handle_cleanup Unexecuted instantiation: sleep.c:winpr_Handle_cleanup wait.c:winpr_Handle_cleanup Line | Count | Source | 223 | 53.7k | { | 224 | 53.7k | WINPR_HANDLE* hdl = nullptr; | 225 | 53.7k | ULONG type = 0; | 226 | | | 227 | 53.7k | if (!winpr_Handle_GetInfo(handle, &type, &hdl)) | 228 | 0 | return WAIT_FAILED; | 229 | | | 230 | 53.7k | if (!hdl || !hdl->ops) | 231 | 0 | return WAIT_FAILED; | 232 | | | 233 | | /* If there is no cleanup function, assume all ok. */ | 234 | 53.7k | if (!hdl->ops->CleanupHandle) | 235 | 17.9k | return WAIT_OBJECT_0; | 236 | | | 237 | 35.8k | return hdl->ops->CleanupHandle(handle); | 238 | 53.7k | } |
Unexecuted instantiation: generic.c:winpr_Handle_cleanup Unexecuted instantiation: namedPipeClient.c:winpr_Handle_cleanup Unexecuted instantiation: file.c:winpr_Handle_cleanup Unexecuted instantiation: comm.c:winpr_Handle_cleanup Unexecuted instantiation: comm_ioctl.c:winpr_Handle_cleanup Unexecuted instantiation: comm_serial_sys.c:winpr_Handle_cleanup Unexecuted instantiation: comm_sercx_sys.c:winpr_Handle_cleanup Unexecuted instantiation: comm_sercx2_sys.c:winpr_Handle_cleanup Unexecuted instantiation: pipe.c:winpr_Handle_cleanup Unexecuted instantiation: shell.c:winpr_Handle_cleanup Unexecuted instantiation: handle.c:winpr_Handle_cleanup Unexecuted instantiation: nonehandle.c:winpr_Handle_cleanup Unexecuted instantiation: apc.c:winpr_Handle_cleanup Unexecuted instantiation: thread.c:winpr_Handle_cleanup Unexecuted instantiation: nt.c:winpr_Handle_cleanup Unexecuted instantiation: comm_io.c:winpr_Handle_cleanup Unexecuted instantiation: io.c:winpr_Handle_cleanup Unexecuted instantiation: sspicli.c:winpr_Handle_cleanup |
239 | | |
240 | | WINPR_ATTR_NODISCARD |
241 | | BOOL winpr_set_cloexec(int fd, BOOL cloexec); |
242 | | |
243 | | #endif /* WINPR_HANDLE_PRIVATE_H */ |