登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
Gitee AI
NEW
我知道了
查看详情
登录
注册
1月18日,北京,聊聊2025如何加入技术开发?
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
1
Star
2
Fork
16
TenonOS-EDU
/
Advanced Operating Systems Course
代码
Issues
0
Pull Requests
1
Wiki
统计
流水线
服务
Gitee Pages
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
我知道了,不再自动展开
更新失败,请稍后重试!
Issues
/
详情
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
考核1:代码纠错
已完成
#IAYE2C
kangy_g
成员
创建于
2024-10-20 19:28
### 问题 找出代码片段中的2处问题并改正 ``` static void bbuddy_pfree(struct uk_alloc *a, void *obj, unsigned long num_pages) { struct uk_bbpalloc *b; chunk_head_t *freed_ch, *to_merge_ch; chunk_tail_t *freed_ct; unsigned long mask; UK_ASSERT(a != NULL); uk_alloc_stats_count_pfree(a, obj, num_pages); b = (struct uk_bbpalloc *)&a->priv; freelist_sanitycheck(b->free_head); size_t order = (size_t)num_pages_to_order(num_pages); /* if the object is not page aligned it was clearly not from us */ UK_ASSERT((((uintptr_t)obj) & (__PAGE_SIZE - 1)) == 0); /* First free the chunk */ map_free(b, (uintptr_t)obj, 1UL << order); #if 0 /* Create free chunk */ freed_ch = (chunk_head_t *)obj; freed_ct = (chunk_tail_t *)((char *)obj + (1UL << (order + __PAGE_SHIFT))) - 1; /* Now, possibly we can conseal chunks together */ while (order < FREELIST_SIZE) { mask = 1UL << (order + __PAGE_SHIFT); if ((unsigned long)freed_ch & mask) { to_merge_ch = (chunk_head_t *)((char *)freed_ch - mask); if (allocated_in_map(b, (uintptr_t)to_merge_ch) || to_merge_ch->level != order) break; /* Merge with predecessor */ freed_ch = to_merge_ch; } else { to_merge_ch = (chunk_head_t *)((char *)freed_ch + mask); if (allocated_in_map(b, (uintptr_t)to_merge_ch) || to_merge_ch->level != order) break; /* Merge with successor */ freed_ct = (chunk_tail_t *)((char *)to_merge_ch + mask) - 1; } /* We are commited to merging, unlink the chunk */ *(to_merge_ch->pprev) = to_merge_ch->next; to_merge_ch->next->pprev = to_merge_ch->pprev; order++; } /* Link the new chunk */ freed_ch->level = order; freed_ch->next = b->free_head[order]; freed_ch->pprev = &b->free_head[order]; freed_ct->level = order; freed_ch->next->pprev = &freed_ch->next; b->free_head[order] = freed_ch; #else int nr_page_left = 1UL << order; while(nr_page_left) { freed_ch = (chunk_head_t *)obj; freed_ct = (chunk_tail_t *)((char *)obj + (1UL << __PAGE_SHIFT)) - 1; freed_ch->level = 0; freed_ch->next = b->free_head[0]; freed_ch->pprev = &b->free_head[0]; freed_ct->level = 0; freed_ch->next->pprev = &freed_ch->next; b->free_head[0] = freed_ch; nr_page_left--; obj = (char *) freed_ct + 1; } #endif freelist_sanitycheck(b->free_head); uk_bbpalloc_dump_freelist(); } ``` ### 提交内容 * 1 Markdown文档**简洁**、准确地说明问题 * 2 修改后的代码片段,保存为一个文件foo.c,不要有多余内容
### 问题 找出代码片段中的2处问题并改正 ``` static void bbuddy_pfree(struct uk_alloc *a, void *obj, unsigned long num_pages) { struct uk_bbpalloc *b; chunk_head_t *freed_ch, *to_merge_ch; chunk_tail_t *freed_ct; unsigned long mask; UK_ASSERT(a != NULL); uk_alloc_stats_count_pfree(a, obj, num_pages); b = (struct uk_bbpalloc *)&a->priv; freelist_sanitycheck(b->free_head); size_t order = (size_t)num_pages_to_order(num_pages); /* if the object is not page aligned it was clearly not from us */ UK_ASSERT((((uintptr_t)obj) & (__PAGE_SIZE - 1)) == 0); /* First free the chunk */ map_free(b, (uintptr_t)obj, 1UL << order); #if 0 /* Create free chunk */ freed_ch = (chunk_head_t *)obj; freed_ct = (chunk_tail_t *)((char *)obj + (1UL << (order + __PAGE_SHIFT))) - 1; /* Now, possibly we can conseal chunks together */ while (order < FREELIST_SIZE) { mask = 1UL << (order + __PAGE_SHIFT); if ((unsigned long)freed_ch & mask) { to_merge_ch = (chunk_head_t *)((char *)freed_ch - mask); if (allocated_in_map(b, (uintptr_t)to_merge_ch) || to_merge_ch->level != order) break; /* Merge with predecessor */ freed_ch = to_merge_ch; } else { to_merge_ch = (chunk_head_t *)((char *)freed_ch + mask); if (allocated_in_map(b, (uintptr_t)to_merge_ch) || to_merge_ch->level != order) break; /* Merge with successor */ freed_ct = (chunk_tail_t *)((char *)to_merge_ch + mask) - 1; } /* We are commited to merging, unlink the chunk */ *(to_merge_ch->pprev) = to_merge_ch->next; to_merge_ch->next->pprev = to_merge_ch->pprev; order++; } /* Link the new chunk */ freed_ch->level = order; freed_ch->next = b->free_head[order]; freed_ch->pprev = &b->free_head[order]; freed_ct->level = order; freed_ch->next->pprev = &freed_ch->next; b->free_head[order] = freed_ch; #else int nr_page_left = 1UL << order; while(nr_page_left) { freed_ch = (chunk_head_t *)obj; freed_ct = (chunk_tail_t *)((char *)obj + (1UL << __PAGE_SHIFT)) - 1; freed_ch->level = 0; freed_ch->next = b->free_head[0]; freed_ch->pprev = &b->free_head[0]; freed_ct->level = 0; freed_ch->next->pprev = &freed_ch->next; b->free_head[0] = freed_ch; nr_page_left--; obj = (char *) freed_ct + 1; } #endif freelist_sanitycheck(b->free_head); uk_bbpalloc_dump_freelist(); } ``` ### 提交内容 * 1 Markdown文档**简洁**、准确地说明问题 * 2 修改后的代码片段,保存为一个文件foo.c,不要有多余内容
评论 (
0
)
kangy_g
创建了
任务
许祝愿
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !1
许祝愿
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !2
丁永誉
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !3
刘赛
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !4
李浩德
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !5
王祖鑫
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !7
马青宇
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !6
Liuyanxue
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !11
许祝愿
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !20
Liuyanxue
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !30
Liuyanxue
关联了
TenonOS-EDU/Advanced Operating Systems Course Pull Request !31
Liuyanxue
通过合并
Pull Request !31: 22451054刘艳雪 考核1、2、3
将
任务状态
从
待办的
修改为
已完成
展开全部操作日志
折叠全部操作日志
登录
后才可以发表评论
状态
已完成
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
未关联
main
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
1
https://gitee.com/tenon-os-edu/advanced-operating-systems-course.git
[email protected]
:tenon-os-edu/advanced-operating-systems-course.git
tenon-os-edu
advanced-operating-systems-course
Advanced Operating Systems Course
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册