Regarding getrandom syscall
mpg at elzevir.fr
Tue Jun 21 15:10:50 EDT 2016
Maybe your unistd.h comes from an older kernel? That would explain why
it doesn't define that symbol.
Here  is some code using that syscall successfully, you can see it
looks a lot like Sayutin's code, except it does a few more compile-time
and runtime checks to fallback on using /dev/urandom if necessary.
On 21/06/2016 15:41, Avantika Rawat wrote:
> Thanks for the suggestion but i am getting following error
> error: 'SYS_getrandom' undeclared (first use in this function)
> then i have replaced the SYS_getrandom by 275 in syscall(275, -- args--);
> as 275 is the __NR_getrandom defines in unistd.h file, but it is
> returning -1.
> Can somebody tell me what i am missing here??
> . Also in /proc/kallsyms it is showing two syscalls added for getrandom
> ffffffff80417a38 T SyS_getrandom
> ffffffff80417a38 T sys_getrandom
> On Sat, Jun 18, 2016 at 7:12 PM, Sayutin Dmitry <cdkrot at yandex.ru> wrote:
>> Well, in fact it is not hard.
>> Just use syscall(2) provided by libc.
>> You need to provide to this function syscall id and syscall args.
>> Syscall id can be retrieved from macro constant
>> Should look something like:
>> #define _GNU_SOURCE
>> #include <unistd.h>
>> #include <sys/syscall.h>
>> syscall(SYS_getrandom, -- your - args - here --);
>> It returns long value - the result of syscall.
>> If it is between [-4095; -1] then it is negated errno, otherways it is return value.
>> 18.06.2016, 16:32, "Anoop" <anoop.chargotra at gmail.com>:
>>> Hi Avantika,
>>> On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <avani.rawat at gmail.com> wrote:
>>>> Hi ALL,
>>>> I am trying to use getrandom syscall in kernel 3.10.20 by following this
>>>> i have compiled the kernel and now want to call the getrandom syscall from
>>>> userspace to generate random numbers. But i am getting following error while
>>>> calling the getrandom () from userspace.
>>>> (.text.startup+0x18): undefined reference to `getrandom'
>>>> (.text.startup+0x1c): undefined reference to `getrandom'
>>> Your user space program will not know where 'getrandom' is defined
>>> unless it's in the C library. You need to research more on how to call
>>> custom system calls.
>>>> Avantika Rawat
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies at kernelnewbies.org
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>> Sayutin Dmitry <cdkrot at yandex.com>
More information about the Kernelnewbies