2015-12-22 12:55:44 +01:00
|
|
|
/*
|
2017-01-18 21:35:11 +01:00
|
|
|
* This file is part of Jehanne.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
|
|
|
|
*
|
|
|
|
* Jehanne is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 2 of the License.
|
|
|
|
*
|
|
|
|
* Jehanne is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
2015-12-22 12:55:44 +01:00
|
|
|
*/
|
2017-01-18 21:35:11 +01:00
|
|
|
#define PORTABLE_SYSCALLS
|
2015-12-22 12:55:44 +01:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
|
|
|
|
extern char end[];
|
2017-01-18 21:35:11 +01:00
|
|
|
static char *last_brk = { end };
|
2015-12-22 12:55:44 +01:00
|
|
|
|
2017-01-18 21:35:11 +01:00
|
|
|
#define ROUND_BRK(b) (((uintptr_t)b + 7) & ~7)
|
2015-12-22 12:55:44 +01:00
|
|
|
|
2017-01-18 21:35:11 +01:00
|
|
|
static uintptr_t
|
|
|
|
setbrk(uintptr_t p)
|
2017-01-16 23:53:05 +01:00
|
|
|
{
|
2017-01-18 21:35:11 +01:00
|
|
|
long b;
|
|
|
|
/* assert: devself is still working */
|
2019-11-26 02:25:23 +01:00
|
|
|
assert((b = sys_create("#0/brk/set", -1, p)) < 0);
|
2017-01-18 21:35:11 +01:00
|
|
|
if(b == -1)
|
|
|
|
return ~0; // an error occurred
|
|
|
|
return (uintptr_t)~b;
|
2017-01-16 23:53:05 +01:00
|
|
|
}
|
2016-12-31 00:43:02 +01:00
|
|
|
|
2015-12-22 12:55:44 +01:00
|
|
|
int
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_brk(void *p)
|
2015-12-22 12:55:44 +01:00
|
|
|
{
|
2017-01-18 21:35:11 +01:00
|
|
|
uintptr_t new_brk;
|
2015-12-22 12:55:44 +01:00
|
|
|
|
2017-01-18 21:35:11 +01:00
|
|
|
new_brk = ROUND_BRK(p);
|
|
|
|
if(setbrk(new_brk) == ~0)
|
2015-12-22 12:55:44 +01:00
|
|
|
return -1;
|
2017-01-18 21:35:11 +01:00
|
|
|
last_brk = (char*)new_brk;
|
2015-12-22 12:55:44 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_segbrk(uint32_t increment)
|
2015-12-22 12:55:44 +01:00
|
|
|
{
|
2017-01-18 21:35:11 +01:00
|
|
|
uintptr_t new_brk;
|
2015-12-22 12:55:44 +01:00
|
|
|
|
2017-01-18 21:35:11 +01:00
|
|
|
new_brk = ROUND_BRK(last_brk);
|
|
|
|
if(setbrk(new_brk+increment) == ~0)
|
2015-12-22 12:55:44 +01:00
|
|
|
return (void*)-1;
|
2017-01-18 21:35:11 +01:00
|
|
|
last_brk = (char*)new_brk + increment;
|
|
|
|
return (void*)new_brk;
|
2015-12-22 12:55:44 +01:00
|
|
|
}
|