Skip to content

Fix: task_struct backwards-compatibility with kernel versions < 5.14 (2)#55

Merged
tanelpoder merged 1 commit intotanelpoder:masterfrom
Christoph-Lutz:master
Dec 14, 2024
Merged

Fix: task_struct backwards-compatibility with kernel versions < 5.14 (2)#55
tanelpoder merged 1 commit intotanelpoder:masterfrom
Christoph-Lutz:master

Conversation

@Christoph-Lutz
Copy link

@Christoph-Lutz Christoph-Lutz commented Dec 12, 2024

The state field in task_struct has been renamed to __state in kernel version 5.14.

Due to this change, xcapture-bpf.c fails with the following error on kernel versions < 5.14: /virtual/main.c:178:29: error: no member named '__state' in 'struct task_struct'; did you mean 'state'?

The state field rename has been backported to the RHEL8 4.18 kernels as well, but the fix in #53 / 55f1e30 did not consider this. Therefore, this fix now also includes a macro that checks for RHEL8 like so:

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0) || RHEL_MAJOR >= 8
#define STATE_FIELD __state
#else
#define STATE_FIELD state
#endif
...
t->state = curtask->STATE_FIELD;

The state field in task_struct has been renamed to __state in kernel version 5.14.

Due to this change, xcapture-bpf.c fails with the following error on kernel versions < 5.14:
/virtual/main.c:178:29: error: no member named '__state' in 'struct task_struct'; did you mean 'state'?

The state field rename has been backported to the RHEL8 4.18 kernels as well, but the fix in
tanelpoder#53 / 55f1e30 did not consider this. Therefore, this fix now also includes a macro that checks
for RHEL8 like so:

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0) || RHEL_MAJOR >= 8
#define STATE_FIELD __state
#else
#define STATE_FIELD state
#endif
...
t->state = curtask->STATE_FIELD;
@tanelpoder tanelpoder merged commit 21327e8 into tanelpoder:master Dec 14, 2024
@tanelpoder
Copy link
Owner

Cool, thanks for the change and for using the version check macro too (I noticed that the previous approach errored out on 6.8.0, I think my own original code had that issue too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants