December 02, 2021
On Thursday, 2 December 2021 at 20:36:46 UTC, Greg Strong wrote:
> On Thursday, 2 December 2021 at 17:36:18 UTC, H. S. Teoh wrote:
>> The solution is very simple: extern(C), extern(C++), and extern anything
>> except extern(D) really, should be @system, and extern(D) (the default)
>> should be @safe.
>>
>> The real issue is convincing Walter to accept this.
>
> Yes - this seems like the most reasonable solution to me.  I don't see why it would be particularly controversial.

The last time this came up, Walter's argument against it was (iirc) that having two separate defaults for different kinds of functions is much worse for usability than having one universal default.

It's worth keeping in mind that extern(C) does not necessarily mean "written in C". So applying this rule as written would lead to some rather confusing edge cases; for example:

    import std.stdio;

    extern(C) void sayHello() // @system by default
    {
        writeln("Hello!");
    }

    void main() // @safe by default
    {
        sayHello();
        // Error: @safe function `main` cannot call @system function `sayHello`
    }
December 02, 2021
On Thu, Dec 02, 2021 at 08:36:46PM +0000, Greg Strong via Digitalmars-d wrote:
> On Thursday, 2 December 2021 at 17:36:18 UTC, H. S. Teoh wrote:
> > The solution is very simple: extern(C), extern(C++), and extern
> > anything except extern(D) really, should be @system, and extern(D)
> > (the default) should be @safe.
> > 
> > The real issue is convincing Walter to accept this.
> 
> Yes - this seems like the most reasonable solution to me.  I don't see why it would be particularly controversial.

In my mind, it's crystal clear.  But Walter refused to do it for whatever reason.  IIRC, he was the only person who rejected this.


T

-- 
In a world without fences, who needs Windows and Gates? -- Christian Surchi
December 02, 2021

On Thursday, 2 December 2021 at 12:15:38 UTC, Johan wrote:

>

On Thursday, 2 December 2021 at 11:01:07 UTC, Imperatorn wrote:

>

On Thursday, 2 December 2021 at 08:09:18 UTC, Paulo Pinto wrote:

>

[...]

Bottom line:
Use D instead of C 😎

Sorry to rain on the party here, but D is of course not at all immune to this problem.
It was not hard to find out-of-bounds memory access in the D compiler, using the fuzz techniques mentioned in the article.

https://johanengelen.github.io/ldc/2018/01/14/Fuzzing-with-LDC.html
https://github.com/dlang/dmd/pull/7050

Note the discussion of bounds checking in the PR...

-Johan

Agreed, it was more of a "C sux" comment (I use it at work = have seen the horrors).
Anyway, D is still better than C 😊

December 03, 2021
On Thursday, 2 December 2021 at 17:43:44 UTC, H. S. Teoh wrote:
> On Thu, Dec 02, 2021 at 11:44:28AM +0000, IGotD- via Digitalmars-d wrote:
>> On Thursday, 2 December 2021 at 11:27:01 UTC, H. S. Teoh wrote:
>> > 
>> > Another nail in the coffin of C.  Still many more nails to go, but the inevitable draws ever nearer.
> [...]
>> Would it be impossible to add bounds checking in C?
>> 
>> It's been over 4 decades and it seems like there is some profound resistance to add this.
>
> C wouldn't be C anymore once it has bounds checking.  You can bet your life that the moment somebody proposes such a thing, complaints about "efficiency" will flare up all over the intarweb.  99% of the C userbase will revolt, and the proposal will be DOA.
>
> Not to mention, how *do* you add bounds checking to a language where arrays automatically and implicitly decay to pointers?  No length information is present for you to do bounds checking on. The only way to fix this is to reengineer the language from scratch to introduce bounds-checked arrays.  But that does not fix the problems with the existing standard C libraries which take bare pointers for arrays. *Replacing* current arrays with bounds-checked ones essentially turns it into D, at which point it's not C anymore (see previous paragraph).
>
>
> T

You add it to the hardware, where every memory reference becomes a fat pointer, hence C Machines, so Lisp Machines with memory tagging, just designed for C instead.

That is how SPARC ADI, ARM MTE work.

Intel borked their MPX execution, so who knows if they will come up with something up, given that iOS and Android are now making use of hardware memory tagging.
December 03, 2021

