|
Message-ID: <20220629161136.GD2408@voyager> Date: Wed, 29 Jun 2022 18:11:36 +0200 From: Markus Wichmann <nullplan@....net> To: musl@...ts.openwall.com Subject: Re: Question about calloc, free in CPU_ALLOC and CPU_FREE On Wed, Jun 29, 2022 at 05:49:55PM +0200, Thomas Stüfe wrote: > Greetings, > > I have a small question about the way muslc implements the CPU_ALLOC and > CPU_FREE macros. > > I see them defined in sched.h as: > > #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) > #define CPU_FREE(set) free(set) > > whereas the glibc defines them as calls to functions __sched_cpu_alloc() > and __sched_cpufree(): > > #define __CPU_ALLOC(count) __sched_cpualloc (count) > #define __CPU_FREE(cpuset) __sched_cpufree (cpuset) > > in the end both variants allocate from C-heap, but the muslc variant gets > inlined directly into the calling code. If that calling code has a function > "free" or "calloc" (okay, less likely) these get called instead. Could also > be a class local method in C++. > That would be invalid. calloc() and free() are names defined in the C standard, so no user defined macro or function can have those names. I don't know about you point about C++, though. Could be conceivably worked around by using the :: operator, but that is only valid in C++, so we'd have to #ifdef it. > I realize this is not a big issue. But would it not be safer to do as the > glibc does in this case? > Not really; if someone wants to use reserved names, there is little reason to presume that "calloc" is any safer than "__sched_cpualloc". > Thank you, > > Thomas Ciao, Markus
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.