Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Jul 2016 09:05:35 -0700
From:      Conrad Meyer <cem@freebsd.org>
To:        Adam Starak <starak.adam@gmail.com>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Modify user space from kernel.
Message-ID:  <CAG6CVpWdZMYqKLzz1H70Hq_SXF1eeOcEy0%2BiU6DYMVkAkqgAhg@mail.gmail.com>
In-Reply-To: <CAAz%2B7vqLgd5GSBfFMdD-xsAsEoujgPh8ZdKY4xZ1LO0h30OmSQ@mail.gmail.com>
References:  <CAAz%2B7vqLgd5GSBfFMdD-xsAsEoujgPh8ZdKY4xZ1LO0h30OmSQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jul 29, 2016 at 6:11 AM, Adam Starak <starak.adam@gmail.com> wrote:
> Hello!
>
> My name is Adam. I participate in Google Summer of Code this year. I came
> up with a big problem, which doesn't allow me to go further in my project=
.
>
> I made a new syscall, which is going to retrieve sysctl data and put it
> inside the nvlist. And here my problem is. I need to move somehow this da=
ta
> (packed nvlist) into the user space. Is there any chance to pass data fro=
m
> kernel to user space without knowing the size of it?
>
> Right now, the implementation of __sysctl() function requests void pointe=
r
> and size in order to get data. If allocated memory is too low, it returns
> ENOMEM and you need to realloc the data. I wanted to avoid this situation=
.

Hey Adam,

That is the usual way to do it.  Just curious =E2=80=94 why do you want to
avoid that situation?

Your other option might be to put an upper limit on the size of the
result, and pass a buffer of that size in from userspace.  But then
you are artificially limited to some arbitrary size and must
preallocate a large buffer even in the case that the output is small.

Best,
Conrad



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpWdZMYqKLzz1H70Hq_SXF1eeOcEy0%2BiU6DYMVkAkqgAhg>