To add a new field to user_struct , you need to do 3 things:
The definition of user_struct is in the sched.h file (include / linux / sched.h)
You must add your field to the struct .
struct user_struct { atomic_t ready_processes; };
In the line user.c (kernel / user.c) 51, user_struct is created globally for root_user . Give your field a value here.
struct user_struct root_user = { .ready_processes = ATOMIC_INIT(1), .__count = ATOMIC_INIT(2), .processes = ATOMIC_INIT(1), .files = ATOMIC_INIT(0), .sigpending = ATOMIC_INIT(0), .locked_shm = 0, .user_ns = &init_user_ns, };
You have finished initializing your field for the root user, but you must also initialize it for other users.
For this purpose, in user.c, navigate to the alloc_uid function, where new users get allocated and initialized. For example, you see there the string atomic_set(&new->__count, 1); which initializes __count . Add to this the initialization code.
atomic_set(&new->__count, 1); atomic_set(&new->ready_processes, 1);
NOTE. It works on Linux 2.6.32.62. I am not sure about the other versions, but I think that it should not be completely different.
Ali Seyedi
source share