On Thursday, 2 December 2021 at 19:35:25 UTC, bachmeier wrote:

>

On Thursday, 2 December 2021 at 17:21:58 UTC, Tejas wrote:

>

On Thursday, 2 December 2021 at 17:11:09 UTC, Paul Backus wrote:

>

[...]

Hmm... not a fan of that solution

Still feel marking extern (C) stuff as @trusted is better.

Introducing a new feature for such a fundamental, yet obvious thing seems overkill, IMHO. Forcing not @safe stuff to be annotated seems better to me.

Sure, if you don't use extern(C) much and you don't care about everyone that uses it extensively in their code moving to other languages, go ahead and do that. It's not realistic to break that much code written in a language that was designed from the start to be closely tied to C. It wouldn't be hard to add a -safe compilation flag, but apparently nobody's into that, they'd prefer to break code others have written.

I think the problem with adding new compiler flags is that it doubles the amount of configs that have to be checked/tested for from then on-wards (at least that's what I was told when I asked if it was possible to do away with the short/byte implicit conversion to int via a compiler flag).

Rather go with Adam's default(safe) than a new compiler flag, if that's what it'll come down to.

December 03, 2021

On Thursday, 2 December 2021 at 17:21:58 UTC, Tejas wrote:

>

Forcing not @safe stuff to be annotated seems better to me.

Definitely is better. It's how it is done in literally every other langauge.

D is the only one I know that does it opposite, where being unsafe is default.

Ex. Rust and C# are safe by default.

The correct solution in my head for the extern functions is simply being able to mark them trusted.

December 03, 2021

On Thursday, 2 December 2021 at 08:09:18 UTC, Paulo Pinto wrote:

>

Google's Project Zero goes through a memory corruption exploit on Network Security Services, where despite all static analysers, fuzzers and code reviews, it flew under the radar.

https://googleprojectzero.blogspot.com/2021/12/this-shouldnt-have-happened.html

Hence why @safe matters.

That's tame, see Apple's complaint against NSO group. Pegasus was delivered through a buffer overflow vulnerability too.

December 03, 2021

On Friday, 3 December 2021 at 06:56:53 UTC, Paulo Pinto wrote:

>

That is how SPARC ADI, ARM MTE work.

Intel borked their MPX execution, so who knows if they will come up with something up, given that iOS and Android are now making use of hardware memory tagging.

Where did you find info on iOS and Android shipping with memory tagging?

According to the ARM MTE paper it adds 4 bits for every 16 bytes and is probabilistic in nature, so it does not work with large offsets. It also forces 16 byte alignment of objects on the stack.

December 03, 2021

On Friday, 3 December 2021 at 08:45:06 UTC, Ola Fosheim Grøstad wrote:

>

On Friday, 3 December 2021 at 06:56:53 UTC, Paulo Pinto wrote:

>

That is how SPARC ADI, ARM MTE work.

Intel borked their MPX execution, so who knows if they will come up with something up, given that iOS and Android are now making use of hardware memory tagging.

Where did you find info on iOS and Android shipping with memory tagging?

According to the ARM MTE paper it adds 4 bits for every 16 bytes and is probabilistic in nature, so it does not work with large offsets. It also forces 16 byte alignment of objects on the stack.

Read my previous comment, https://forum.dlang.org/post/anyicezeifvbuxurhwkz@forum.dlang.org

On Android's case it is quite recent, only the models with Armv8.5 have it turned on, for older CPUs there is a lightheight version applied to critical components via HWASan.

And on iOS although Project Zero has find some flaws on PAC, they have been fixing those issues.

December 03, 2021

On Friday, 3 December 2021 at 10:04:11 UTC, Paulo Pinto wrote:

>

Read my previous comment, https://forum.dlang.org/post/anyicezeifvbuxurhwkz@forum.dlang.org

Missed that Apple-link, yep, seems like they have it as an option for new devices if you use the right compiler switches.

>

On Android's case it is quite recent, only the models with Armv8.5 have it turned on, for older CPUs there is a lightheight version applied to critical components via HWASan.

And on iOS although Project Zero has find some flaws on PAC, they have been fixing those issues.

It is interesting, although it seems in practice to be limited to object boundaries and won't work with fields? My take on this is that it won't work with arrays embedded in structs if the array is followed by another field?