HNHacker News
TopNewBestAskShowJobs

abainbridge

1,994 karma · joined October 5, 2012

submissionscomments
abainbridge··on Rust in the Linux Kernel: Just the Beginning
How would Rust fix this? Here's a Rust program that overflows a u8, with no compile error or warning. https://godbolt.org/z/ME3e9KeMe

You can turn on runtime overflow checking with the Rust compiler, but you can do that with gcc compiling C too.

I guess the answer is that you wouldn't do the memcpy like that in idiomatic Rust - you'd use some higher level construct that gives the compiler more chance to catch your errors. Could anyone comment on how this works in a case like this?

edit: Can't reply to repliers. Defined overflow doesn't help here. A checked_add() function could be used in the Linux kernel in C, just as easily as in Rust. Forcing checked_add() to be used in the Rust compiler would help, but would also have performance and readability impact, which is presumably why it is still being debated.

abainbridge··on Debugging C with Cosmopolitan Libc
No. It sounds like Detours works even when the function hasn't got MOV EDI, EDI at the start.
abainbridge··on Debugging C with Cosmopolitan Libc
Oh yeah, sophisticated: https://github.com/microsoft/Detours/wiki/OverviewIntercepti...
abainbridge··on Debugging C with Cosmopolitan Libc
From https://www.microsoft.com/en-us/research/project/detours/

"Detours is a library for instrumenting arbitrary Win32 functions Windows-compatible processors. Detours intercepts Win32 functions by re-writing the in-memory code for target functions."

Doesn't that just re-write the DLL import table? ie it only allows interception of a Win32 API calls, not interception of my function A calling my function B?

abainbridge··on Debugging C with Cosmopolitan Libc
> Cosmopolitan Libc allows you to log every function call over the program’s execution – just pass --ftrace at the end of your program, like this:

> ./hex16.com ./missing.txt --ftrace

That seems like magic. It seems you have to build with a special flag that tells GCC to put a nop at the start of each function. Then, before main runs, Cosmopolitan sees the --ftrace on the command line, and modifies the code in memory to replace those nops with calls to something that does the logging. See https://justine.lol/ftrace/.

abainbridge··on Apple unveils redesigned iPad
Gah.
abainbridge··on Apple unveils redesigned iPad
Here's an Android Tablet with that chip for £99 ($88 at current exchange rate). https://www.laptopsdirect.co.uk/tcl-tab-10s-32gb-10.2-inch-w...
abainbridge··on Intel, SiFive Demo High-Performance RISC-V on Intel 4
Ahhh, that's why MT/s exists. All I need to know now is how many data bits are in a transfer and how many memory channels there are, and I'll be able to calculate how fast the memory interface is.
abainbridge··on Paris Will Become ‘100% Cyclable’
Good question. I'm thinking of morning rush hour because that I did a traffic survey then. I noticed a lot of building trades vehicles. All the trades people seem to want to be at their site for the day by 8.30am. I guess that is so they can do a full day's work before it gets dark (which is at 3.30pm in winter). There is also a lot of food suppliers delivering in time for catering teams to make lunch in schools, offices, cafes etc.

I probably shouldn't have called it rush hour. The traffic is busy from 7am until 7pm on weekdays.

abainbridge··on Paris Will Become ‘100% Cyclable’
Commercial traffic needs to drive - trucks and vans need cannot easily be replaced with public transport. I live on a busy road in Cambridge UK. At rush hour the traffic is about 50% commercial. I don't know what the proportion is in Paris, but my expectation is that the roads would still have lots of motor vehicle traffic even once you convert everything that can be to bike/public transport.
abainbridge··on Real-time internal combustion engine simulation
I'm fascinated by how this works. Does it do any CFD type of simulation of the gas flow in the engine? Is the simulation entirely 2D?

