Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Oct 2016 19:28:50 -0700
From:      Julian Elischer <julian@freebsd.org>
To:        freebsd-hackers@freebsd.org, Alan Somers <asomers@FreeBSD.org>
Subject:   Re: Proper way to add vendor-specific syscalls? [Correct answer] :-)
Message-ID:  <7f0a642b-9c05-3bb6-53ee-66424a26b661@freebsd.org>
In-Reply-To: <CAOtMX2gi0rvC85qcUb2UZRbVGB%2BS%2BeXuAzzxn50GmUV4QKKghg@mail.gmail.com>
References:  <CAOtMX2gi0rvC85qcUb2UZRbVGB%2BS%2BeXuAzzxn50GmUV4QKKghg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 3/10/2016 10:48 AM, Alan Somers wrote:
> What's the proper way to add a vendor-specific syscall? The comments
> in kern/syscalls.master suggest that they should be put in the range
> from 151-180, but most of that range is actually occupied.  Only five
> nosys slots are available.  If I add syscalls to the end of the list,
> they'll likely collide with future standard syscalls.  Should I just
> added ~100 nosys syscalls to the end of the list, and put my custom
> syscalls afterwards?  Is there any penalty to lengthening the list?
>
> -Alan
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"

the correct way is to allow them to dynamically allocate a syscall, 
(assuming they are in a module)
see man modstat(2)  the syscall number is in the modspecfic data.
also see the SYSCALL_MODULE(2) man page

read /usr/share/examples/kld/syscall
and
read both the module and the test program.

key parts are:
(in the module:

the module needs something like:

static int ddfenabled_offset = NO_SYSCALL;
static struct sysent ddfenabled_sysent = {
         AS(ddfenabled_args),
         (sy_call_t *)ddfenabled,
         AUE_NULL,
         NULL,
         0,
         0,
         0
};
SYSCALL_MODULE(ddfenabled, &ddfenabled_offset, &ddfenabled_sysent, 
ddload, NULL);

the user code needs something like:

static int ddfenabled_sysno = 0;
/*
  * Module init
  */
int rlu_init(void)
{
     struct module_stat mstat;
     int modid;

     /* Find some dedup-related syscalls */
     if (ddfenabled_sysno == 0) {
         mstat.version = sizeof(mstat);
         if ((modid = modfind("ddfenabled")) == -1 || modstat(modid, 
&mstat) == -1) {
             return -1;
         }
         ddfenabled_sysno = mstat.data.intval;
     }

     return 0;
}





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7f0a642b-9c05-3bb6-53ee-66424a26b661>