On 11/27/18 12:58 AM, Dmitry Timoshkov wrote:
Zebediah Figura z.figura12@gmail.com wrote:
case TYPE_SEMAPHORE:
{
KSEMAPHORE *semaphore = CONTAINING_RECORD(objs[i], KSEMAPHORE, Header);
objs[i]->WaitListHead.Blink = CreateSemaphoreW( NULL,
semaphore->Header.SignalState, semaphore->Limit, NULL );
break;
}
...
- EnterCriticalSection( &sync_cs );
- ret = InterlockedExchangeAdd( &semaphore->Header.SignalState, count );
- if (handle)
ReleaseSemaphore( handle, count, NULL );
- LeaveCriticalSection( &sync_cs );
Wouldn't it be better to use native instead of win32 APIs? This way you would be able to propagate errors instead of ignoring them.
Kernel sync functions, as a rule, don't return errors. For example, KeReleaseSemaphore() returns the previous count, and raises an exception if the limit is exceeded. Similarly, while KeWaitForMultipleObjects() does return an NTSTATUS, error conditions (like passing more than 64 objects, or waiting too many times on a mutex) result in exceptions or panics.