I've thought about doing a similar project myself but would like to be able to simulate the effects of engine tuning techniques such as "porting" of the cylinder head. I think that is quite hard - I don't think a simple incompressible flow CFD simulation would be sufficient. Particularly if you wanted to simulate the pressure waves in a tuned-length-induction system, I'm pretty sure you'd need compressible flow.

I haven't been able to find any suitable tutorials on simulating compressible flow. Most of the teaching material I found starts with vast amounts of pencil and paper maths exercises and assumes graduate level vector calculus. I want something that starts with for loops and a hand waving understanding of the concepts of vector calculus.

I think you could still do something interesting in 2D. I've struggled to find anywhere to discuss such ideas.

abainbridge··on Olive.c: a simple graphics library that does not have any dependencies
Gee thanks. I tried typing olive.c there. That didn't help. The string "tsoding" is the magic I needed.
abainbridge··on Olive.c: a simple graphics library that does not have any dependencies
How can I find them?
abainbridge··on GCC's new fortification level: The gains and costs
From the Zig language reference: Zig has many instances of undefined behavior. If undefined behavior is detected at compile-time, Zig emits a compile error and refuses to continue. Most undefined behavior that cannot be detected at compile-time can be detected at runtime. In these cases, Zig has safety checks. [...] When a safety check fails, Zig crashes with a stack trace
abainbridge··on I like Odin
I agree with all of that. How theoretical are the optimization gains from the extra constraints guaranteed by Rust's borrow checker?
abainbridge··on I like Odin
> Assuming you're thinking of the same thing

Yes.

> are you suggesting that the compiler (or other static analysis) could catch all of the issues you listed?

Yes, the compiler for the first two and the standard library's heap implementation for the third.

> This path leads you to something like Rust

There are stops along this path before you get to Rust. If you just add the 3 things I mention above to a C like language, it would still be perfectly possible to leak memory. But that isn't a safety problem.

The 3 things don't include a borrow checker. You could still make doubly linked list and graph data-structures.

abainbridge··on I like Odin
You can have safe manual memory management. The main cases of bugs are:

1. Null pointer deref. Can be fixed by having optional types and requiring that possibly null pointers have to be wrapped in them.

2. Out of bounds references. Can be fixed by making the type system track how big all objects are, and having the compiler insert bounds checking.

3. Use after free. Can be fixed by the free function zero'ing heap objects smaller than a page (eg 4KB), and unmapping larger ones so that future accesses are a seg fault. The heap also needs to not create new objects at the same address as deleted ones, but we have 64-bit address spaces, so maybe that's fine.

These all have costs, but so do all solutions to these problems.

I can't think of any reasons that a language with manual memory management has to be less safe than one with a Garbage Collector / ARC.

abainbridge··on Things people blamed on bicycles
Agreed. The lesson I take from this is that people/the media love to say X is bad because of Y. If they don't present evidence then we should probably ignore the claim.
abainbridge··on More energy on less land: The drive to shrink solar’s footprint
That seems like an excellent point. Why hasn't this already been done everywhere that gets sunny?
abainbridge··on Dark Matter Doesn't Exist
Except we don't get to invent where they are because you can see normal matter. We tried before to invent some normal matter to explain the orbit of Mercury. https://en.wikipedia.org/wiki/Vulcan_(hypothetical_planet).
abainbridge··on Dark Matter Doesn't Exist
I agree. I find it hard to argue against the claim that all physics is just curve fitting. We always end up with tuned parameters to make the maths work. For example the G in F = Gmm/r^2 (Newtonian mechanics).

I'm not an expert, but it seems like Dark Matter theories allow the DM distribution to be tuned. Is that the case? Can you say, "oh, there must be a clump of DM over here with mass X". If so, that would give you lots of parameters to tune per situation you're modelling. It may be that IS how the universe works. The problem is that the theory is hard to falsify if it has so much wiggle room to fit every situation.

abainbridge··on Capy – Cross-platform library for making native GUIs in Zig
There is no consistent native look/behaviour on Windows. Even a single program (Excel), written by MS themselves, has no consistent style. I think I see 7 different styles in these search results: https://www.google.com/search?q=excel+%22save+changes%22+dia...

Maybe some of those variations are due to running the same Excel on different versions of Windows, and it conforming to what it thinks native looks like on each. It's hard to tell.

If I redo the experiment on my own Windows 10 machine, I see 7 different kinds of save-changes dialogs, from these 7 programs: VS 2013, Notepad++, Paint.NET, Photoshop CS6, TextPad, UltraEdit and WordPad.

Again, this isn't a perfect test because many of those programs are using non-native GUI frameworks. But my point is that as a Windows user, I can't tell what native is, because approximately every program looks different.

abainbridge··on Phrases in computing that might need retiring
> I don’t know of any good replacement…

My Chambers dictionary suggests these alternatives: actually, really, absolutely.

It also says, "literally is in common use to intensify an idiom, and this is not incorrect".

My general rule is that usage defines meaning. If lots of people use literally as an idiom intensifier, then I'd be wrong to argue. However, my GCSE English teacher said that we need to consider the intended audience and form. Me saying, "They literally flew down the road" to my mates in the pub is fine. It is not fine in formal writing.

abainbridge··on Phrases in computing that might need retiring
Sinister used to mean left handed. "A shambles" used to mean a slaughterhouse. Sanction used to mean allow, now it means not allow. It is fine for words to change meaning, even to their own opposite. Natural language has done that forever.

Edit: you're all right, sanction has both meanings.

abainbridge··on Some Thoughts on Zig
I also see that this is a bike-shed issue [1]. It probably isn't as important as some other language issues that are complicated enough that I don't even know about them. However, people's first impression of the language matter, so fixing the bike shed matters.

[1] https://en.wikipedia.org/wiki/Law_of_triviality

abainbridge··on Some Thoughts on Zig
Maybe there is a good reason. I'd just like to know what it is. My guess is that fixing issue 358 with syntactic sugar would mean that the debug info would show scope blocks that don't correspond to {} in the source, and that is annoying.
abainbridge··on Some Thoughts on Zig
I don't understand why fixing issue 358 in the Zig compiler isn't trivial. I don't understand the reluctance. I don't understand why:

    for (var i: usize = a; i < b; i += 1) { foo(); }
    for (var i: usize = a; i < b; i += 1) { bar(); }
Is worse than:

    var i: usize = a;
    while (i < b) : (i += 1) { foo(); }
    while (i < b) : (i += 1) { bar(); }
Which is what happens without the for-loop scoping of the variable. (ie when I cut and pasted, I introduced a logic bug where I forgot to initialize i for the second loop).
abainbridge··on What happened to the lab-leak hypothesis?
I guess it is because the UK stopped doing as much testing. Presumably Google is reporting the number of positive tests (or something) and many people with covid don't bother getting tested any more.

The ONS is still doing random sampling and extrapolating to say how many people in the country are infected. "Around 1.7m people in the UK had coronavirus in the week ending 18 June" - https://www.bbc.co.uk/news/uk-51768274

abainbridge··on EndBASIC
> Drawing modern graphics is not done by blitting pixels onto a framebuffer

That's a choice. The hardware still supports it. It is still possible (and fast-ish and simple) to do graphics by blitting pixels.

abainbridge··on EndBASIC
Having a bitmap in normal system memory that we can write to the window or screen is easy though and should be more widely supported. Once you've got that you can write pixels, lines, rectangles, mandlebrots etc very easily and building up to a GUI toolkit is also quite easy and fun. This mechanism is fast enough for pretty much everything other than games on modern hardware.

I consider GPU acceleration a form of premature optimization - it adds complexity unnecessarily in many cases.

Here's my library for doing that on Windows and X11. https://github.com/abainbridge/deadfrog-lib

← PreviousPage 4 of 18Next →