From owner-freebsd-hackers@freebsd.org Mon Aug 1 14:32:50 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 1C715BAA497 for ; Mon, 1 Aug 2016 14:32:50 +0000 (UTC) (envelope-from christian.mauderer@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (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 CAD531741; Mon, 1 Aug 2016 14:32:49 +0000 (UTC) (envelope-from christian.mauderer@embedded-brains.de) Received: from [88.198.220.131] (helo=sslproxy02.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1bUEGs-0004eH-Sr; Mon, 01 Aug 2016 16:32:46 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bUEGs-0001AZ-LF; Mon, 01 Aug 2016 16:32:46 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 751992A1807; Mon, 1 Aug 2016 16:32:59 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Pl3XidulRvIY; Mon, 1 Aug 2016 16:32:59 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id E85242A180B; Mon, 1 Aug 2016 16:32:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Jsk2zJCEFuTf; Mon, 1 Aug 2016 16:32:58 +0200 (CEST) Received: from mauderer-linux.eb.localhost (unknown [192.168.96.190]) by mail.embedded-brains.de (Postfix) with ESMTPSA id D2F832A1807; Mon, 1 Aug 2016 16:32:58 +0200 (CEST) Subject: Re: Changes to pfctl to allow easier integration into a library To: Kristof Provost References: <25df9fd5-be75-b9ae-aa3a-22abef3bddf0@embedded-brains.de> <0C7EC45D-C3BC-4417-AF77-3ACC027D28B5@FreeBSD.org> Cc: "freebsd-hackers@freebsd.org" From: Christian Mauderer Message-ID: Date: Mon, 1 Aug 2016 16:32:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: <0C7EC45D-C3BC-4417-AF77-3ACC027D28B5@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.99.2/22008/Mon Aug 1 13:12:04 2016) 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: Mon, 01 Aug 2016 14:32:50 -0000 Am 01.08.2016 um 16:02 schrieb Kristof Provost: > On 1 Aug 2016, at 15:03, Christian Mauderer wrote: >> Can I improve anything to make the patches more acceptable? >> > Can you explain why > 0003-pfctl-Pull-static-variables-out-of-the-function.patch is required? > I=E2=80=99m not sure I see why you need it. >=20 >> Is the virtualisation that Bjoern mentioned necessary or was my >> interpretation correct that this is only meant for kernel space code? > I believe your interpretations is correct. > User land code should not have to care about VIMAGE. >=20 > Regards, > Kristof Hello Kristof, I use roughly the following method for the global variables: - I put all initialized (zero or value) variables into a special named linker section. - In a wrapper around main() I do the following: o First save the content of the section to a temporary memory space o Execute the original (mostly unchanged) main() o After main() finishes, I restore the content of the section To simplify a later update to a newer source version, the difference between the sources we use and the original FreeBSD sources should be minimal. Therefore my attempt to put the variables into a section is the following: I create a header file (i.e. pfctl-data.h) that contains a matching declaration of the global variables but with an added gcc attribute __attribute__((__section__("my_section_name"))). This header file is included at the end of the original pfctl.c. Problem is: This method doesn't work for a static variable that is defined inside a function. Therefore I pulled them out of the functions and put them into the scope of the c module. Kind regards Christian Mauderer --=20 -------------------------------------------- embedded brains GmbH Christian Mauderer Dornierstr. 4 D-82178 Puchheim Germany email: christian.mauderer@embedded-brains.de Phone: +49-89-18 94 741 - 18 Fax: +49-89-18 94 741 - 08 PGP: Public key available on request. Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG= .