Re: mallocarray(9)

2014-07-10 Thread Matthew Dempsky
On Thu, Jul 10, 2014 at 12:34 PM, Jean-Philippe Ouellet wrote: > 2nd one should be mallocarray. Doh, fixed. Thanks!

Re: mallocarray(9)

2014-07-10 Thread Jean-Philippe Ouellet
On Thu, Jul 10, 2014 at 12:02:40PM -0700, Matthew Dempsky wrote: > -.Fn malloc "unsigned long size" "int type" "int flags" > +.Fn malloc "size_t size" "int type" "int flags" > +.Ft void * > +.Fn malloc "size_t nmemb" "size_t size" "int type" "int flags" 2nd one should be mallocarray.

Re: mallocarray(9)

2014-07-10 Thread Ted Unangst
On Thu, Jul 10, 2014 at 12:02, Matthew Dempsky wrote: > + panic("overflow"); Print the sizes here and ok with me. panic("reallocarray overflow: %zu * %zu", num, size);

Re: mallocarray(9)

2014-07-10 Thread Matthew Dempsky
e.9 ktrem ktrace.9 ktrsysret.9 ktrace.9 KTRPOINT.9 MLINKS+=lock.9 lockinit.9 lock.9 lockmgr.9 lock.9 lockstatus.9 MLINKS+=log.9 addlog.9 -MLINKS+=malloc.9 free.9 +MLINKS+=malloc.9 mallocarray.9 malloc.9 free.9 MLINKS+=membar_sync.9 membar_enter.9 membar_sync.9 membar_exit.9 \ memba

Re: mallocarray(9)

2014-07-10 Thread Ted Unangst
On Thu, Jul 10, 2014 at 10:28, Matthew Dempsky wrote: > We've found a bunch of uses for reallocarray() in userland, and I > think the idiom is worth reusing in the kernel. There are enough > places where we do malloc(x * y) that I think it makes sense to add > mallocarray(x, y). > +void *malloc(u

Re: mallocarray(9)

2014-07-10 Thread Matthew Dempsky
On Thu, Jul 10, 2014 at 10:28:35AM -0700, Matthew Dempsky wrote: > +/* > + * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX > + * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW > + */ > +#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) > + > +void * > +mallocarray(unsigned long nme

mallocarray(9)

2014-07-10 Thread Matthew Dempsky
232,7 @@ MLINKS+=ktrace.9 ktrcsw.9 ktrace.9 ktrem ktrace.9 ktrsysret.9 ktrace.9 KTRPOINT.9 MLINKS+=lock.9 lockinit.9 lock.9 lockmgr.9 lock.9 lockstatus.9 MLINKS+=log.9 addlog.9 -MLINKS+=malloc.9 free.9 +MLINKS+=malloc.9 mallocarray.9 malloc.9 free.9 MLINKS+=membar_sync.9 membar_enter.9 membar_s