220 40323 <CAJEeERU+5x5VuPFBTKizOzK-U2AeUZEc9W9-sD508+sPSfK4fg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Andrew Sandoval <sandoval@netwaysglobal.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Runtime code generation and self modifying code
Date: Thu, 4 Oct 2018 23:17:33 -0500
Lines: 143
Approved: news@gmane.org
Message-ID: <CAJEeERU+5x5VuPFBTKizOzK-U2AeUZEc9W9-sD508+sPSfK4fg@mail.gmail.com>
References: <4489f889-977c-45f2-8a2f-186ee3b06bff@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="000000000000b020b30577738d46"
X-Trace: blaine.gmane.org 1538712942 12197 195.159.176.226 (5 Oct 2018 04:15:42 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 5 Oct 2018 04:15:42 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDIZ5RW5Y4IBB2WL3POQKGQETLG727I@isocpp.org Fri Oct 05 06:15:38 2018
Return-path: <std-proposals+bncBDIZ5RW5Y4IBB2WL3POQKGQETLG727I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk1-f200.google.com ([209.85.221.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDIZ5RW5Y4IBB2WL3POQKGQETLG727I@isocpp.org>)
	id 1g8HWb-00035C-CD
	for gclcip-std-proposals@m.gmane.org; Fri, 05 Oct 2018 06:15:37 +0200
Original-Received: by mail-vk1-f200.google.com with SMTP id h81-v6sf2846786vke.13
        for <gclcip-std-proposals@m.gmane.org>; Thu, 04 Oct 2018 21:17:47 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1538713067; cv=pass;
        d=google.com; s=arc-20160816;
        b=q8ee4jgclF52s8M5iR6VQs++VhTMz+JrG5vM72kjw/C5PrYEXE8r0MwbFRmPSg3mBd
         aWGzC1d/IyARKqMn/2rdwBRNWgp2zOBC71GVYAXjTwU088LdcISes0hWdtxSywQ2+2kB
         VYIw31oeYBYDByi+KOIYmknfBbgQNgujapq9QO6av5D+vz/SXq6BFEK8f4xLy6qcyR8M
         AtSUD7WkRG/331BSPWbexup133q6zjTyTRfcsGSxncHSZr8UgWpSdnWstO7L3YmWlHLW
         FfQHUdr8H6fPy9mkDlkZGXiKTWCvEcn3J9hzeYWzScLBFz0BaUaSUn2iJUCN+uhFoeIE
         PqOA==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date
         :from:in-reply-to:references:mime-version:dkim-signature;
        bh=/4Z4TxPXxb+Bd3ttWhqBRB7aYVZaEGdVKYVcZv+XDxc=;
        b=O7GfyHb4SlxLmoHQoWC2Yn1RoBIQxR+FDf+jYc74mNQp53NTSI3i1bKSM8Ks2h8fy8
         E5tKQHUYPtd1gwTyuGLUCZH+8Bmv1R3huRUQjzbj7Mwf07CDHqSOmzMGIF9huNB2FrTl
         3N/AZLH3fBHJg25jx0jjnYMzrEDm1Xvuy4N60CqiTScpFHiNlR1tyFN5zWt1hqnmQEcb
         Q0RHRDf+NTXTqbdc9EapZZmQB0RQWBNiJ+QdzL5+zXzRMUwGC/8RLwyTbbCyfRUfKDxL
         zKbLm0VxEnSTQunDVROsX3F96aQ9RgwZb13XTUfKqmFxUrc1I0ET0ZY79WtAPCgZ9NAA
         6pKw==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@netwaysglobal-com.20150623.gappssmtp.com header.s=20150623 header.b=gFQVvPHu;
       spf=neutral (google.com: 209.85.220.41 is neither permitted nor denied by best guess record for domain of sandoval@netwaysglobal.com) smtp.mailfrom=sandoval@netwaysglobal.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=/4Z4TxPXxb+Bd3ttWhqBRB7aYVZaEGdVKYVcZv+XDxc=;
        b=q6dl1cPOPDGG7ZOaz/cgJtzpWC07u1lqVLGtzdpJUUAxlOCRvda98x2VtBPFTflm37
         a8hvdR9EA6zxF1Y+xgmNazkrtDBm5r8iAkF5o3WtkuC1Nf1eiHgTxqRjHKOuzEq8cpI6
         AGSBGrMOCvoZAc5SfCkwwFWw9lQu+ebsLlQWVXs1DC/ebHqezlhaWJMIhUUDfluw2TsL
         KVlb5x6zimDsmozyvWNVz9a/f8Ann4L5SHU+0SatJDEZVC6ac8JjEyJgQ6jj2oxFgQ/N
         dMrQrlqZcwsAMhIQhHr9no4sb59Dmk0n75JRAe1r3+Pj7l/iHc0FW0XDtH3g3QFrt7wn
         pvYg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=/4Z4TxPXxb+Bd3ttWhqBRB7aYVZaEGdVKYVcZv+XDxc=;
        b=Y25bNbGWvf1C+MxpoVVbSwLQn3hKzBn3tlLbYHBD7Fkb6Vk3iC2ZwcKYs60tyiCIUc
         1arUS+syPV3uAVHgb1qp60r1Kzt1xI6iHKN+ldPaUomNiEQ2JWAiQKte3xGoYmNzLs9l
         3Hco8UKXD06YYYRO53qsZc/p0OuuY3I00ODdpj4cZSsxII3Dsqm0oBNCnEzzh7KV8Hh9
         bcOKbRBEwj9fnyo2sBTTrB4aqeznGp/P/PNYLZMzIsrXIUL/N3UpbfzY/NumOewINW5l
         ESpJfDu1bN/vzmKgfjU/bgMzyzgjDOk6hGP5nizTDSAhuE0qmkcOKyDXhEw2IPH+y8Cm
         QCOg==
X-Gm-Message-State: ABuFfoifwENTCiX1c40o5EHwdc3mkitACqWNhYJyHpeL0fOqKPAbWfxN
	8cN9S8yAuwMuP8jw2lhiiL8=
X-Google-Smtp-Source: ACcGV61xj14Xy9sg2VkrUVfG3ViHlkuPrT0T8M4HmsLjRWIIRs11zFkJ19+MqvLV2CvPopC8TTbQSA==
X-Received: by 2002:ab0:63c7:: with SMTP id i7mr8044326uap.25.1538713067198;
        Thu, 04 Oct 2018 21:17:47 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a67:7681:: with SMTP id r123ls1130531vsc.4.gmail; Thu, 04
 Oct 2018 21:17:46 -0700 (PDT)
X-Received: by 2002:a67:23d1:: with SMTP id j78-v6mr3607861vsj.240.1538713066183;
        Thu, 04 Oct 2018 21:17:46 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1538713066; cv=none;
        d=google.com; s=arc-20160816;
        b=W1kVmgbK5HhZxn74X2Q57Owfjw0SbAWF8QoqT3LaLTaVXQHA0MkgCcvZ9PaaAUwgWj
         VsfR0JOWty+WOqmLsQSL6WVpzzH1TloEyCrXvNRTLAiZKwCzEJ6IhKA79+3nDIrJPrF0
         I8vJrbo5sz7FrsCNO2FFSskx2ICzeDwsMOd2dHDT0Jg97ddI5/+8mjWAHtyDsCLs0zEk
         tKfhGD4zs9iw5zwExrkhQgNDsjIMzCla3kI+933z+4UMFJej+P4LepekAoz6FNmNS0AJ
         L/K8iaWp2UVQUi8fw3dUya4GLtTZRyqS8no3DIbiidcczVPAr1zZtkC9998xR+yJ4wAG
         dbpA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:in-reply-to:references:mime-version
         :dkim-signature;
        bh=qSAzkXXuQZDhwV0pB4CtHvRVdXDzPtIu/EGR9pH52Ts=;
        b=1KleNpy+TDlPyBe5+FVwu4e2Gg8fdYHnFOrQ05ePtKuPm9wwL6fnL3SMndZdNRYqNl
         QXhFwhbrksGWDeR1F7POXgCjdrc3nbOK2ZXsVabfMKA7+lHaXPQ8lo7FIDodCLmpZhD1
         eUcRRzerGv378CwLBmzRy2xXyKre4uiLTs1zFTQEoXV1Eu7iq7dr/QS6nB+sqb8eub+V
         78gz28BKkffNA+Fgd2zetRXKpHlJQpdH+XfOS5OHUVCicI2bCL3qY0P96tBE/feDVDrS
         3dOkMB6aTHgmVRu9hOKsXs4VSvLmoLQ/164k/06kk77CAtSZq1pcc7J2v1GwFGk1KJbI
         hd/Q==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@netwaysglobal-com.20150623.gappssmtp.com header.s=20150623 header.b=gFQVvPHu;
       spf=neutral (google.com: 209.85.220.41 is neither permitted nor denied by best guess record for domain of sandoval@netwaysglobal.com) smtp.mailfrom=sandoval@netwaysglobal.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id u16sor260724ual.3.2018.10.04.21.17.46
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Thu, 04 Oct 2018 21:17:46 -0700 (PDT)
Received-SPF: neutral (google.com: 209.85.220.41 is neither permitted nor denied by best guess record for domain of sandoval@netwaysglobal.com) client-ip=209.85.220.41;
X-Received: by 2002:ab0:502:: with SMTP id 2-v6mr3989127uax.51.1538713065621;
 Thu, 04 Oct 2018 21:17:45 -0700 (PDT)
In-Reply-To: <4489f889-977c-45f2-8a2f-186ee3b06bff@isocpp.org>
X-Original-Sender: sandoval@netwaysglobal.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@netwaysglobal-com.20150623.gappssmtp.com header.s=20150623
 header.b=gFQVvPHu;       spf=neutral (google.com: 209.85.220.41 is neither
 permitted nor denied by best guess record for domain of sandoval@netwaysglobal.com)
 smtp.mailfrom=sandoval@netwaysglobal.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:40323
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40323>

--000000000000b020b30577738d46
Content-Type: text/plain; charset="UTF-8"

Working the security side of this I can tell you emphatically that JIT code
and self-modifying code are two of the worst things ever to be utilized,
especially within Web Browsers, etc.  If we could eliminate JIT engines
altogether we'd eliminate a ton of software vulnerabilities.  Sadly most
JIT engines leak writable, executable memory for extended periods of time.
We finally have compilers that generate checks for stack overflows, etc.,
and we have DEP, only to have it somewhat ruined by JIT'd code, packers,
and self-modifying code, etc.

I'd rather pay the cost of an atomic operation any day compared to the cost
of changing page table entries to make executable memory writable +
executable, and then (hopefully) back to just executable.  Because even
then you still leave a small window open where something can trample your
executable memory, slipping in a call, jmp, or a well placed exception such
as divide-by-zero or a invalid instruction or any other number of abuses.

-Andrew

On Thu, Oct 4, 2018 at 7:35 PM Matthew Fioravante <fmatthew5876@gmail.com>
wrote:

> One big area where dynamic languages are way ahead of C++ is runtime
> dynamic code generation or self modifying code.
>
>
> One tiny example is singleton initialization. The only safe way in C++ to
> do non-constexpr singletons is by lazy init.
>
> The problem with lazy init is that you have to pay for a branch on every
> access, and that usually involves an atomic check.
>
> What if you instead you atomically overwrote the check with NOPS. Then the
> branch is gone and accessing the object is as efficient as if it weren't
> lazy.
>
> Has anyone considered writing proposals for improving runtime code gen
> with C++?
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>


-- 
*Andrew L. Sandoval*
sandoval@netwaysglobal.com

[image: qrcode] <http://mormon.org/me/72HW/>

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJEeERU%2B5x5VuPFBTKizOzK-U2AeUZEc9W9-sD508%2BsPSfK4fg%40mail.gmail.com.

--000000000000b020b30577738d46
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Working the security side of this I can tell you emphatica=
lly that JIT code and self-modifying code are two of the worst things ever =
to be utilized, especially within Web Browsers, etc.=C2=A0 If we could elim=
inate JIT engines altogether we&#39;d eliminate a ton of software vulnerabi=
lities.=C2=A0 Sadly most JIT engines leak writable, executable memory for e=
xtended periods of time.=C2=A0 We finally have compilers that generate chec=
ks for stack overflows, etc., and we have DEP, only to have it somewhat rui=
ned by JIT&#39;d code, packers, and self-modifying code, etc.<div><br></div=
><div>I&#39;d rather pay the cost of an atomic operation any day compared t=
o the cost of changing page table entries to make executable memory writabl=
e + executable, and then (hopefully) back to just executable.=C2=A0 Because=
 even then you still leave a small window open where something can trample =
your executable memory, slipping in a call, jmp, or a well placed exception=
 such as divide-by-zero or a invalid instruction or any other number of abu=
ses.</div><div><br></div><div>-Andrew</div></div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr">On Thu, Oct 4, 2018 at 7:35 PM Matthew Fioravante &lt=
;<a href=3D"mailto:fmatthew5876@gmail.com">fmatthew5876@gmail.com</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>One big=
 area where dynamic languages are way ahead of C++ is runtime dynamic code =
generation or self modifying code.<br></div><div><br></div><div><br></div><=
div>One tiny example is singleton initialization. The only safe way in C++ =
to do non-constexpr singletons is by lazy init. <br></div><div><br></div><d=
iv>The problem with lazy init is that you have to pay for a branch on every=
 access, and that usually involves an atomic check.</div><div><br></div><di=
v>What if you instead you atomically overwrote the check with NOPS. Then th=
e branch is gone and accessing the object is as efficient as if it weren&#3=
9;t lazy.<br></div><div><br></div><div>Has anyone considered writing propos=
als for improving runtime code gen with C++?<br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-45f2-8a2f-186ee3b06bff%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4489f889-977c-=
45f2-8a2f-186ee3b06bff%40isocpp.org</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><font size=3D=
"4"><b style=3D"color:rgb(153,0,0);font-family:comic sans ms,sans-serif">An=
drew L. Sandoval</b></font><br><span style=3D"font-family:courier new,monos=
pace"><a href=3D"mailto:sandoval@netwaysglobal.com" target=3D"_blank">sando=
val@netwaysglobal.com</a></span><br><br><a href=3D"http://mormon.org/me/72H=
W/" target=3D"_blank"><img src=3D"http://qrcode.kaywa.com/img.php?s=3D5&amp=
;d=3Dhttp%3A%2F%2Fmormon.org%2Fme%2F72HW%2F" alt=3D"qrcode" height=3D"62" w=
idth=3D"62"></a><br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAJEeERU%2B5x5VuPFBTKizOzK-U2AeUZEc9W=
9-sD508%2BsPSfK4fg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJEeERU%2B5x=
5VuPFBTKizOzK-U2AeUZEc9W9-sD508%2BsPSfK4fg%40mail.gmail.com</a>.<br />

--000000000000b020b30577738d46--

.
