kcalloc equivalent

Unless of course it’s in Haskell :wink:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Thursday, April 16, 2015 12:58 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] kcalloc equivalent

OR

And I’ll be in the middle: It doesn’t matter whether you learn to write C
in user-mode or kernel-mode, but you need to learn how to write C.

Mr. Roberts was right when he said “the questions you were asking here were
simple C questions” and we’re probably not the most, ahem, patient people on
the face of the planet, ahem, with such questions.

For the record, I’m like Mr. Kirby: I never wrote a line of user-mode C
code until I had written probably a dozen kernel-mode drivers. It took me
years to develop any sort of appreciation whatsoever for user-mode code
development. In fact, some might say I’ve yet to develop an adequate
appreciation.

Peter
OSR
@OSRDrivers


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

In order to do this:

kcalloc(Table.NumberOfStructures,sizeof(SMBIOSHeader),GFP_KERNEL)

In the windows kernel you do this:

new SMBIOSHeaderTable.NumberOfStructures

Reasons:
(1) it is short, easy to read, and easily fits on the screen without horizontal scrolling or splitting the line
(2) auto zeroes the memory like kcalloc which is less error prone than adding a supplemental RtlZeroMemory code respecifying a correct pointer and size which is particularly easy to botch with arrays because one may accidentally put an & before the pointer, not multiply out the size correctly, or even forget the line since it’s a 2nd step and there is nothing the compiler can do to warn/help. I’ve seen all of 3 of these problems in other people’s code.
(3) it is 100% type safe instead of blowing away the type with a void splat.
(4) automatically uses your driver pool tag without sprinkling it everywhere in your code (clean)
(5) goes to the default pool instead of sprinkling the pool type all over your code when you don’t need anything special…

Everyone I know uses it.

xxxxx@gmail.com wrote:

In order to do this:

kcalloc(Table.NumberOfStructures,sizeof(SMBIOSHeader),GFP_KERNEL)

In the windows kernel you do this:

new SMBIOSHeaderTable.NumberOfStructures

You only do that if you are writing in C++ and you have declared a
global “operator new”.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> In the windows kernel you do this: new SMBIOSHeaderTable.NumberOfStructures

Reasons:

Well, this thread seems to have a good potential for turning into something “exciting” - after all, we haven’t had “C vs C++” discussions for quite a while, have we. …

Anton Bassov

In the other kernel you can’t use new. So it is worth noting that in windows kernel you can. That’s it.

Hi Peter,

Got it and I will do :slight_smile:

Zakaria.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: 16 April 2015 15:43
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] kcalloc equivalent

[quote]
I have to
clarify that I’m an intern student at Micron, :slight_smile: [/quote]

Next time, you probably want to post from gmail and leave the name of your employer out of it.

Just some friendly advice,

Peter
OSR
@OSRDrivers


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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


Micron Europe Limited
Registered in England, Company No. 02341071
Registered Office: L’Avenir, Opladen Way
Bracknell, Berkshire RG12 0PH, UK

Hi Tim,

I’m not agreeing on this point, firstly it’s not C question, if it was then where is kcalloc since formal c has this function, secondly the question I asked it doesn’t implicate anything other than that I didn’t read kcalloc function definition and I have never read a professional book that said I have to. Rather I read a books that introduced me to kmalloc, kcalloc etc. as different functions each of which has different usage. I understood them and used them very well, and when I go to programming language on another platform that doesn’t have that function, it’s really common to ask where its, and also if you trace my very early comments before anyone raises the point, I figured it out on my own, rather I just carried on to get more clarification and confirmation that what I’m doing is right.

Thanks for being " trying to prove that I’m not good programmer rather than help me to be so " .

Zakaria, Intern at Micron.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: 16 April 2015 17:48
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] kcalloc equivalent

xxxxx@micron.com wrote:

My questions imply my windows drivers knowledge level, therefore I
have to clarify that I’m an intern student at Micron, :slight_smile:

Let me point out as gently as I can that the questions you were asking here were simple C questions, and were not driver-related in any way.
If you are really not comfortable with the basics of C yet, then it may be too early for you to be digging in to kernel drivers.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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


Micron Europe Limited
Registered in England, Company No. 02341071
Registered Office: L’Avenir, Opladen Way
Bracknell, Berkshire RG12 0PH, UK

Hi,

In Linux C there is a problem, I can’t declare an array while of variable size is not known until we run the execution file,
I.e. the number of structures I get from the SMBIOS entry point table, I will not be able to define the array size until I fetch the size, somehow whenever I declare array dynamically inux C gives me an issue, and I am not sure if its in windows as well .

Thanks for the heads-up and will try it out.

Zakaria. Intern at Micron.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: 17 April 2015 01:53
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] kcalloc equivalent

In order to do this:

kcalloc(Table.NumberOfStructures,sizeof(SMBIOSHeader),GFP_KERNEL)

In the windows kernel you do this:

new SMBIOSHeaderTable.NumberOfStructures

Reasons:
(1) it is short, easy to read, and easily fits on the screen without horizontal scrolling or splitting the line
(2) auto zeroes the memory like kcalloc which is less error prone than adding a supplemental RtlZeroMemory code respecifying a correct pointer and size which is particularly easy to botch with arrays because one may accidentally put an & before the pointer, not multiply out the size correctly, or even forget the line since it’s a 2nd step and there is nothing the compiler can do to warn/help. I’ve seen all of 3 of these problems in other people’s code.
(3) it is 100% type safe instead of blowing away the type with a void splat.
(4) automatically uses your driver pool tag without sprinkling it everywhere in your code (clean)
(5) goes to the default pool instead of sprinkling the pool type all over your code when you don’t need anything special…

