blob: 9b18a2919d84c805678f32200126549c18ec5661 [file] [log] [blame]
Brad Fitzpatrick51947442016-03-01 22:57:46 +00001// Copyright 2010 The Go Authors. All rights reserved.
David du Colombiere9c57d82014-11-21 19:39:01 +01002// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package runtime
6
7import "unsafe"
8
David du Colombiere9c57d82014-11-21 19:39:01 +01009func sbrk(n uintptr) unsafe.Pointer {
David du Colombiere9c57d82014-11-21 19:39:01 +010010 // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c
Dmitry Vyukov3c3848a2015-01-30 14:36:12 +030011 bl := bloc
12 n = memRound(n)
Richard Millerc2cdfbd2018-02-28 09:35:55 +000013 if bl+n > blocMax {
14 if brk_(unsafe.Pointer(bl+n)) < 0 {
15 return nil
16 }
17 blocMax = bl + n
David du Colombiere9c57d82014-11-21 19:39:01 +010018 }
Dmitry Vyukov3c3848a2015-01-30 14:36:12 +030019 bloc += n
David du Colombiere9c57d82014-11-21 19:39:01 +010020 return unsafe.Pointer(bl)
21}