MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / brk

Method brk

source/kernel/kprocess.cpp:1143–1166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1141}
1142
1143U32 KProcess::brk(KThread* thread, U32 address) {
1144 if (address > this->brkEnd) {
1145 U32 len = address-this->brkEnd;
1146 U32 alreadyAllocated = K_ROUND_UP_TO_PAGE(this->brkEnd) - this->brkEnd;
1147
1148 if (len<=alreadyAllocated) {
1149 this->brkEnd+=len;
1150 } else {
1151 U32 aligned = (this->brkEnd+4095) & 0xFFFFF000;
1152 U32 startPage = aligned >> K_PAGE_SHIFT;
1153 U32 stopPage = startPage+((len-alreadyAllocated+K_PAGE_SIZE-1)>>K_PAGE_SHIFT);
1154
1155 for (U32 i=startPage;i<=stopPage;i++) {
1156 if (this->memory->isPageAllocated(i)) {
1157 return -K_ENOMEM;
1158 }
1159 }
1160 if (memory->mmap(thread, aligned, len - alreadyAllocated, K_PROT_READ | K_PROT_WRITE | K_PROT_EXEC, K_MAP_PRIVATE | K_MAP_ANONYMOUS | K_MAP_FIXED_NOREPLACE, -1, 0)==aligned) {
1161 this->brkEnd+=len;
1162 }
1163 }
1164 }
1165 return this->brkEnd; // intentional, should return the new end, even though the libc brk returns the old value
1166}
1167
1168U32 KProcess::ioctl(KThread* thread, FD fildes, U32 request) {
1169 KFileDescriptorPtr fd = this->getFileDescriptor(fildes);

Callers 1

syscall_brkFunction · 0.80

Calls 2

mmapMethod · 0.80
isPageAllocatedMethod · 0.45

Tested by

no test coverage detected