Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux kernel container

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use the Linux kernel container". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to use the Linux kernel container.

File: include/linux/kernel.h, defined as follows:

/ * * container_of-cast a member of a structure out to the containing structure * @ ptr: the pointer to the member. * @ type: the type of the container struct this is embedded in. * @ member: the name of the member within the struct. * * / # define container_of (ptr, type,member) ({\ const typeof (type *) 0)-> member) * _ mptr = (ptr);\ (type *) ((char *) _ mptr-offsetof (type,member));}) # define offsetof (TYPE, MEMBER) ((size_t) & (TYPE *) 0)-> MEMBER) 1. Function

Function: obtain the address of the container structure member according to the pointer ptr of the member type in the structure type.

Second, parameters

1) ptr: pointer to structure member member

2) type: container structure type

3) member: a member in a structure

III. Explanation

1) typeof: gets the data type of the member member

2) (type *) 0: 0 pointer that defines the type of type structure

3) typeof (type *) 0)-> member) * _ _ mptr: that is, the pointer _ _ mptr that defines the member type

4) offsetof (type,member): calculates the offset of the member member

5) (type *): defines the structure type pointer

The illustration is as follows:

IV. Examples

File: drivers/gpu/drm/rockchip/rockchip_drm_vop.c

# # 1. Define the structure vopstruct vop {struct drm_crtc crtc;...}; # # 2. Using container_of (), obtain the vop address # define to_vop (x) container_of (x, struct vop, crtc) # # 3 through the address x of the member crtc in the structure vop. Initialize the structure vop pointer static int vop_hdr_atomic_check (struct drm_crtc * crtc, struct drm_crtc_state * crtc_state) {struct vop * vop = to_vop (crtc);.} so far, I believe you have a better understanding of "how to use the Linux kernel container". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report