Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.ms-windows.programmer.nt.kernel-mode > #25 > unrolled thread
| Started by | xmllmx <xmllmx@gmail.com> |
|---|---|
| First post | 2012-05-26 13:04 -0700 |
| Last post | 2012-05-27 18:52 -0700 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.os.ms-windows.programmer.nt.kernel-mode
Is memcmp an unsolved symbol in NT kernel driver even if compiled with /Oi? xmllmx <xmllmx@gmail.com> - 2012-05-26 13:04 -0700
Re: Is memcmp an unsolved symbol in NT kernel driver even if compiled with /Oi? "Don Burn" <burn@windrvr.com> - 2012-05-26 20:19 +0000
Re: Is memcmp an unsolved symbol in NT kernel driver even if compiled with /Oi? xmllmx <xmllmx@gmail.com> - 2012-05-26 13:37 -0700
Re: Is memcmp an unsolved symbol in NT kernel driver even if compiled with /Oi? Tim Roberts <timr@probo.com> - 2012-05-27 18:52 -0700
| From | xmllmx <xmllmx@gmail.com> |
|---|---|
| Date | 2012-05-26 13:04 -0700 |
| Subject | Is memcmp an unsolved symbol in NT kernel driver even if compiled with /Oi? |
| Message-ID | <44201cc4-e49a-49fe-9335-5f642e911afd@googlegroups.com> |
Code Sample 1:
#include <ntifs.h>
NTSTATUS DriverEntry(PDRIVER_OBJECT param1, PUNICODE_STRING param2)
{
char s1[] = "Hello";
char s2[] = "World";
int n = memcmp(s1, s2, 5);
return 0;
}
WDK compiler reports: error LNK2019: unsolved extern symbol _memcmp referenced in function _DriverEntry@8
However, if I modify a bit the code as follows, then the compiler will accept it.
Code Sample 2:
#include <ntifs.h>
NTSTATUS DriverEntry(PDRIVER_OBJECT param1, PUNICODE_STRING param2)
{
char s1[] = "Hello";
char s2[] = "World";
memcmp(s1, s2, 5);
return 0;
}
Why?
Thanks in advance!
[toc] | [next] | [standalone]
| From | "Don Burn" <burn@windrvr.com> |
|---|---|
| Date | 2012-05-26 20:19 +0000 |
| Message-ID | <%Uawr.38069$9H3.6723@newsfe06.iad> |
| In reply to | #25 |
Use RtlCompareMemory not memcmp.
Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
"xmllmx" <xmllmx@gmail.com> wrote in message
news:44201cc4-e49a-49fe-9335-5f642e911afd@googlegroups.com:
> Code Sample 1:
>
> #include <ntifs.h>
>
> NTSTATUS DriverEntry(PDRIVER_OBJECT param1, PUNICODE_STRING param2)
> {
> char s1[] = "Hello";
> char s2[] = "World";
>
> int n = memcmp(s1, s2, 5);
>
> return 0;
> }
>
> WDK compiler reports: error LNK2019: unsolved extern symbol _memcmp referenced in function _DriverEntry@8
>
> However, if I modify a bit the code as follows, then the compiler will accept it.
>
> Code Sample 2:
>
> #include <ntifs.h>
>
> NTSTATUS DriverEntry(PDRIVER_OBJECT param1, PUNICODE_STRING param2)
> {
> char s1[] = "Hello";
> char s2[] = "World";
>
> memcmp(s1, s2, 5);
>
> return 0;
> }
>
> Why?
>
> Thanks in advance!
[toc] | [prev] | [next] | [standalone]
| From | xmllmx <xmllmx@gmail.com> |
|---|---|
| Date | 2012-05-26 13:37 -0700 |
| Message-ID | <08994d02-b9c9-4bae-ad94-dbc0e99a2997@googlegroups.com> |
| In reply to | #26 |
On Sunday, May 27, 2012 4:19:07 AM UTC+8, Don Burn wrote:
> Use RtlCompareMemory not memcmp.
>
>
> Don Burn
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
>
>
>
>
> "xmllmx" <xmllmx@gmail.com> wrote in message
> news:44201cc4-e49a-49fe-9335-5f642e911afd@googlegroups.com:
>
> > Code Sample 1:
> >
> > #include <ntifs.h>
> >
> > NTSTATUS DriverEntry(PDRIVER_OBJECT param1, PUNICODE_STRING param2)
> > {
> > char s1[] = "Hello";
> > char s2[] = "World";
> >
> > int n = memcmp(s1, s2, 5);
> >
> > return 0;
> > }
> >
> > WDK compiler reports: error LNK2019: unsolved extern symbol _memcmp referenced in function _DriverEntry@8
> >
> > However, if I modify a bit the code as follows, then the compiler will accept it.
> >
> > Code Sample 2:
> >
> > #include <ntifs.h>
> >
> > NTSTATUS DriverEntry(PDRIVER_OBJECT param1, PUNICODE_STRING param2)
> > {
> > char s1[] = "Hello";
> > char s2[] = "World";
> >
> > memcmp(s1, s2, 5);
> >
> > return 0;
> > }
> >
> > Why?
> >
> > Thanks in advance!
Dear Don,
I know RtlCompareMemory is a better choice. But I just wonder its cause. I have a third-party source code which uses a lot of memcmp, so I have to solve it.
Thank you very much.
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2012-05-27 18:52 -0700 |
| Message-ID | <m0m5s75g8dnjvt9obl5holkjk1fe8p0b8b@4ax.com> |
| In reply to | #27 |
xmllmx <xmllmx@gmail.com> wrote:
>
>I know RtlCompareMemory is a better choice. But I just wonder its cause.
You must have changed more than just the "int n =". The difference here is
the optimization level.
memcmp is an intrinsic. If you have intrinsics enabled (/Oi), then the
compiler expands the code for memcmp inline, by using a "rep cmpsb"
instruction. No function call is required. If you have the instrinsic
switch turned off, then it compiles a call to the external function memcmp,
which must exist.
By the way, "memcmp", like most of the C run-time library, is available for
kernel drivers in the library libcntpr.lib. Just add
USE_LIBCNTPR=1
to your "sources" file.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.os.ms-windows.programmer.nt.kernel-mode
csiph-web