[英]Passing Address to user space from Kernel space
我正在linux-3.7.6 / kernel / sched / core.c上工作,在schedule()函數中,我必須記錄進程的pid和tgid並向用戶空間顯示記錄的值。 我在存儲tgid和pid的內核空間中使用了全局結構數組,並且在考慮是否可以將數組的地址傳遞給用戶空間,然后在用戶空間訪問tgid和pid的值。
typedef struct process{
int pid;
int tgid;
}p;
p proc[100];
有沒有一種方法可以一次將存儲在結構數組中的所有數據發送到用戶空間? 我之前使用過copy_to_user,但是由於將copy_to_user以塊形式復制數據時如何發送這些整個值集停留在這里? 如果有人能給我指導如何前進,我將不勝感激。 謝謝!
我假設您要在將數組復制到用戶級別時保持原子性。
一種簡單的方法是:
p local_array[100];
preemption_disable(); //disable preemption so you array content will not change,
//because no schedule() can be executed at this time.
memcpy(local_array, array, sizeof(array)); //then we get the consistent snapshot of
//array.
preemption_enable();
copy_to_user(user_buff_ptr, local_array, sizeof(array));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.