I'm writing a driver that requires me to clear all the memory allocated to zero. memset
is a userspace function, but I would like to know if the kernel provides a macro that helps me do this.
I looked it up in a Linux driver development book I have (it's German, so I will give a loose translation of what it basically says) and it gives the following description:
#include <asm/io.h>
void *memset(void *s, int c, size_t n);
Fills the first
n
Bytes of the given region of memory ats
with the constant byte valuec
. If you want to set regions of memory mapped I/O memory to a constant value, you must use thememset_io()
function.Returns a pointer to
s
.
Doing some more investigation... If you look into the <asm/io.h>
sources, you can find:
#include <linux/string.h> /* for memset() and memcpy() */
...but also the definition of the memset_io()
function, so I guess that this should be the correct #include
.
It's true memset()
in
include <string.h >
not supposed to appear in kernel code.And the fact is it may cost you a lot to trace down where memset()
is included during driver development. Actually memset()
is defined in
#include<linux/string.h>
it says:
#ifndef __KERNEL__
#include <string.h>
#else
/* We don't want strings.h stuff being used by user stuff by accident */
Hope this help you type down 'memset()' with 100% sure :)
According to this thread and people commenting here that have used it, memset
is available in kernel code. Maybe you just forgot to
#include <string.h>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With