diff --git a/kernel/elf.cpp b/kernel/elf.cpp index 69f2f86d..bc50272c 100644 --- a/kernel/elf.cpp +++ b/kernel/elf.cpp @@ -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); diff --git a/kernel/include/sortix/kernel/syscall.h b/kernel/include/sortix/kernel/syscall.h index 8bf559f9..7eaf68bd 100644 --- a/kernel/include/sortix/kernel/syscall.h +++ b/kernel/include/sortix/kernel/syscall.h @@ -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); diff --git a/kernel/include/sortix/mman.h b/kernel/include/sortix/mman.h index 28b36a74..bcb07bc4 100644 --- a/kernel/include/sortix/mman.h +++ b/kernel/include/sortix/mman.h @@ -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) diff --git a/kernel/include/sortix/syscall.h b/kernel/include/sortix/syscall.h index 06d2f1f4..79acfd55 100644 --- a/kernel/include/sortix/syscall.h +++ b/kernel/include/sortix/syscall.h @@ -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 */ diff --git a/kernel/memorymanagement.cpp b/kernel/memorymanagement.cpp index 7993c054..440be5ce 100644 --- a/kernel/memorymanagement.cpp +++ b/kernel/memorymanagement.cpp @@ -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 | diff --git a/kernel/process.cpp b/kernel/process.cpp index 1f1610aa..cee5a7b6 100644 --- a/kernel/process.cpp +++ b/kernel/process.cpp @@ -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(); diff --git a/kernel/syscall.cpp b/kernel/syscall.cpp index 0b0219a3..ba47c745 100644 --- a/kernel/syscall.cpp +++ b/kernel/syscall.cpp @@ -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, diff --git a/libc/Makefile b/libc/Makefile index 82b39e99..041a873c 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -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 \ diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 40ce431b..6aa4b586 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -391,8 +391,7 @@ typedef __pid_t pid_t; /* TODO: intptr_t is not declared because 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); diff --git a/libc/unistd/sbrk.cpp b/libc/unistd/sbrk.cpp deleted file mode 100644 index 60db768d..00000000 --- a/libc/unistd/sbrk.cpp +++ /dev/null @@ -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 . - - unistd/sbrk.cpp - Controls the size of the data segment. - -*******************************************************************************/ - -#include -#include -#include - -DEFN_SYSCALL1(void*, sys_sbrk, SYSCALL_SBRK, intptr_t); - -extern "C" void* sbrk(intptr_t increment) -{ - return sys_sbrk(increment); -}