Re: Regarding the understanding of the malloc(3) code

2020-03-27 Thread Neeraj Pal
On Fri, Mar 27, 2020 at 3:21 PM Otto Moerbeek wrote: > For chunk size 256, there will indeed be 16 chunks in a page. i will > *not* be 255 in that case, but 15. There is no such thing as > MALLOC_BYTES. the memset will becomes memset(p->bits, 0xff, 2) and > set p->bits[0] to to 0x The line

Re: Regarding the understanding of the malloc(3) code

2020-03-27 Thread Otto Moerbeek
On Fri, Mar 27, 2020 at 02:21:44PM +0530, Neeraj Pal wrote: > On Wed, Mar 25, 2020 at 2:06 AM Otto Moerbeek wrote: > > > pp points to a page of chunks > > bp point to the associated meta info: a bitmap that says which chunks > > in the page are free. The bitmap is an aray of shorts, so 16 bits p

Re: Regarding the understanding of the malloc(3) code

2020-03-27 Thread Neeraj Pal
On Wed, Mar 25, 2020 at 2:06 AM Otto Moerbeek wrote: > pp points to a page of chunks > bp point to the associated meta info: a bitmap that says which chunks > in the page are free. The bitmap is an aray of shorts, so 16 bits per > entry. > per entry means for our case bits[1], so only one entry

Re: Regarding the understanding of the malloc(3) code

2020-03-24 Thread Otto Moerbeek
On Wed, Mar 25, 2020 at 01:54:51AM +0530, Neeraj Pal wrote: > Hi Otto, > > I am having two small issues or confusions: > > First Query: > > 885 /* > 886 * Allocate a page of chunks > 887 */ > 888 static struct chunk_info * > 889 omalloc_make_chunks(struct dir_info *d, int bits, int listn

Re: Regarding the understanding of the malloc(3) code

2020-03-24 Thread Neeraj Pal
Hi Otto, I am having two small issues or confusions: First Query: 885 /* 886 * Allocate a page of chunks 887 */ 888 static struct chunk_info * 889 omalloc_make_chunks(struct dir_info *d, int bits, int listnum) 890 { 891 struct chunk_info *bp; 892 void *pp; 893 894

Re: Regarding the understanding of the malloc(3) code

2020-03-24 Thread Neeraj Pal
On Wed, Mar 18, 2020 at 4:01 PM Otto Moerbeek wrote: > Not all meta-data canaries live in r/o memory. > > A thing that also helps is to follow the cvs history of a file. The > first version of my malloc (form 2008) was more simple, and looking at > the diffs through the years gives you great hin

Re: Regarding the understanding of the malloc(3) code

2020-03-18 Thread Otto Moerbeek
On Wed, Mar 18, 2020 at 03:35:45PM +0530, Neeraj Pal wrote: > On Wed, 18 Mar, 2020, 12:46 pm Otto Moerbeek, wrote: > > > There are several types of canaries. They try to detect corruption of > > various meta data structures. There are alo canaries for user allocated > > data, they are enabled wi

Re: Regarding the understanding of the malloc(3) code

2020-03-18 Thread Neeraj Pal
On Wed, 18 Mar, 2020, 12:46 pm Otto Moerbeek, wrote: > There are several types of canaries. They try to detect corruption of > various meta data structures. There are alo canaries for user allocated > data, they are enabled with the C option. > Yeah, I am using option C through sysctl(8) to under

Re: Regarding the understanding of the malloc(3) code

2020-03-18 Thread Otto Moerbeek
On Wed, Mar 18, 2020 at 07:29:51AM +0530, Neeraj Pal wrote: > On Fri, Mar 13, 2020, at 11:45 AM Otto Moerbeek wrote: > > > > Please indent your code snippets. > yeah, my apologies. I shall indent the code snippets. > > > > > di_info is special. Having a guard page on both sides for regular > > a

Re: Regarding the understanding of the malloc(3) code

2020-03-17 Thread Neeraj Pal
On Fri, Mar 13, 2020, at 11:45 AM Otto Moerbeek wrote: > > Please indent your code snippets. yeah, my apologies. I shall indent the code snippets. > > di_info is special. Having a guard page on both sides for regular > allocation can be done, but would waste more pages. Note that > allocations ar

Re: Regarding the understanding of the malloc(3) code

2020-03-12 Thread Otto Moerbeek
On Fri, Mar 13, 2020 at 03:43:21AM +0530, Neeraj Pal wrote: > On Tue, Mar 10, 2020 at 4:03 PM Otto Moerbeek wrote: > > There's an off by one in your question :-) > Yeah, sorry about that, actually in flow of writing the mail forgot to notice. > > > Fo single threaded programs, two malloc_dir poo

Re: Regarding the understanding of the malloc(3) code

2020-03-12 Thread Neeraj Pal
On Tue, Mar 10, 2020 at 4:03 PM Otto Moerbeek wrote: > There's an off by one in your question :-) Yeah, sorry about that, actually in flow of writing the mail forgot to notice. > Fo single threaded programs, two malloc_dir pools are maintained. > One for MAP_CONCEALED memory (#0) and one for regu

Re: Regarding the understanding of the malloc(3) code

2020-03-10 Thread Otto Moerbeek
On Tue, Mar 10, 2020 at 03:04:00AM +0530, Neeraj Pal wrote: > Hi there, > > I am reading and learning the internals of malloc(3). > So, after compiling the debug version of libc and using it for one > basic sample code for malloc(3). > > Not able to understand some parts of the following code sn

Regarding the understanding of the malloc(3) code

2020-03-09 Thread Neeraj Pal
Hi there, I am reading and learning the internals of malloc(3). So, after compiling the debug version of libc and using it for one basic sample code for malloc(3). Not able to understand some parts of the following code snippet: void _malloc_init(int from_rthreads) { u_int i, nmutexes; s