Hi,All.
Having a question:)
I had to declare an array of size taken from a variable:
WCHAR *wfname[(fIo.FileNameLength/2 + 1)];
But it didn’t work saying that it can’t declare array of a variable size.
So, I tried via malloc:
WCHAR *wfname = (WCHAR *)malloc((fIo.FileNameLength/2 + 1)*sizeof(WCHAR));
It worked, but I had to link msvcrt.lib to my driver to get malloc.
But now when I try to load the driver it returns:
System error 2 has occured.
The system cannot find the file specified.
The msvcrt.dll is present in my system…
Any ideas?
–
uname -a
Linux TRUSK 2.6.8-2-686 #1 Thu May 19 17:53:30 JST 2005 i686 GNU/Linux
You cannot use malloc in the kernel. You should not be linking with MSVCRT.
Take a look at the DDK documentation for ExAllocatePoolWithTag, or better
yet tak a class on driver writing.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply
wrote in message news:xxxxx@ntdev…
> Hi,All.
>
> Having a question:)
>
> I had to declare an array of size taken from a variable:
>>WCHAR *wfname[(fIo.FileNameLength/2 + 1)];
> But it didn’t work saying that it can’t declare array of a variable size.
> So, I tried via malloc:
>>WCHAR *wfname = (WCHAR *)malloc((fIo.FileNameLength/2 + 1)*sizeof(WCHAR));
> It worked, but I had to link msvcrt.lib to my driver to get malloc.
>
> But now when I try to load the driver it returns:
>>System error 2 has occured.
>>The system cannot find the file specified.
> The msvcrt.dll is present in my system…
>
>
> Any ideas?
>
>
>
> –
> uname -a
> Linux TRUSK 2.6.8-2-686 #1 Thu May 19 17:53:30 JST 2005 i686 GNU/Linux
>
> The msvcrt.dll is present in my system…
Dear shadow88, I’d hate to offend you, but are you sure
you are ready for writing a driver?
Kernel modules are built and run in a very special environment,
and a couple of books (and/or samples to be analyzed) definitely
would not hurt.
The gurus will answer your question, but think about it:
is it really worth their effort? They will simply quote something
from help files or books you can as easily read yourself.
Both sides win: you have a full info from a book instead of a quote,
and gurus spare the typing [some of them can spell but can’t type,
you know:-)].
Seriously, the complexity and depth of your questions begs for
a couple of library/practice sessions.
As to malloc, look for functions that start with ExAllocatePool… in
the DDK documentation. There are several of them, you may want
to read about ExAllocatePool and ExAllocatePoolWithTag first.
- What is common between the two, what is different?
- Which one is used more often in DDK samples? Why?
More complex (but still very basic) questions:
-
What other memory allocation facilities are there
(lookasidelists - gosh, what is it? why would they need them?)
-
Is it ok to allocate as much as you need on the stack, as you
sometimes do in a user mode app (is char my_buf[8192] ok in
the kernel? what about char my_buf[32768]?)
I wish you luck.
----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Sunday, July 30, 2006 11:29 AM
Subject: [ntdev] MSVCRT
> Hi,All.
>
> Having a question:)
>
> I had to declare an array of size taken from a variable:
>>WCHAR *wfname[(fIo.FileNameLength/2 + 1)];
> But it didn’t work saying that it can’t declare array of a variable size.
> So, I tried via malloc:
>>WCHAR *wfname = (WCHAR *)malloc((fIo.FileNameLength/2 + 1)*sizeof(WCHAR));
> It worked, but I had to link msvcrt.lib to my driver to get malloc.
>
> But now when I try to load the driver it returns:
>>System error 2 has occured.
>>The system cannot find the file specified.
> The msvcrt.dll is present in my system…
>
>
> Any ideas?
>
>
>
> –
> uname -a
> Linux TRUSK 2.6.8-2-686 #1 Thu May 19 17:53:30 JST 2005 i686 GNU/Linux
>
> —
> 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
Here we go again … now I suppose you are going pollute the list with a
dozen different questions about how to use malloc, finally accusing us of
not understanding your question. Have you even bothered to look at the
online documentation for the DDK? Hell, do you even have the DDK? This is
covered quite well in the DDK and if you bother to look at the samples you
will find many an example on how to allocate memory in the kernel. The
bottom line is you cannot use ANY of the runtime libraries, you can ONLY
link a driver with the libraries provided in the DDK.
Get the DDK and USE it.
The personal opinion of
Gary G. Little
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@voliacable.com
Sent: Sunday, July 30, 2006 10:29 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] MSVCRT
Hi,All.
Having a question:)
I had to declare an array of size taken from a variable:
WCHAR *wfname[(fIo.FileNameLength/2 + 1)];
But it didn’t work saying that it can’t declare array of a variable size.
So, I tried via malloc:
WCHAR *wfname = (WCHAR *)malloc((fIo.FileNameLength/2 + 1)*sizeof(WCHAR));
It worked, but I had to link msvcrt.lib to my driver to get malloc.
But now when I try to load the driver it returns:
System error 2 has occured.
The system cannot find the file specified.
The msvcrt.dll is present in my system…
Any ideas?
–
uname -a
Linux TRUSK 2.6.8-2-686 #1 Thu May 19 17:53:30 JST 2005 i686 GNU/Linux
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
__________ NOD32 1.1684 (20060729) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
Ok guyz, you’re right…
I’m a webdeveloper and all this kernel mode stuff is wild for me.
So, I can image how stupid may my questions look for people working in totally
different area.
Just had a simple task to modify a far-more simple driver and I’m almost done
with it.
However, I won’t disturb you anymore…
Best wishes.
Dear shadow88, I’d hate to offend you, but are you sure
you are ready for writing a driver?
Kernel modules are built and run in a very special environment,
and a couple of books (and/or samples to be analyzed) definitely
would not hurt.
The gurus will answer your question, but think about it:
is it really worth their effort? They will simply quote something
from help files or books you can as easily read yourself.
Both sides win: you have a full info from a book instead of a quote,
and gurus spare the typing [some of them can spell but can’t type,
you know:-)].
Seriously, the complexity and depth of your questions begs for
a couple of library/practice sessions.
As to malloc, look for functions that start with ExAllocatePool… in
the DDK documentation. There are several of them, you may want
to read about ExAllocatePool and ExAllocatePoolWithTag first.
- What is common between the two, what is different?
- Which one is used more often in DDK samples? Why?
More complex (but still very basic) questions:
-
What other memory allocation facilities are there
(lookasidelists - gosh, what is it? why would they need them?)
-
Is it ok to allocate as much as you need on the stack, as you
sometimes do in a user mode app (is char my_buf[8192] ok in
the kernel? what about char my_buf[32768]?)
I wish you luck.
----- Original Message -----
From:
> To: “Windows System Software Devs Interest List”
> Sent: Sunday, July 30, 2006 11:29 AM
> Subject: [ntdev] MSVCRT
>
> > Hi,All.
> >
> > Having a question:)
> >
> > I had to declare an array of size taken from a variable:
> >>WCHAR *wfname[(fIo.FileNameLength/2 + 1)];
> >
> > But it didn’t work saying that it can’t declare array of a variable size.
> >
> > So, I tried via malloc:
> >>WCHAR *wfname = (WCHAR *)malloc((fIo.FileNameLength/2 +
> >> 1)*sizeof(WCHAR));
> >
> > It worked, but I had to link msvcrt.lib to my driver to get malloc.
> >
> > But now when I try to load the driver it returns:
> >>System error 2 has occured.
> >>The system cannot find the file specified.
> >
> > The msvcrt.dll is present in my system…
> >
> >
> > Any ideas?
> >
> >
> >
> > –
> > uname -a
> > Linux TRUSK 2.6.8-2-686 #1 Thu May 19 17:53:30 JST 2005 i686 GNU/Linux
> >
> > —
> > 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
–
uname -a
Linux TRUSK 2.6.8-2-686 #1 Thu May 19 17:53:30 JST 2005 i686 GNU/Linux
> I had to declare an array of size taken from a variable:
>WCHAR *wfname[(fIo.FileNameLength/2 + 1)];
But it didn’t work saying that it can’t declare array of a variable size.
Correct, this is a basic rule of C language. Use ExAllocatePoolWithTag to
allocate such an array.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com