linux release函数,linux file_operation 结构中的release 能不能保证与其他函数没

针对同一个 filep, 会不会其他调用比如 ioctl 正在调用过程中, 另一个线程调用了 close,  从而导致在 compat_ioctl, unlocked_ioctl 什么的还没有完成, release 已经进去了?

android binder驱动里面就有这么几个情景:

在release 中

while ((n = rb_first(&proc->threads))) {

struct binder_thread *thread;

thread = rb_entry(n, struct binder_thread, rb_node);

binder_inner_proc_unlock(proc);

threads++;

active_transactions += binder_thread_release(proc, thread);

binder_inner_proc_lock(proc);

}

这过这个thread 在 binder_inner_proc_unlock 前引用计数没自增, 而是在 binder_thread_release 中有 自增->完成操作->自减, 到0 free的逻辑

另外一边:

ioctl 中有

thread = binder_get_thread(proc);

case BINDER_THREAD_EXIT:

binder_debug(BINDER_DEBUG_THREADS, "%d:%d exit\n",

proc->pid, thread->pid);

binder_thread_release(proc, thread);

thread = NULL;

break;

binder_get_thread 同样没有 +1 操作

那么. 我就有理由相信两者发生了竞争

导致一个野指针问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`skb_release` 函数Linux 内核用来释放 `skb` 数据结构(网络数据包缓冲区)的函数。它的定义在文件 `net/core/skbuff.c` 。 下面是 `skb_release` 函数的代码及注释: ```c void skb_release(struct sk_buff *skb) { struct nf_hook_state state; unsigned int i; /* Call the packet destroy function for nf_hooks */ if (unlikely(nf_hooks_needed(skb))) nf_hook_state_init(&state, NFPROTO_UNSPEC, NF_HOOK_INVALID, NULL, skb, NULL, dev_net(skb->dev), 0); for (i = 0; i < NFPROTO_NUMPROTO; i++) nf_hook(NFPROTO(i), NF_INET_PRE_ROUTING, &state, skb, skb->dev, NULL, skb_dst(skb)->dev, NULL, skb->protocol); /* Call the destructor for each extension header. */ for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { if (skb_shinfo(skb)->frags[i].page) kmap_atomic(skb_shinfo(skb)->frags[i].page); if (skb_shinfo(skb)->destructor[i]) skb_shinfo(skb)->destructor[i](skb); if (skb_shinfo(skb)->frags[i].page) kunmap_atomic(skb_shinfo(skb)->frags[i].page); } if (skb_shinfo(skb)->frag_list) kfree_skb_list(skb_shinfo(skb)->frag_list); /* Release the skb itself */ kmem_cache_free(skbuff_head_cache, skb); } ``` 该函数的作用是释放 `skb` 数据结构,它的主要步骤包括: 1. 如果 `skb` 上注册了网络钩子(`nf_hook`),则依次调用每个网络钩子的销毁函数(`nf_hook` 函数的第 4 个参数)。 2. 对于 `skb` 的每个扩展头,调用其析构函数(`destructor`)进行清理,以释放扩展头占用的内存。 3. 如果 `skb` 存在分段数据(`frag_list`),则释放分段数据占用的内存。 4. 最后,释放 `skb` 本身占用的内存。 需要注意的是,该函数只是释放 `skb` 数据结构本身占用的内存,但并不会释放 `skb` 引用的其他内存(例如数据包的内容、关联的网络设备等)。这些内存的释放由其他函数负责。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值