Play with physical addresses in Linux by
Ciro Santilli 35 Updated 2025-04-18 +Created 1970-01-01
Convert virtual addresses to physical from user space with
/proc/<pid>/pagemap
and from kernel space with virt_to_phys
:Dump all page tables from userspace with
/proc/<pid>/maps
and /proc/<pid>/pagemap
:Read and write physical addresses from userspace with
/dev/mem
:In
v4.2
, look under arch/x86/
:include/asm/pgtable*
include/asm/page*
mm/pgtable*
mm/page*
There seems to be no structs defined to represent the pages, only macros:
include/asm/page_types.h
is specially interesting. Excerpt:#define _PAGE_BIT_PRESENT 0 /* is present */
#define _PAGE_BIT_RW 1 /* writeable */
#define _PAGE_BIT_USER 2 /* userspace addressable */
#define _PAGE_BIT_PWT 3 /* page write through */
When an exception happens, the CPU jumps to an address that the OS had previously registered as the fault handler. This is usually done at boot time by the OS.
This could happen for example due to a programming error:but there are cases where it is not a bug, for example in Linux when:
int *is = malloc(1);
is[2] = 1;
- the program wants to increase its stack.
- the page was swapped to disk.The OS will need to do some work behind the processes back to get the page back into RAM.
The algorithmically minded will have noticed that paging requires associative array (like Java
Map
of Python dict()
) abstract data structure where:The single level paging scheme uses a simple array implementation of the associative array:and in C pseudo-code it looks like this:
- the keys are the array index
- this implementation is very fast in time
- but it is too inefficient in memory
linear_address[0] = physical_address_0
linear_address[1] = physical_address_1
linear_address[2] = physical_address_2
...
linear_address[2^20-1] = physical_address_N
But there another simple associative array implementation that overcomes the memory problem: an (unbalanced) k-ary tree.
Using a K-ary tree instead of an array implementation has the following trade-offs:
In C-pseudo code, a 2-level K-ary tree with and we have the following arrays:
K = 2^10
looks like this:level0[0] = &level1_0[0]
level1_0[0] = physical_address_0_0
level1_0[1] = physical_address_0_1
...
level1_0[2^10-1] = physical_address_0_N
level0[1] = &level1_1[0]
level1_1[0] = physical_address_1_0
level1_1[1] = physical_address_1_1
...
level1_1[2^10-1] = physical_address_1_N
...
level0[N] = &level1_N[0]
level1_N[0] = physical_address_N_0
level1_N[1] = physical_address_N_1
...
level1_N[2^10-1] = physical_address_N_N
and it still contains
2^10 * 2^10 = 2^20
possible keys.K-ary trees can save up a lot of space, because if we only have one key, then we only need the following arrays:
Their crash system does not have an amazing user interface.
Tested on Ubuntu 21.10.
After something crashes, look under
/var/crash
for a crash file, which helps to determine which package to report under on Launchpad.E.g. a file
/var/crash/_usr_sbin_gdm3.0.crash
makes you want to file the bug under gdm at: bugs.launchpad.net/ubuntu/+source/gdm/+filebugThen, while reporting the bug, you want to give the developpers access to that Ubuntu's crash report system has already uploaded the
.crash
file. But you can't publicly upload it because it contains memory dumps and could contain secret information. The way to do it is to look at the ID under:sudo cat /var/crash/_usr_sbin_gdm3.0.uploaded
.crash
for you, so you just have to confirm it and give the ID on the ticket.You can view a list of all your uploaded errors at:and each of those contain a link to:which you yourself cannot see.
xdg-open https://errors.ubuntu.com/user/$(sudo cat /var/lib/whoopsie/whoopsie-id)
https://errors.ubuntu.com/oops/<.uloaded error id>
askubuntu.com/questions/434431/how-can-i-read-a-crash-file-from-var-crash asks how to read the
.crash
files.Running:splits it up into a few files, but does not make any major improvements.
sudo apport-unpack /var/crash/_usr_sbin_gdm3.0.crash /tmp/app
apport-retrace
sudo apt install apport-retrace
sudo chmod 666 /var/crash/_usr_sbin_gdm3.0.crash
apport-retrace -g /var/crash/_usr_sbin_gdm3.0.crash
Tried:but then
echo "deb http://ddebs.ubuntu.com $(lsb_release -cs) main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ddebs.list
echo -e "deb http://ddebs.ubuntu.com $(lsb_release -cs)-updates main restricted universe multiverse\ndeb http://ddebs.ubuntu.com $(lsb_release -cs)-proposed main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ddebs.list
sudo apt install ubuntu-dbgsym-keyring
sudo apt update
fails with:E: The repository 'http://ddebs.ubuntu.com impish-security Release' does not have a Release file.
Bibliography:
- www.slipcue.com/music/brazil/brazillist.html cute site from the 90s
One of the most beautiful things in mathematics are theorems of conjectures that are very simple to state and understand (e.g. for K-12, lower undergrad levels), but extremely hard to prove.
This is in contrast to conjectures in certain areas where you'd have to study for a few months just to precisely understand all the definitions and the interest of the problem statement.
Bibliography:
- mathoverflow.net/questions/75698/examples-of-seemingly-elementary-problems-that-are-hard-to-solve
- www.reddit.com/r/mathematics/comments/klev7b/whats_your_favorite_easy_to_state_and_understand/
- mathoverflow.net/questions/42512/awfully-sophisticated-proof-for-simple-facts this one is for proofs for which simpler proofs exist
- math.stackexchange.com/questions/415365/it-looks-straightforward-but-actually-it-isnt this one is for "there is some reason it looks easy", whatever that means
First Sibling of Special Relativity by
Ciro Santilli 35 Updated 2025-04-18 +Created 1970-01-01
Unlisted articles are being shown, click here to show only listed articles.