Critical Section between applications?

(first longer message seems to got lost…)

Hello,

i have a USB device, which driver is based on OSR USB FX2.
I have a DLL which contains Enter / LeaveCriticalSection
to secure my USB Read / Write Sequences.
This works ok. Even when i access the DLL with multiple threads.

Now i access my DLL from two applications.
(i see two DLL_PROCESS_ATTACH).
Can i still use Enter / LeaveCriticalSection to synchronize accesses
between the the applications?
I think i must use shared memory to have the variable for the CriticalSection
in both memory areas?

Or is this the wrong way? Must it e.g. be done completely in driver?
(e.g. by taking the request, but not calling CompletionRoutine)?

Can you give me a hint?

Many thanks!

Best regards,

Martin

Yes, it is wrong way. Even if you’re able to implement it somewhat (not sharing critical sections, that’s crazy), who prevents somebody else to open the device directly and ignore your synchronization?

The driver should synchronize access to the device. The simplest way is to make the device exclusive so only one app can open it. The more complex way is to allow apps to open the device concurrently but allow them to get exclusive access for some time. Using IOCTLs like “lock” and “unlock” and once one app has the device locked, requests from other apps are queued or returned with an error. Also, you can implement some automatic locking logic to protect your sequences if driver has a way how to identify them. Beware, in both cases you have to handle app crash/close handle and automatically unlock. This is an advantage of exclusive access; OS handles everything for you.

Michal

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-512293-
xxxxx@lists.osr.com] On Behalf Of xxxxx@clibb.de
Sent: Monday, September 03, 2012 7:59 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Critical Section between applications?

(first longer message seems to got lost…)

Hello,

i have a USB device, which driver is based on OSR USB FX2.
I have a DLL which contains Enter / LeaveCriticalSection
to secure my USB Read / Write Sequences.
This works ok. Even when i access the DLL with multiple threads.

Now i access my DLL from two applications.
(i see two DLL_PROCESS_ATTACH).
Can i still use Enter / LeaveCriticalSection to synchronize accesses
between the the applications?
I think i must use shared memory to have the variable for the CriticalSection
in both memory areas?

Or is this the wrong way? Must it e.g. be done completely in driver?
(e.g. by taking the request, but not calling CompletionRoutine)?

Can you give me a hint?

Many thanks!

Best regards,

Martin


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

NOTE: The information in this message is intended for the personal and confidential use of the designated recipient(s) named above. To the extent the recipient(s) is/are bound by a non-disclosure agreement, or other agreement that contains an obligation of confidentiality, with AuthenTec, then this message and/or any attachments shall be considered confidential information and subject to the confidentiality terms of that agreement. If the reader of this message is not the intended recipient named above, you are notified that you have received this document in error, and any review, dissemination, distribution or copying of this message is strictly prohibited. If you have received this document in error, please delete the original message and notify the sender immediately.
Thank You!
AuthenTec, Inc. http://www.authentec.com/

Use Mutex

Thanks,
Cyril

-------- Original Message --------

From: xxxxx@clibb.de
Sent: Monday, September 03, 2012 11:39 AM
To: “Windows System Software Devs Interest List”
> Subject: [ntdev] Critical Section between applications?
>
> (first longer message seems to got lost…)
>
> Hello,
>
> i have a USB device, which driver is based on OSR USB FX2.
> I have a DLL which contains Enter / LeaveCriticalSection
> to secure my USB Read / Write Sequences.
> This works ok. Even when i access the DLL with multiple threads.
>
> Now i access my DLL from two applications.
> (i see two DLL_PROCESS_ATTACH).
> Can i still use Enter / LeaveCriticalSection to synchronize accesses
> between the the applications?
> I think i must use shared memory to have the variable for the CriticalSection
> in both memory areas?
>
> Or is this the wrong way? Must it e.g. be done completely in driver?
> (e.g. by taking the request, but not calling CompletionRoutine)?
>
> Can you give me a hint?
>
> Many thanks!
>
> Best regards,
>
> Martin
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