Everyone I know uses it.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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


Micron Europe Limited
Registered in England, Company No. 02341071
Registered Office: L’Avenir, Opladen Way
Bracknell, Berkshire RG12 0PH, UK

OP: In addition to not identifying yourself as working at Micron, I have another lesson for you… Do not argue with those far senior to you, who are trying to help you.

Final piece of advice: Do not apply for a job at OSR.

You’re welcome,

Peter
OSR
@OSRDrivers

Hi Peter,

I’m quite shocked of your reply, I thought myself living in Democratic Society either US/UK, both should accept points of view obviously with full of respect and sincere and appreciation.

I appreciate your help. An again I’m an intern and learning, I am not arguing anything, just explaining my point of view.

Thanks for your understanding.

Zakaria.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: 17 April 2015 13:27
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] kcalloc equivalent

OP: In addition to not identifying yourself as working at Micron, I have another lesson for you… Do not argue with those far senior to you, who are trying to help you.

Final piece of advice: Do not apply for a job at OSR.

You’re welcome,

Peter
OSR
@OSRDrivers


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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


Micron Europe Limited
Registered in England, Company No. 02341071
Registered Office: L’Avenir, Opladen Way
Bracknell, Berkshire RG12 0PH, UK

Also, could you please remove this whole thread and deactivate my account, if not possible, please then change my email to xxxxx@zastudio.net as soon as possible, Also delete all my replies.

Many thanks in advance.

Zakaria.

zak @ zastudio.net

> Final piece of advice: Do not apply for a job at OSR.

Well, I guess it would not be that easy to find someone who fares significantly better than the OP…

After havig read his two latest “masterpieces” concerning “formalC /Linux C/Windows C” nonsense and particularly the one concerning the dynamic arrays I got a very clear picture of the OP. He seems to be just a classical example of modern-day university student who is taught how to write the OSes in Java, because all his statements are typical of someone who is accustomed to work in a managed language…

Anton Bassov

Well, to be honest I have recognised a few misspelled and miss-phrased sentences, unfortunately OSR doesn’t offer the functionality to edit on the forum, so I thought that’s fine since I’m speaking with Seniors they could understand the coax. I’m student that’s right and learning, I’m not perfect but I try my best.

Peter,

I’ve asked his manager to “have a word”.

And to send Zak to me before posting

Regards,

Mark

On 17/04/2015 13:26, xxxxx@osr.com wrote:
> OP: In addition to not identifying yourself as working at Micron, I have another lesson for you… Do not argue with those far senior to you, who are trying to help you.
>
> Final piece of advice: Do not apply for a job at OSR.
>
> You’re welcome,
>
> Peter
> OSR
> @OSRDrivers
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>
>

> I’ve asked his manager to “have a word”.

Well, this part already seems to be kind of excessive and unnecessary, don’t you think…

And to send Zak to me before posting

Well, and this one seems to defeat the very purpose of a technical NG/discussion forum…

Anton Bassov

Zak is now in the Intern Hall of Fame.

Mark Roddy

On Fri, Apr 17, 2015 at 10:08 AM, Mark S. Edwards
wrote:

> Peter,
>
> I’ve asked his manager to “have a word”.
>
> And to send Zak to me before posting
>
> Regards,
>
> Mark
>
>
>
> On 17/04/2015 13:26, xxxxx@osr.com wrote:
>
>> OP: In addition to not identifying yourself as working at Micron, I have
>> another lesson for you… Do not argue with those far senior to you, who
>> are trying to help you.
>>
>> Final piece of advice: Do not apply for a job at OSR.
>>
>> You’re welcome,
>>
>> Peter
>> OSR
>> @OSRDrivers
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> 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
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>

Hi,

I’m an intern i.e. I’m in a position that I can’t really argue or take this post further or justify myself anymore, yet one final point, to Mark Edwards you shouldn’t speak with my manager if you cared about the company as WHOLE

Sorry everyone, I innocently asked simple question and clarified that I’m student, hope this is not really causing any inconvenience to anybody.

Hope if Peter could remove it and deactivate this account.

xxxxx@gmail.com wrote:

In the other kernel you can’t use new. So it is worth noting that in windows kernel you can. That’s it.

I think you’ve drawn the wrong conclusions here.

NEITHER the Linux kernel nor the Windows kernel supports “operator
new”. That’s a C++ runtime library feature that would not be provided
by a kernel. The only way you can use “operator new” in a Windows
kernel driver is if you have supplied your own “operator new” that calls
ExAllocatePool. And if you took that exact same code but called kmalloc
instead, you could use “operator new” in the Linux kernel.

Religion in the Linux kernel community is far more strong and
fundamentalist than in the Windows kernel community, and the Linux
kernel religion is anti-C++, so it’s very rare to see any C++ at all in
the Linux kernel. It is quite possible, just as it always has been in
Windows, but you risk the derision of the community.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Zakaria Abushima (zabushima) wrote:

I’m quite shocked of your reply, I thought myself living in Democratic Society either US/UK, both should accept points of view obviously with full of respect and sincere and appreciation.

There is a common misconception, both outside and inside the US, that
“freedom of speech” means that every opinion must be accepted, welcomed,
respected, and held as true. Not so. “Freedom of speech” simply means
that you cannot be arrested for what you say. I can disagree with you,
I can state my disagreements – loudly even, and I can certainly choose
whether or not to hire you based on what you say.

In addition, this is a private forum on privately-owned equipment. The
owner of that equipment (OSR) is free to regulate and even censor the
content on it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.