From owner-freebsd-current@freebsd.org Sat Jun 8 11:47:41 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 9F69715C9ACE for ; Sat, 8 Jun 2019 11:47:41 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: from mail-yw1-xc29.google.com (mail-yw1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 41CA286F50 for ; Sat, 8 Jun 2019 11:47:41 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: by mail-yw1-xc29.google.com with SMTP id 186so1778409ywo.4 for ; Sat, 08 Jun 2019 04:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=HSvta/ab8mNeX3QhYj4D0RA3PuZw8fUGdStTGBsQMX8=; b=CyFSsa9MjIqx7njVoyMs3HoPuHZOlm0Y+MI1Rwxqkenfu/INoimcYzGWGT80K6PYqU zxAKxQugUWaHIK4WtiT2ssIjTOVL6e6YOki6EfEr9mXqXdKJgXFf4zLGzoZbxYTiPSmY pm2qf4EepQix2QjDNwZNgICRMDAcXAvFeq/+DGLPcN+DlCL+kBq7hzj5RQjnV6zIHmjD 5tHNCR4yTYfcThDHbbzoMITWq2TgOjLgDF302hYdjigYYexJupxWdIuFQVZodqZ7Bvb9 1wzPkEzR6rzNgp+sH2DQkXyBRUmEdqtep5lmA4/5qotIiWdKaK5yzEPrPR5wEUS0U5Ds NLCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=HSvta/ab8mNeX3QhYj4D0RA3PuZw8fUGdStTGBsQMX8=; b=UmSiOoTEJ17Lb3Sj6EngXTcdTK+sdpIeJX99k2JQ1wbwWLB8aOfIzkFNN0and90IF6 MkToH+mwt9YQiT9v2Mrt8otPCGwWntABXF6R7GyUHB5hDPNFtTebLoXEi106iJZWHpWT ucOml2syZikXVufC0QI2qC8b2fnkkTYtp15oGRWO7pC3iZQIFArcDgJlhaVF9g2m1K8f 1xnDa94hulHCYjC8ZgmXOJJc/sO4SzhdJN8+7xSG0OfMpCf4glEj0eOLHkVMGhC57Def FmxSXz5aJ7EE0XpLbPi1sKlmGoVAg6IaOwCBNxvP/KeiX7qT9otH3HNjCauTIZgFMfDZ aLCw== X-Gm-Message-State: APjAAAXVWi5gNoNzEzn7USZKrca5NlWnzkzx1IbJaiy1hb36q7+4Iuo7 f3BpbyfweHjEL4TXZ7+bIgcmC8cF9Ufs8QtBU5DsYbqG4MY= X-Google-Smtp-Source: APXvYqxz3h8uiPaiRcQncDoSMfGR+Bgsf+LbqDxZoQn8RMIYPJB2HZQWjq3OqCdjMnMO0EqTcrSJ+ZCEtq9sUIJT6GU= X-Received: by 2002:a81:3a46:: with SMTP id h67mr28184055ywa.455.1559994460469; Sat, 08 Jun 2019 04:47:40 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:2c91:0:0:0:0:0 with HTTP; Sat, 8 Jun 2019 04:47:39 -0700 (PDT) In-Reply-To: <20190608102816.GR75280@kib.kiev.ua> References: <20190608102816.GR75280@kib.kiev.ua> From: Oliver Pinter Date: Sat, 8 Jun 2019 13:47:39 +0200 Message-ID: Subject: Re: adding a syscall to libc? To: Konstantin Belousov Cc: Rick Macklem , "freebsd-current@FreeBSD.org" X-Rspamd-Queue-Id: 41CA286F50 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.97 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.970,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Sat, 08 Jun 2019 11:47:41 -0000 On Saturday, June 8, 2019, Konstantin Belousov wrote: > 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 think > 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, what > 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. Typically, > if syscall provides access to the global files namespace, it must be not > allowed. On the other hand, if syscall only operates on already opened > 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 connect > 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 commit > 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. The best place for this little writeup would be in the wiki. ;) > > > > > Thanks in advance for your help, rick > > ps: I am using the Linux man pages for the syscall ABI. At some point, > I'll put this > > in phabricator and post here for comments/review. > > _______________________________________________ > > freebsd-current@freebsd.org mailing list > > https://lists.freebsd.org/mailman/listinfo/freebsd-current > > To unsubscribe, send any mail to " > freebsd-current-unsubscribe@freebsd.org" > _______________________________________________ > freebsd-current@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >