MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / TaskControlBlock

Method TaskControlBlock

src/task/task_control_block.cpp:131–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131TaskControlBlock::TaskControlBlock(const char* _name, int priority,
132 ThreadEntry entry, void* arg)
133 : name(_name) {
134 // 分配辅助数据
135 aux = new TaskAuxData{};
136 if (!aux) {
137 klog::Err("Failed to allocate TaskAuxData for task {}", name);
138 return;
139 }
140
141 // 设置优先级
142 sched_info.priority = priority;
143 sched_info.base_priority = priority;
144
145 // 分配内核栈
146 kernel_stack = static_cast<uint8_t*>(aligned_alloc(
147 cpu_io::virtual_memory::kPageSize, kDefaultKernelStackSize));
148 if (!kernel_stack) {
149 klog::Err("Failed to allocate kernel stack for task {}", name);
150 return;
151 }
152
153 // 设置 trap_context_ptr 指向内核栈顶预留的位置
154 trap_context_ptr = reinterpret_cast<cpu_io::TrapContext*>(
155 kernel_stack + kDefaultKernelStackSize - sizeof(cpu_io::TrapContext));
156
157 // 设置内核栈顶
158 auto stack_top =
159 reinterpret_cast<uint64_t>(kernel_stack) + kDefaultKernelStackSize;
160
161 // 初始化任务上下文
162 InitTaskContext(&task_context, entry, arg, stack_top);
163
164 fsm.Start();
165}
166
167TaskControlBlock::TaskControlBlock(const char* _name, int priority,
168 uint8_t* elf, int argc, char** argv)

Callers

nothing calls this directly

Calls 5

ErrFunction · 0.85
LoadElfFunction · 0.85
StartMethod · 0.80
aligned_allocFunction · 0.50
InitTaskContextFunction · 0.50

Tested by

no test coverage detected