__kmemdup_nul(9)
π __kmemdup_nul β Kernel API Manual, but make it make sense π
okay so bestie, welcome to the <pink>Kernel API Manual</pink> entry for __kmemdup_nul(9) β yes the double-underscore one, she's the β¨internalβ¨ girlie, put some respect on her name π
πΈ NAME πΈ
__kmemdup_nul β creates a NUL-terminated string from @s, which might be unterminated π±
like, @s might just rawdog its way to the end with no \0 in sight, and this function is the one that shows up with a little terminator for her π«Ά
β¨ SYNOPSIS β¨
char * __kmemdup_nul (const char *s , size_t len , gfp_t gfp );
that's the whole vibe check right there π
π¦ ARGUMENTS π¦
sβ the data to copy. literally the payload, the main character, the whole reason we're here πlenβ the size of the data, and no bestie, this does not include the NUL terminator, so don't be out here counting her πgfpβ the GFP mask used in thekmalloccall when allocating memory. it's giving "how do you want this allocation to go down" energy β
π RETURN π
you get back a newly allocated copy of s with NUL-termination β slay π β or NULL in case of error π so like, check your return values, fr fr, no cap, this is the moment where NULL checks are non-negotiable π
π SEE ALSO π
ok so this is the friend group, everybody's tagged π«Ά
Kernel file ./mm/util.c
then, in the order the manpage hands them to us, no reshuffling, no skipping:
kfree_const(9)kstrdup(9)kstrdup_const(9)kstrndup(9)kmemdup(9)kmemdup_array(9)kvmemdup(9)kmemdup_nul(9)memdup_user(9)vmemdup_user(9)strndup_user(9)memdup_user_nul(9)randomize_page(9)__account_locked_vm(9)account_locked_vm(9)__vmalloc_array(9)vmalloc_array(9)__vcalloc(9)vcalloc(9)folio_mapping(9)folio_copy(9)get_cmdline(9)mem_dump_obj(9)compat_set_desc_from_vma(9)__compat_vma_mmap(9)compat_vma_mmap(9)snapshot_page(9)mmap_action_prepare(9)mmap_action_complete(9)folio_pte_batch(9)page_range_contiguous(9)
π‘ no seriously, that's all of them, don't @ me, I didn't invent a single one and I didn't drop a single one either π₯
and that's the page, bestie! π
tiny little note before I go β this one lives in the ./mm section, dated October 2026, and it's filed under the header __kmemdup_nul(9) in the <purple>Kernel API Manual</purple>. go forth and terminate your strings properly, mwah ππβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms