From owner-freebsd-current@freebsd.org Sun Jun 9 06:13:02 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 856AC15BEB5E for ; Sun, 9 Jun 2019 06:13:02 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from CAN01-QB1-obe.outbound.protection.outlook.com (mail-eopbgr660061.outbound.protection.outlook.com [40.107.66.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "GlobalSign Organization Validation CA - SHA256 - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F12EF8B03E for ; Sun, 9 Jun 2019 06:13:01 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from YQXPR01MB3128.CANPRD01.PROD.OUTLOOK.COM (52.132.93.160) by YQXPR01MB3879.CANPRD01.PROD.OUTLOOK.COM (52.132.94.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1965.12; Sun, 9 Jun 2019 06:12:59 +0000 Received: from YQXPR01MB3128.CANPRD01.PROD.OUTLOOK.COM ([fe80::f9fe:559f:fdc:9e5a]) by YQXPR01MB3128.CANPRD01.PROD.OUTLOOK.COM ([fe80::f9fe:559f:fdc:9e5a%3]) with mapi id 15.20.1965.017; Sun, 9 Jun 2019 06:12:59 +0000 From: Rick Macklem To: Konstantin Belousov CC: "freebsd-current@FreeBSD.org" Subject: Re: adding a syscall to libc? Thread-Topic: adding a syscall to libc? Thread-Index: AQHVHaUq4CSrPmO6/E+nutIFTmCjBKaRjnkAgAFG004= Date: Sun, 9 Jun 2019 06:12:59 +0000 Message-ID: References: , <20190608102816.GR75280@kib.kiev.ua> In-Reply-To: <20190608102816.GR75280@kib.kiev.ua> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5097e902-840c-4726-82c1-08d6eca18596 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:YQXPR01MB3879; x-ms-traffictypediagnostic: YQXPR01MB3879: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 006339698F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(376002)(346002)(366004)(39850400004)(396003)(199004)(189003)(186003)(9686003)(55016002)(6916009)(14454004)(99286004)(46003)(305945005)(2906002)(71190400001)(6436002)(53936002)(66476007)(476003)(11346002)(66946007)(73956011)(86362001)(66556008)(66446008)(786003)(486006)(64756008)(76116006)(446003)(316002)(229853002)(74316002)(8936002)(6506007)(52536014)(74482002)(478600001)(8676002)(102836004)(81166006)(4326008)(33656002)(81156014)(71200400001)(14444005)(256004)(68736007)(25786009)(6246003)(1411001)(7696005)(5660300002)(76176011)(21314003); DIR:OUT; SFP:1101; SCL:1; SRVR:YQXPR01MB3879; H:YQXPR01MB3128.CANPRD01.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: uoguelph.ca does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: q4p5PPVsQmdVUEccufz+YKiwwaoyGMyOcbsAItRt4NMxcwzNyxVncln7tmzXhXKxFY6+4jX9d8km8VIBrpvQTeafor+JOTbgb9uYgkLIhm++Kf2A1NtPdCaqVGGQQzwfyTOJUiUbQP25+hXLiTzfUSLBQIEB+G+c0EN01nMylErZdy++86ubtM281Ll7CPA6JgRFXSX7/hpyCrRU1S1CZbMczI9r9CmpGxv+086jx1PjXv01LqVTuMOrKPqrhBtPfshlZo9dzW6+TkT62NJMeLMVnmyWYSBktkIXDdhQhTzhwVzvQh5TTXkUB79FjFspQcqhMhbSbPdzWMFOWYWsrMPeMR2RvcxYGMjuui1sksGzAP8m9VtFwThCUhaEHvqJa3mqWuMpMlQSsl1SkBXjebzCasJSMx8qGLdqpGxUfkU= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: uoguelph.ca X-MS-Exchange-CrossTenant-Network-Message-Id: 5097e902-840c-4726-82c1-08d6eca18596 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Jun 2019 06:12:59.3377 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: be62a12b-2cad-49a1-a5fa-85f4f3156a7d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rmacklem@uoguelph.ca X-MS-Exchange-Transport-CrossTenantHeadersStamped: YQXPR01MB3879 X-Rspamd-Queue-Id: F12EF8B03E 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_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[]; NEURAL_HAM_SHORT(-0.97)[-0.974,0] 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: Sun, 09 Jun 2019 06:13:02 -0000 Konstantin Belousov wrote: >On Sat, Jun 08, 2019 at 02:57:27AM +0000, Rick Macklem wrote: >> Hi, >> First off, thanks Kostik for the fine explanation. I agree with Oliver that= it should be captured somewhere like the wiki. I'm no wiki guy, so hopefully someone = else will do this? >> 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 automagical= ly, 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. I could only find a Symbol.map in src/lib/libc/sys. I added it there and it= seems to work. (I am using a stable/12 source tree for testing the build/userland. I= 'll check head in case it has moved.) >'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: Yes, I don't think I need the above. >- Add the syscall to sys/kern/syscalls.master, and if reasonable, > to sys/compat/freebsd32/syscalls.master. I don't think a 32bit binary on a 64bit system needs this for now. (At least that's my understanding of what this is used for?) >- 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). It uses open fds, but I think I'll leave it out of capabilities.conf for no= w. If there is a need, someone more familiar with capsicum can check it. >- Add syscall prototype to the user-visible portion of header, > hiding it under the proper visibility check. Hmm, not quite sure what you mean here. It ends up in sys/sysproto.h automagically. Does it need to go somewhere else too? >- Add syscall symbol to lib/libc/sys/Symbol.ver. All I found was lib/libc/sys/Symbol.map and I've added it there. >- 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 implementatio= ns > of host-native and compat32 sys_YOURSYSCALL() should be just > decoding of uap members and call into kern_YOURSYSCALL. I think it might be useful for the Linuxolator, since it is meant to be Lin= ux compatible, so I've done this. > - Consider the need to add auditing for new syscall. This one I need to look at more closely. I may end up posting to the list w.r.t. what to do about this. I think I'll leave it out of the first draft = for phabricator. >- Add man page for the syscall, at lib/libc/sys/YOURSYSCALL.2, and connect > it to the build in lib/libc/sys/Makefile.inc. Yea, I know I have to write a man page. Maybe get to that tomorrow. >- 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. Righto, I'll do this when it gets to that stage. Thanks again for the useful answer, rick