False positive in PFD?

Hi.

I tried to remove some leftover PFD warning from one of our drivers, and I
discovered what is probably a false positive (both DDK 3790.1830 and
WDK6000).

If you have some code like this


LONG g_Var;

VOID MyFunction(PLONG pVar)
{
(VOID)InterlockedIncrement(pVar);
}

void SomeFunction()
{

InterlockedIncrement(&g_Var);
MyFunction(&g_Var);

}

PFD will complain that

warning 28112: A variable (g_Var) which is accessed via an Interlocked
function must always be accessed via an Interlocked function. See line XXX:
It is not always safe to access a variable which is accessed via the
Interlocked* family of functions in any other way.
Found in function ‘SomeFunction’

InterlockedXXX functions protect the access to the content of the variable,
but it’s perfectly safe to pass a pointer to the variable (although it can
be dangerous, you need to be sure that the called function MyFunction always
uses InterlockedXXX functions).

I just wanted a confirmation before throwing some #pragma’s to disable the
warnings.

Have a nice day
GV

The warning can be legitimate. What are you doing with the address of
g_Var in MyFunction? Does MyFunction also only use interlocked
operations on the parameter or does it increment/decrement it w/out
interlocked operations?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gianluca Varenni
Sent: Friday, June 29, 2007 3:37 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] False positive in PFD?

Hi.

I tried to remove some leftover PFD warning from one of our drivers, and
I
discovered what is probably a false positive (both DDK 3790.1830 and
WDK6000).

If you have some code like this


LONG g_Var;

VOID MyFunction(PLONG pVar)
{
(VOID)InterlockedIncrement(pVar);
}

void SomeFunction()
{

InterlockedIncrement(&g_Var);
MyFunction(&g_Var);

}

PFD will complain that

warning 28112: A variable (g_Var) which is accessed via an Interlocked
function must always be accessed via an Interlocked function. See line
XXX:
It is not always safe to access a variable which is accessed via the
Interlocked* family of functions in any other way.
Found in function ‘SomeFunction’

InterlockedXXX functions protect the access to the content of the
variable,
but it’s perfectly safe to pass a pointer to the variable (although it
can
be dangerous, you need to be sure that the called function MyFunction
always
uses InterlockedXXX functions).

I just wanted a confirmation before throwing some #pragma’s to disable
the
warnings.

Have a nice day
GV


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

MyFunction just accesses the variable with an Interlocked functions

void MyFunction (PDEVICE_EXTENSION pdx, PLONG GateVar)
{
LARGE_INTEGER WaitInterval;

WaitInterval.QuadPart = -100000;

while(InterlockedCompareExchange(GateVar, 0, 0) != 0)
{
KeDelayExecutionThread(KernelMode, FALSE, &WaitInterval);
}
}

Have a nice day
GV

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Friday, June 29, 2007 3:41 PM
Subject: RE: [ntdev] False positive in PFD?

The warning can be legitimate. What are you doing with the address of
g_Var in MyFunction? Does MyFunction also only use interlocked
operations on the parameter or does it increment/decrement it w/out
interlocked operations?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gianluca Varenni
Sent: Friday, June 29, 2007 3:37 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] False positive in PFD?

Hi.

I tried to remove some leftover PFD warning from one of our drivers, and
I
discovered what is probably a false positive (both DDK 3790.1830 and
WDK6000).

If you have some code like this

-----------------------------------
LONG g_Var;

VOID MyFunction(PLONG pVar)
{
(VOID)InterlockedIncrement(pVar);
}

void SomeFunction()
{

InterlockedIncrement(&g_Var);
MyFunction(&g_Var);

}
------------------------------------

PFD will complain that

warning 28112: A variable (g_Var) which is accessed via an Interlocked
function must always be accessed via an Interlocked function. See line
XXX:
It is not always safe to access a variable which is accessed via the
Interlocked* family of functions in any other way.
Found in function ‘SomeFunction’

InterlockedXXX functions protect the access to the content of the
variable,
but it’s perfectly safe to pass a pointer to the variable (although it
can
be dangerous, you need to be sure that the called function MyFunction
always
uses InterlockedXXX functions).

I just wanted a confirmation before throwing some #pragma’s to disable
the
warnings.

Have a nice day
GV


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Try annotating GateVar with __drv_interlocked (available in the 6001
WDK), that should indicate to PFD that it is being accessed with
interlocked operations in the function you are passing the var to

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gianluca Varenni
Sent: Friday, June 29, 2007 3:55 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] False positive in PFD?

MyFunction just accesses the variable with an Interlocked functions

void MyFunction (PDEVICE_EXTENSION pdx, PLONG GateVar)
{
LARGE_INTEGER WaitInterval;

WaitInterval.QuadPart = -100000;

while(InterlockedCompareExchange(GateVar, 0, 0) != 0)
{
KeDelayExecutionThread(KernelMode, FALSE, &WaitInterval);
}
}

Have a nice day
GV

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Friday, June 29, 2007 3:41 PM
Subject: RE: [ntdev] False positive in PFD?

The warning can be legitimate. What are you doing with the address of
g_Var in MyFunction? Does MyFunction also only use interlocked
operations on the parameter or does it increment/decrement it w/out
interlocked operations?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gianluca Varenni
Sent: Friday, June 29, 2007 3:37 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] False positive in PFD?

Hi.

I tried to remove some leftover PFD warning from one of our drivers, and
I
discovered what is probably a false positive (both DDK 3790.1830 and
WDK6000).

If you have some code like this

-----------------------------------
LONG g_Var;

VOID MyFunction(PLONG pVar)
{
(VOID)InterlockedIncrement(pVar);
}

void SomeFunction()
{

InterlockedIncrement(&g_Var);
MyFunction(&g_Var);

}
------------------------------------

PFD will complain that

warning 28112: A variable (g_Var) which is accessed via an Interlocked
function must always be accessed via an Interlocked function. See line
XXX:
It is not always safe to access a variable which is accessed via the
Interlocked* family of functions in any other way.
Found in function ‘SomeFunction’

InterlockedXXX functions protect the access to the content of the
variable,
but it’s perfectly safe to pass a pointer to the variable (although it
can
be dangerous, you need to be sure that the called function MyFunction
always
uses InterlockedXXX functions).

I just wanted a confirmation before throwing some #pragma’s to disable
the
warnings.

Have a nice day
GV


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

This will work with WDK6001 only.

For this particular driver I’m still using DDK3790.1830. I will probably add
a pragma to disable the warning…

Thanks anyway for the help!
GV

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Friday, June 29, 2007 4:12 PM
Subject: RE: [ntdev] False positive in PFD?

Try annotating GateVar with __drv_interlocked (available in the 6001
WDK), that should indicate to PFD that it is being accessed with
interlocked operations in the function you are passing the var to

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gianluca Varenni
Sent: Friday, June 29, 2007 3:55 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] False positive in PFD?

MyFunction just accesses the variable with an Interlocked functions

void MyFunction (PDEVICE_EXTENSION pdx, PLONG GateVar)
{
LARGE_INTEGER WaitInterval;

WaitInterval.QuadPart = -100000;

while(InterlockedCompareExchange(GateVar, 0, 0) != 0)
{
KeDelayExecutionThread(KernelMode, FALSE, &WaitInterval);
}
}

Have a nice day
GV

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Friday, June 29, 2007 3:41 PM
Subject: RE: [ntdev] False positive in PFD?

The warning can be legitimate. What are you doing with the address of
g_Var in MyFunction? Does MyFunction also only use interlocked
operations on the parameter or does it increment/decrement it w/out
interlocked operations?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gianluca Varenni
Sent: Friday, June 29, 2007 3:37 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] False positive in PFD?

Hi.

I tried to remove some leftover PFD warning from one of our drivers, and
I
discovered what is probably a false positive (both DDK 3790.1830 and
WDK6000).

If you have some code like this

-----------------------------------
LONG g_Var;

VOID MyFunction(PLONG pVar)
{
(VOID)InterlockedIncrement(pVar);
}

void SomeFunction()
{

InterlockedIncrement(&g_Var);
MyFunction(&g_Var);

}
------------------------------------

PFD will complain that

warning 28112: A variable (g_Var) which is accessed via an Interlocked
function must always be accessed via an Interlocked function. See line
XXX:
It is not always safe to access a variable which is accessed via the
Interlocked* family of functions in any other way.
Found in function ‘SomeFunction’

InterlockedXXX functions protect the access to the content of the
variable,
but it’s perfectly safe to pass a pointer to the variable (although it
can
be dangerous, you need to be sure that the called function MyFunction
always
uses InterlockedXXX functions).

I just wanted a confirmation before throwing some #pragma’s to disable
the
warnings.

Have a nice day
GV


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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