From owner-freebsd-current@freebsd.org Wed Jun 12 16:06:28 2019 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0500A15BAFCF for ; Wed, 12 Jun 2019 16:06:28 +0000 (UTC) (envelope-from brooks@spindle.one-eyed-alien.net) Received: from spindle.one-eyed-alien.net (spindle.one-eyed-alien.net [199.48.129.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B09F283827 for ; Wed, 12 Jun 2019 16:06:26 +0000 (UTC) (envelope-from brooks@spindle.one-eyed-alien.net) Received: by spindle.one-eyed-alien.net (Postfix, from userid 3001) id E192B3C0182; Wed, 12 Jun 2019 16:06:24 +0000 (UTC) Date: Wed, 12 Jun 2019 16:06:24 +0000 From: Brooks Davis To: Oliver Pinter Cc: Konstantin Belousov , Rick Macklem , "freebsd-current@FreeBSD.org" Subject: Re: adding a syscall to libc? Message-ID: <20190612160624.GG64641@spindle.one-eyed-alien.net> References: <20190608102816.GR75280@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="2qXFWqzzG3v1+95a" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Rspamd-Queue-Id: B09F283827 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.26 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; IP_SCORE(-3.57)[ip: (-9.30), ipnet: 199.48.128.0/22(-4.63), asn: 36236(-3.88), country: US(-0.06)]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; MIME_TRACE(0.00)[0:+,1:+]; DMARC_NA(0.00)[freebsd.org]; AUTH_NA(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MX_GOOD(-0.01)[cached: spindle.one-eyed-alien.net]; NEURAL_HAM_SHORT(-0.78)[-0.776,0]; R_SPF_NA(0.00)[]; SIGNED_PGP(-2.00)[]; FORGED_SENDER(0.30)[brooks@freebsd.org,brooks@spindle.one-eyed-alien.net]; R_DKIM_NA(0.00)[]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:36236, ipnet:199.48.128.0/22, country:US]; FROM_NEQ_ENVFROM(0.00)[brooks@freebsd.org,brooks@spindle.one-eyed-alien.net]; RCVD_TLS_LAST(0.00)[]; FREEMAIL_CC(0.00)[gmail.com] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jun 2019 16:06:28 -0000 --2qXFWqzzG3v1+95a Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jun 08, 2019 at 01:47:39PM +0200, Oliver Pinter wrote: > On Saturday, June 8, 2019, Konstantin Belousov wrot= e: >=20 > > On Sat, Jun 08, 2019 at 02:57:27AM +0000, Rick Macklem wrote: > > > Hi, > > > > > > I've started working of a copy_file_range() syscall for FreeBSD. I th= ink > > I have the > > > kernel patched and ready for some testing. > > > However, I'm confused about what I need to do in src/lib/libc/sys? > > > - Some syscalls have little .c files, but other ones do not. > > > When is one of these little .c files needed and, when not needed, w= hat > > else > > > needs to be done? (I notice that syscall.mk in src/sys/sys > > automagically, but > > > I can't see what else, if anything, needs to be done?) > > Most important is to add the new syscall public symbol to sys/Symbol.map > > into the correct version, FBSD_1.6 for CURRENT-13. Do no bother with > > __sys_XXX and __XXX aliases. > > > > 'Tiny .c files' are typically used for one of two purposes: > > - Convert raw kernel interface into something expected by userspace, > > often this coversion uses more generic and non-standard interface to > > implement more usual function. Examples are open(2) or waitid(2) > > which are really tiny wrappers around openat(2) and wait6(2) in > > today libc. > > - Allow libthr to hook into libc to provide additional services. Libthr > > often has to modify semantic of raw syscall, and libc contains the > > tables redirecting to implementation, the tables are patched on libthr > > load. Since tables must fill entries with some address in case libthr > > is not loaded, tiny functions which wrap syscalls are created for > > use in that tables. > > > > I think you do not need anything that complications for start, in which > > case adding new syscall consists of the following steps: > > - Add the syscall to sys/kern/syscalls.master, and if reasonable, > > to sys/compat/freebsd32/syscalls.master. > > - Consider if the syscall makes sense in capsicumized environment, > > and if yes, list the syscall in sys/kern/capabilities.conf. Typicall= y, > > if syscall provides access to the global files namespace, it must be = not > > allowed. On the other hand, if syscall only operates on already open= ed > > file descriptors, then it is suitable (but of course there are lot of > > nuances). > > - Add syscall prototype to the user-visible portion of header, > > hiding it under the proper visibility check. > > - Add syscall symbol to lib/libc/sys/Symbol.ver. > > - Implement the syscall. There are some additional details that might > > require attention: > > - If compat32 syscall going to be implemented, or you know > > that Linuxolator needs to implement same syscall and would > > like to take advantage of the code, provide > > int kern_YOURSYSCALL(); > > wrapper and declare it in sys/syscallsubr.h. Real > > implementations > > of host-native and compat32 sys_YOURSYSCALL() should be just > > decoding of uap members and call into kern_YOURSYSCALL. > > - Consider the need to add auditing for new syscall. > > - Add man page for the syscall, at lib/libc/sys/YOURSYSCALL.2, and conn= ect > > it to the build in lib/libc/sys/Makefile.inc. > > - When creating review for the change, do not include diff for generated > > files after make sysent. Similarly, when doing the commit, first com= mit > > everything non-generated, then do make -C sys/kern sysent (and > > make sysent -C sys/compat/freebsd32 sysent if appropriate) and commit > > the generated files in follow-up. >=20 >=20 > The best place for this little writeup would be in the wiki. ;) I wrote the initial version of this page long ago: https://wiki.freebsd.org/AddingSyscalls -- Brooks --2qXFWqzzG3v1+95a Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJdASL/AAoJEKzQXbSebgfADGwIAINGFN721khWIVUi7C/P50n9 ZG5D2UG3jih+ufPiTyEA7fGfrSCudowB2O8cl98V4b+o0m0LlrqoyONj+EIWKo9w NsfdIbjxDx5EWyZU+m1iUNzlyAhvNVYxQ7Vz5PB4zxJiuI3XftVlTAJZQ7+KqEdH +Xesizml5rQpb6Sv7Zpzq0KORzPRk8iwu/BfnuqPvM2wSVN+UpLpdiBnHTZBcOFu yofLfFmcM1TQE/wZ/hw0wvCl4fQwb6rnP8zvDtNLOnHKkKfkaKpxFiY1S2hLa3Y7 D3KoCw5/lBBq6gznib+sTumQ/6YvjcS3ldrmYVE0m/ys8dmePosdMDme69AXG6E= =eXhQ -----END PGP SIGNATURE----- --2qXFWqzzG3v1+95a--