在kernel模块里面创建链表_内核模块中简单的插入链表_蓝牙先生的博客-CSDN博客使用QEMU搭建ARM64实验环境_蓝牙先生的博客-CSDN博客#1.toolchainwget -c https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xztar xfv gcc-arm-8.2-2018.11-x86_64-arm-eabi.tar.xzexport PAThttps://blog.csdn.net/m0_37132481/article/details/123547874?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167930402216800213099511%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=167930402216800213099511&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-3-123547874-null-null.blog_rank_default&utm_term=%E9%93%BE&spm=1018.2226.3001.4450环境
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
list.h
$ cat list.h #if ! defined(__LIST__) #define __LIST__ #include
struct list_head {struct list_head *next, *prev; }; #define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD(name) \struct list_head name = LIST_HEAD_INIT(name)#ifndef container_of #define container_of(ptr, type, member) \(type *)((char *)(ptr) - (char *) &((type *)0)->member) #endif #define __container_of(ptr, sample, member) \(void *)container_of((ptr), typeof(*(sample)), member)#define list_entry(ptr, type, member) \container_of(ptr, type, member)/****************************init******************************/ static inline void __list_add(struct list_head *entry,struct list_head *prev, struct list_head *next) {next->prev = entry;entry->next = next;entry->prev = prev;prev->next = entry; } /****************************add******************************/ static inline void list_add(struct list_head *entry, struct list_head *head) {__list_add(entry, head, head->next); } static inline void list_add_tail(struct list_head *entry, struct list_head *head) {__list_add(entry, head->prev, head); } /****************************delete******************************/ static inline void __list_del(struct list_head *prev, struct list_head *next) {next->prev = prev;prev->next = next; } static inline void list_del(struct list_head *entry) {__list_del(entry->prev, entry->next); } /****************************empty******************************/ static inline bool list_empty(struct list_head *head) {return head->next == head; } /****************************tranverse******************************/ #define list_for_each_entry_safe(pos, tmp, head, member) \for (pos = __container_of((head)->next, pos, member), \tmp = __container_of(pos->member.next, pos, member); \&pos->member != (head); \pos = tmp, tmp = __container_of(pos->member.next, tmp, member))#define list_for_each_entry(pos, head, member) \for (pos = __container_of((head)->next, pos, member); \&pos->member != (head); \pos = __container_of(pos->member.next, pos, member)) #endif
main.c
$ cat main.c
/*file name:main.cdate : Mon Mar 20 04:34:40 AM EDT 2023
*/
#include
#include
#include
#include
#include
#include
#include #include "list.h"struct demo_data_t {int data;struct list_head node;
};
int main(int argc, char *argv[])
{LIST_HEAD(list_handle);for(int loop = 0; ; loop++) {/*****************************add**********************************************/for(int i = 0; i < 10; i++) {struct demo_data_t *entry = calloc(1, sizeof(struct demo_data_t) * 1024 * 1024);entry->data = i;list_add_tail(&entry->node, &list_handle);}/*****************************tranverse**********************************************/struct demo_data_t *pos = NULL, *tmp = NULL;list_for_each_entry_safe(pos, tmp, &list_handle, node) {printf("%d ", pos->data);list_del(&pos->node);free(pos);}printf("\n");}return 0;
}
经常遇到需要使用链表、丢列、栈数据结构问题,备份一下,免得每次都去查找;方便下次快速使用;
<完>
上一篇: 公函的涵义和用途