pub fn sbrk(n: usize) usize n: usize369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384pub fn sbrk(n: usize) usize {
if (bloc == 0) {
// we are at the start
bloc = @intFromPtr(&ExecData.end);
bloc_max = @intFromPtr(&ExecData.end);
}
const bl = std.mem.alignForward(usize, bloc, std.heap.pageSize());
const n_aligned = std.mem.alignForward(usize, n, std.heap.pageSize());
if (bl + n_aligned > bloc_max) {
// we need to allocate
if (brk_(bl + n_aligned) < 0) return 0;
bloc_max = bl + n_aligned;
}
bloc = bloc + n_aligned;
return bl;
}