mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Remove sbrk(2).
Note: This is an incompatible ABI change.
This commit is contained in:
parent
74247eb71e
commit
5143f01b0a
10 changed files with 4 additions and 105 deletions
|
@ -139,9 +139,6 @@ addr_t Construct32(Process* process, const uint8_t* file, size_t filelen,
|
|||
if ( pht->flags & PF_R ) { prot |= PROT_READ; }
|
||||
if ( pht->flags & PF_W ) { prot |= PROT_WRITE; }
|
||||
|
||||
if ( (pht->flags & (PF_X | PF_R | PF_W)) == (PF_R | PF_W) )
|
||||
prot |= PROT_HEAP;
|
||||
|
||||
struct segment segment;
|
||||
segment.addr = mapto;
|
||||
segment.size = Page::AlignUp(mapbytes);
|
||||
|
@ -348,9 +345,6 @@ addr_t Construct64(Process* process, const uint8_t* file, size_t filelen,
|
|||
if ( pht->flags & PF_R ) { prot |= PROT_READ; }
|
||||
if ( pht->flags & PF_W ) { prot |= PROT_WRITE; }
|
||||
|
||||
if ( (pht->flags & (PF_X | PF_R | PF_W)) == (PF_R | PF_W) )
|
||||
prot |= PROT_HEAP;
|
||||
|
||||
struct segment segment;
|
||||
segment.addr = mapto;
|
||||
segment.size = Page::AlignUp(mapbytes);
|
||||
|
|
|
@ -131,7 +131,6 @@ ssize_t sys_readv(int, const struct iovec*, int);
|
|||
ssize_t sys_recv(int, void*, size_t, int);
|
||||
ssize_t sys_recvmsg(int, struct msghdr*, int);
|
||||
int sys_renameat(int, const char*, int, const char*);
|
||||
void* sys_sbrk(intptr_t);
|
||||
int sys_sched_yield(void);
|
||||
ssize_t sys_send(int, const void*, size_t, int);
|
||||
ssize_t sys_sendmsg(int, const struct msghdr*, int);
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#define PROT_KERNEL (PROT_KEXEC | PROT_KWRITE | PROT_KREAD)
|
||||
|
||||
#define PROT_FORK (1<<6)
|
||||
#define PROT_HEAP (1<<7)
|
||||
|
||||
#define MAP_SHARED (1<<0)
|
||||
#define MAP_PRIVATE (1<<1)
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
#define SYSCALL_MEMSTAT 32
|
||||
#define SYSCALL_ISATTY 33
|
||||
#define SYSCALL_UPTIME 34 /* OBSOLETE */
|
||||
#define SYSCALL_SBRK 35
|
||||
#define SYSCALL_SBRK 35 /* OBSOLETE */
|
||||
#define SYSCALL_LSEEK 36
|
||||
#define SYSCALL_GETPAGESIZE 37
|
||||
#define SYSCALL_MKDIR 38 /* OBSOLETE */
|
||||
|
|
|
@ -262,7 +262,7 @@ bool MapMemory(Process* process, uintptr_t addr, size_t size, int prot)
|
|||
|
||||
namespace Sortix {
|
||||
|
||||
const int USER_SETTABLE_PROT = PROT_USER | PROT_HEAP;
|
||||
const int USER_SETTABLE_PROT = PROT_USER;
|
||||
const int UNDERSTOOD_MMAP_FLAGS = MAP_SHARED |
|
||||
MAP_PRIVATE |
|
||||
MAP_ANONYMOUS |
|
||||
|
|
|
@ -1625,62 +1625,6 @@ int sys_setpgid(pid_t pid, pid_t pgid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void* sys_sbrk(intptr_t increment)
|
||||
{
|
||||
Process* process = CurrentProcess();
|
||||
ScopedLock lock(&process->segment_lock);
|
||||
|
||||
// Locate the heap segment.
|
||||
struct segment* heap_segment = NULL;
|
||||
for ( size_t i = process->segments_used; !heap_segment && i != 0; i-- )
|
||||
{
|
||||
struct segment* candidate = &process->segments[i-1];
|
||||
if ( !(candidate->prot & PROT_HEAP) )
|
||||
continue;
|
||||
heap_segment = candidate;
|
||||
}
|
||||
if ( !heap_segment )
|
||||
return errno = ENOMEM, (void*) -1UL;
|
||||
|
||||
assert(IsUserspaceSegment(heap_segment));
|
||||
|
||||
// Decrease the size of the heap segment if requested.
|
||||
if ( increment < 0 )
|
||||
{
|
||||
uintptr_t abs_amount = Page::AlignDown(- (uintptr_t) increment);
|
||||
if ( heap_segment->size < abs_amount )
|
||||
abs_amount = heap_segment->size;
|
||||
uintptr_t new_end = heap_segment->addr + heap_segment->size - abs_amount;
|
||||
Memory::UnmapRange(new_end, abs_amount, PAGE_USAGE_USER_SPACE);
|
||||
heap_segment->size -= abs_amount;
|
||||
// TODO: How do we handle that the heap shrinks to 0 bytes?
|
||||
}
|
||||
|
||||
// Increase the size of the heap if requested.
|
||||
if ( 0 < increment )
|
||||
{
|
||||
uintptr_t abs_amount = Page::AlignUp(increment);
|
||||
uintptr_t max_growth = 0 - (heap_segment->addr + heap_segment->size);
|
||||
if ( max_growth < abs_amount )
|
||||
return errno = ENOMEM, (void*) -1UL;
|
||||
struct segment growth;
|
||||
growth.addr = heap_segment->addr + heap_segment->size;
|
||||
growth.size = abs_amount;
|
||||
growth.prot = heap_segment->prot;
|
||||
if ( !IsUserspaceSegment(&growth) )
|
||||
return errno = ENOMEM, (void*) -1UL;
|
||||
if ( FindOverlappingSegment(process, &growth) )
|
||||
return errno = ENOMEM, (void*) -1UL;
|
||||
if ( !Memory::MapRange(growth.addr, growth.size, growth.prot, PAGE_USAGE_USER_SPACE) )
|
||||
return errno = ENOMEM, (void*) -1UL;
|
||||
heap_segment->size += growth.size;
|
||||
}
|
||||
|
||||
assert(IsUserspaceSegment(heap_segment));
|
||||
|
||||
return (void*) (heap_segment->addr + heap_segment->size);
|
||||
}
|
||||
|
||||
size_t sys_getpagesize(void)
|
||||
{
|
||||
return Page::Size();
|
||||
|
|
|
@ -70,7 +70,7 @@ void* syscall_list[SYSCALL_MAX_NUM + 1] =
|
|||
[SYSCALL_MEMSTAT] = (void*) sys_memstat,
|
||||
[SYSCALL_ISATTY] = (void*) sys_isatty,
|
||||
[SYSCALL_UPTIME] = (void*) sys_bad_syscall,
|
||||
[SYSCALL_SBRK] = (void*) sys_sbrk,
|
||||
[SYSCALL_SBRK] = (void*) sys_bad_syscall,
|
||||
[SYSCALL_LSEEK] = (void*) sys_lseek,
|
||||
[SYSCALL_GETPAGESIZE] = (void*) sys_getpagesize,
|
||||
[SYSCALL_MKDIR] = (void*) sys_bad_syscall,
|
||||
|
|
|
@ -618,7 +618,6 @@ unistd/readlinkat.o \
|
|||
unistd/readlink.o \
|
||||
unistd/read.o \
|
||||
unistd/rmdir.o \
|
||||
unistd/sbrk.o \
|
||||
unistd/setegid.o \
|
||||
unistd/seteuid.o \
|
||||
unistd/setgid.o \
|
||||
|
|
|
@ -391,8 +391,7 @@ typedef __pid_t pid_t;
|
|||
/* TODO: intptr_t is not declared because <stdint.h> doesn't allow other headers
|
||||
to define some, but not all, of the fixed width types. Additionally,
|
||||
intptr_t was only added for the sake of sbrk(), but that was removed in
|
||||
POSIX 2001. The legacy sbrk() system call left supported by the kernel
|
||||
can do with __uintptr for now, as it will be removed soon enough. */
|
||||
POSIX 2001. */
|
||||
|
||||
/* Somehow programs are required to declare environ themselves according to
|
||||
the POSIX specification. */
|
||||
|
@ -552,7 +551,6 @@ char* get_current_dir_name(void);
|
|||
int getdomainname(char*, size_t);
|
||||
int getentropy(void*, size_t);
|
||||
int pipe2(int [2], int);
|
||||
void* sbrk(__intptr_t increment);
|
||||
int sethostname(const char*, size_t);
|
||||
typedef unsigned int useconds_t;
|
||||
int usleep(useconds_t useconds);
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
unistd/sbrk.cpp
|
||||
Controls the size of the data segment.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL1(void*, sys_sbrk, SYSCALL_SBRK, intptr_t);
|
||||
|
||||
extern "C" void* sbrk(intptr_t increment)
|
||||
{
|
||||
return sys_sbrk(increment);
|
||||
}
|
Loading…
Add table
Reference in a new issue