site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Thread-index: AcVAKKGC8AAkxdLDTZiLxBpKERH3PQABOCMQ Thread-topic: Kernel stack size Hey Thanks Nikita, I did not know about the M_ZERO flag. I appreciate you taking the time to give us all that tip. Carl -----Original Message----- From: darwin-kernel-bounces+csmith=fortresstech.com@lists.apple.com [mailto:darwin-kernel-bounces+csmith=fortresstech.com@lists.apple.com] On Behalf Of Nikita Danilov Sent: Wednesday, April 13, 2005 8:59 AM To: Carl Smith Cc: darwin-kernel@lists.apple.com Subject: Re: Kernel stack size Carl Smith writes:
OK let me try it another way.
I have this structure declared as global: Struct Frame_Data { void *buff1; void *buff2; void *buff3; }
Then I declare as a global:
Int g_Array_Cnt = 0;
struct Frame_Data my_data[50];
So in my kernel's init routine I do:
While(g_Array_Cnt < 50) { if((my_data[g_Array_Cnt].buff1 = _MALLOC(1600, M_TEMP, M_WAITOK)) != 0) { bzero(&my_data[g_Array_Cnt].buff1, 1600);
if((my_data[g_Array_Cnt].buff2 = _MALLOC(1600, M_TEMP, M_WAITOK)) != 0) { bzero(&my_data[g_Array_Cnt].buff2, 1600);
if((my_data[g_Array_Cnt].buff3 = _MALLOC(1600, M_TEMP, M_WAITOK)) != 0) { bzero(&my_data[g_Array_Cnt].buff3, 1600); } else // error handling } else // error handling } else // error handling
This (after correcting obvious error pointed to by others in this thread) can be simplified to enum { FRAME_BUF_SIZE = 1600 }; my_data[g_Array_Cnt].buff1 = _MALLOC(FRAME_BUF_SIZE, M_TEMP, M_WAITOK | M_ZERO); my_data[g_Array_Cnt].buff2 = _MALLOC(FRAME_BUF_SIZE, M_TEMP, M_WAITOK | M_ZERO); my_data[g_Array_Cnt].buff3 = _MALLOC(FRAME_BUF_SIZE, M_TEMP, M_WAITOK | M_ZERO); M_ZERO automatically zeroes allocated space, and M_WAITOK is guaranteed to return non-NULL (or at least a _lot_ of places in core XNU code assumes it is.). Identical calls to _MALLOC can be further factored into special frame_alloc_buf() function. Nikita. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/csmith%40fortresste ch.com This email sent to csmith@fortresstech.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
Carl Smith