User lever or kernel synchronize is dependent on your design and requirement.
But in my opinion, synchronization should be made at kernel inside the driver.

If kernel level synchronization is made then code will always be able to handle N-processes at same time.

In order to achieve it, you have to make device object based context, device object has FS field which can be used to make per process(i.e. createfile) call.

You should check wdk sample for kernel synchronization.

Anand

In particular, note that placing a CRITICAL_SECTION in shared memory
cannot possibly work, because sitting behind it is a pointer to the local
heap, so you have no idea what it is pointing to in any other process.

Named mutex is best, and I find that the safest way is instead of calling
it “Lock” or some other trivial name, which will get you in all kinds of
trouble if anyone else uses that name, you should call it “Lock-”
where is a GUID created by GUIDGEN. Put this name in a header file
and have both applications #include that header file.
joe

> Use Mutex
>
> Thanks,
> Cyril
>
> -------- Original Message --------
>> From: xxxxx@clibb.de
>> Sent: Monday, September 03, 2012 11:39 AM
>> To: “Windows System Software Devs Interest List”
>> Subject: [ntdev] Critical Section between applications?
>>
>> (first longer message seems to got lost…)
>>
>> Hello,
>>
>> i have a USB device, which driver is based on OSR USB FX2.
>> I have a DLL which contains Enter / LeaveCriticalSection
>> to secure my USB Read / Write Sequences.
>> This works ok. Even when i access the DLL with multiple threads.
>>
>> Now i access my DLL from two applications.
>> (i see two DLL_PROCESS_ATTACH).
>> Can i still use Enter / LeaveCriticalSection to synchronize accesses
>> between the the applications?
>> I think i must use shared memory to have the variable for the
>> CriticalSection
>> in both memory areas?
>>
>> Or is this the wrong way? Must it e.g. be done completely in driver?
>> (e.g. by taking the request, but not calling CompletionRoutine)?
>>
>> Can you give me a hint?
>>
>> Many thanks!
>>
>> Best regards,
>>
>> Martin
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

> (first longer message seems to got lost…)

Hello,

i have a USB device, which driver is based on OSR USB FX2.
I have a DLL which contains Enter / LeaveCriticalSection
to secure my USB Read / Write Sequences.
This works ok. Even when i access the DLL with multiple threads.

Now i access my DLL from two applications.
(i see two DLL_PROCESS_ATTACH).
Can i still use Enter / LeaveCriticalSection to synchronize accesses
between the the applications?
I think i must use shared memory to have the variable for the
CriticalSection
in both memory areas?

A more serious question is why you need to do this synchronization at user
level. Your driver should not require user-level synchronization at all;
all conflicts should be handled in the driver.

You have asked about how to implement a solution, but you have not stated
the problem!
joe

Or is this the wrong way? Must it e.g. be done completely in driver?
(e.g. by taking the request, but not calling CompletionRoutine)?

Can you give me a hint?

Many thanks!

Best regards,

Martin


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

You cannot share a critical section cross process (even if you make sure that it is at the same base address in all processes). Doing so may result in a failure for lock release to work properly, among other things.

  • S (Msft)

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@clibb.de
Sent: Sunday, September 02, 2012 10:59 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Critical Section between applications?

(first longer message seems to got lost…)

Hello,

i have a USB device, which driver is based on OSR USB FX2.
I have a DLL which contains Enter / LeaveCriticalSection to secure my USB Read / Write Sequences.
This works ok. Even when i access the DLL with multiple threads.

Now i access my DLL from two applications.
(i see two DLL_PROCESS_ATTACH).
Can i still use Enter / LeaveCriticalSection to synchronize accesses between the the applications?
I think i must use shared memory to have the variable for the CriticalSection in both memory areas?

Or is this the wrong way? Must it e.g. be done completely in driver?
(e.g. by taking the request, but not calling CompletionRoutine)?

Can you give me a hint?

Many thanks!

Best regards,

Martin


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer