Losing the magic
lwn.net
lwn.net
In most, maybe almost all of the places in the kernel, probably. If you get down to the very low-level nitty gritty: Bootstrapping code, low level memory management, exception handling, maybe context switching... expect to look at hex dumps a lot, possibly even directly through a hardware debugging interface that does not even know what debugging symbols are, let alone what "C code" looks like, and experience the joy the recognition of a magic number brings. Did Santa bring you saved state from an exception handler early this year?
But the article, or the patch, are not wrong, far from it. You are most likely not in that situation while debugging terminal code, as the original magic number file states as example.
You have this raw binary dump of the content of something - generally memory or network flow - and tools which can help you turn the binary dump into a structured view. The issue is mapping the structures onto the dump.
That’s where magic values and known values are useful. You can find them in the middle of the apparent garbage and use them to align your decoder (or to start reading the dump - if you do it often enough it becomes very Matrix like, “blonde, brunette” but with ip packets and C structs).
...But it's also familiar even to little ole me the neophyte, essentially the opposite of a class of 1978 greybeard, from good old Cheat Engine save file manipulation.
Just funny how times change.
Even some of the zoomers will know exactly what you're talking about because of Cheat Engine.
I remember changing my character to a wyvern model and I gave myself a fireball spell, and pretended there was a dragon in my party.
Good times…
I used to work on a medium-model kernel back in the 8086 days. When somebody brought me a crash-dump to look at, one process I'd use is to just page through the kernel data segment, watching the hex go by and relaxing my mind.
As often as not I'd see the corrupt data go by. A string copied where no strings should be. A zero in a dense table that should not have any zeroes. A block duplicated.
Whatever it was, your brain can pattern match way more than we imagine it can.
In things like exception handling and bootstrapping code, there's often not much a tool that decodes structures would give you that you don't see with your own eyes and thoughts anyway. That is very different from debugging, say, networking code.
At one job I used to spend a lot of time looking at crash dumps from a game, and at some point I was able to pretty reliably identify various objects in the engine (models, textures, physics volumes..etc) just from how they looked in a hex view of the crash dumps.
If its a system you're familiar with enough, it really is Matrix-like as you say.
DOCINFO doc;
memset(&doc, 0, sizeof(doc));
doc.cbSize = sizeof(DOCINFO);I'd be interested in specific examples of some ways that type safety has been improved. Or does the author say that there is less of a need for the kind of "type safety" that magic numbers provide because problems will be caught in other ways - by more generic kernel code? If so I'd still be interested in some examples.
Example: https://lwn.net/Articles/750306/
It is literally like the word literally often being used to mean figuratively these days, as in this example…
I shall steal that pithy quote for future use!
Literally it means literally. Figuratively it means very.
It never means figuratively.
"Literally" has been routinely used to mean "figuratively" for over a century. It's definitely not a recent change in usage.
E.g. something like "Safety Feature Quietly Being Removed from Linux Kernel"
There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson.
... quote via https://github.com/globalcitizen/taoup
proc mkFooBarRecord {foo bar} {
# Keep index #0 for a "type" for easier debugging
return [list "fooBarRecord" $foo $bar]
}
proc getFoo {fooBarRecord} {
if {[lindex $fooBarRecord 0] ne "fooBarRecord"} {error "not fooBarRecord"}
return [lindex $fooBarRecord 1]
}
The magic number is sort of like the "0" index of the "Type" field with dicts. field.The use of magic numbers in Linux kernel code is declining. Magic numbers are specific constant values placed within a structure to identify the type of that structure. In-kernel debugging code can check the magic number and raise an alarm if the expected value is not found, thus detecting problems related to type confusion or data corruption. Magic numbers were originally used in the filesystem code to identify the superblock in the disk image, but later grew in use in other areas of the kernel. However, in recent years their use has declined and this patch set from Ahelenia Ziemiańska may be an indication that the reign of magic numbers may be coming to an end.