From owner-freebsd-hackers@freebsd.org Fri Jul 29 13:53:13 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B5406BA6767 for ; Fri, 29 Jul 2016 13:53:13 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from zxy.spb.ru (zxy.spb.ru [195.70.199.98]) (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 795EC1668 for ; Fri, 29 Jul 2016 13:53:13 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from slw by zxy.spb.ru with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1bT7kd-000NA7-2P; Fri, 29 Jul 2016 16:22:55 +0300 Date: Fri, 29 Jul 2016 16:22:55 +0300 From: Slawa Olhovchenkov To: Adam Starak Cc: freebsd-hackers@freebsd.org Subject: Re: Modify user space from kernel. Message-ID: <20160729132254.GD46309@zxy.spb.ru> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: slw@zxy.spb.ru X-SA-Exim-Scanned: No (on zxy.spb.ru); SAEximRunCond expanded to false X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2016 13:53:13 -0000 On Fri, Jul 29, 2016 at 03:11:25PM +0200, Adam Starak wrote: > Hello! > > My name is Adam. I participate in Google Summer of Code this year. I came > up with a big problem, which doesn't allow me to go further in my project. > > I made a new syscall, which is going to retrieve sysctl data and put it > inside the nvlist. And here my problem is. I need to move somehow this data > (packed nvlist) into the user space. Is there any chance to pass data from > kernel to user space without knowing the size of it? > > Right now, the implementation of __sysctl() function requests void pointer > and size in order to get data. If allocated memory is too low, it returns > ENOMEM and you need to realloc the data. I wanted to avoid this situation. char *intrname; size_t inamlen; sysctlbyname("hw.intrnames", NULL, &inamlen, NULL, 0); intrname = malloc(inamlen); sysctlbyname("hw.intrnames", intrname, &inamlen, NULL, 0); NB: check error!