Skip to content

Commit

Permalink
linux: handle UNAME26 personality (libuv#4109)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis authored Jul 31, 2023
1 parent 55376b0 commit 30c3ef9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/unix/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,31 @@ unsigned uv__kernel_version(void) {
if (3 != sscanf(u.release, "%u.%u.%u", &major, &minor, &patch))
return 0;

/* Handle it when the process runs under the UNAME26 personality:
*
* - kernels >= 3.x identify as 2.6.40+x
* - kernels >= 4.x identify as 2.6.60+x
*
* UNAME26 is a poorly conceived hack that doesn't let us distinguish
* between 4.x kernels and 5.x/6.x kernels so we conservatively assume
* that 2.6.60+x means 4.x.
*
* Fun fact of the day: it's technically possible to observe the actual
* kernel version for a brief moment because uname() first copies out the
* real release string before overwriting it with the backcompat string.
*/
if (major == 2 && minor == 6) {
if (patch >= 60) {
major = 4;
minor = patch - 60;
patch = 0;
} else if (patch >= 40) {
major = 3;
minor = patch - 40;
patch = 0;
}
}

version = major * 65536 + minor * 256 + patch;
atomic_store_explicit(&cached_version, version, memory_order_relaxed);

Expand Down

0 comments on commit 30c3ef9

Please sign in to comment.