资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Linux内核容器怎么使用

本篇内容主要讲解“Linux内核容器怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux内核容器怎么使用”吧!

创新互联专注于振兴企业网站建设,响应式网站设计,商城网站定制开发。振兴网站建设公司,为振兴等地区提供建站服务。全流程按需求定制开发,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

文件:include/linux/kernel.h,定义如下:

/** * 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)
一、功能

功能:根据结构体type中成员member的指针ptr获取容器结构体type的地址。

二、参数

1)ptr:指向结构体成员member的指针

2)type:容器结构体类型

3)member:结构体中的成员

三、说明

1)typeof:获取成员member的数据类型

2)(type *)0:定义type结构体类型的0指针

3)typeof( ((type *)0)->member ) *__mptr:即定义member类型的指针__mptr

4)offsetof(type,member):计算成员member的偏移量

5)(type *):定义结构体type指针

图解如下:

Linux内核容器怎么使用

四、示例

文件:drivers/gpu/drm/rockchip/rockchip_drm_vop.c

## 1.定义结构体vopstruct vop {    struct drm_crtc crtc;    ...};## 2.使用container_of(),通过结构体vop中成员crtc的地址x,获取vop地址#define to_vop(x) container_of(x, struct vop, crtc)## 3.初始化结构体vop指针static int vop_hdr_atomic_check(struct drm_crtc *crtc,                struct drm_crtc_state *crtc_state){    struct vop *vop = to_vop(crtc);    ...}

到此,相信大家对“Linux内核容器怎么使用”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


当前标题:Linux内核容器怎么使用
网页路径:http://cdkjz.cn/article/jodgjh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220