SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /userland/libc.c (Article 7) and /userland/libc.c (Article 7.5)


001 /* Copyright (C) 2005 David Decotigny             001 /* Copyright (C) 2005 David Decotigny
002                                                   002 
003    This program is free software; you can redi    003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU Genera    004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundatio    005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any lat    006    of the License, or (at your option) any later version.
007                                                   007    
008    This program is distributed in the hope tha    008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the     009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR    010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details    011    GNU General Public License for more details.
012                                                   012    
013    You should have received a copy of the GNU     013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to t    014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 3    015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA.                                           016    USA. 
017 */                                                017 */
                                                   >> 018 
                                                   >> 019 #include "crt.h"
                                                   >> 020 #include "libc.h"
                                                   >> 021 
                                                   >> 022 
                                                   >> 023 void * mmap(void *start, size_t length, int prot , int flags,
                                                   >> 024             const char *path, loff_t offset)
                                                   >> 025 {
                                                   >> 026   /* At kernel side, offset is considered positive */
                                                   >> 027   if (offset < 0)
                                                   >> 028     return NULL;
                                                   >> 029 
                                                   >> 030   if (0 != _sos_mmap(& start, length, prot, flags, path, offset))
                                                   >> 031     return NULL;
                                                   >> 032 
                                                   >> 033   return start;
                                                   >> 034 }
                                                   >> 035 
                                                   >> 036 
                                                   >> 037 void * mremap(void * old_addr, size_t old_len,
                                                   >> 038               size_t new_len,
                                                   >> 039               unsigned long flags)
                                                   >> 040 {
                                                   >> 041   void * new_uaddr = old_addr;
                                                   >> 042   if (0 != _sos_mresize(old_addr, old_len, & new_uaddr, new_len, flags))
                                                   >> 043     return NULL;
                                                   >> 044 
                                                   >> 045   return new_uaddr;
                                                   >> 046 }
                                                   >> 047 
                                                   >> 048 
                                                   >> 049 /**
                                                   >> 050  * The presence of this global variable without any protected access
                                                   >> 051  * to it explains why the "brk/sbrk" functions below are MT-unsafe !
                                                   >> 052  */
                                                   >> 053 static void * kernel_heap_top = NULL;
                                                   >> 054 int brk(void *end_data_seg)
                                                   >> 055 {
                                                   >> 056   if (! end_data_seg)
                                                   >> 057     return -1;
                                                   >> 058 
                                                   >> 059   kernel_heap_top = _sos_brk(end_data_seg);
                                                   >> 060   return 0;
                                                   >> 061 }
                                                   >> 062 
                                                   >> 063 
                                                   >> 064 void *sbrk(ptrdiff_t increment)
                                                   >> 065 {
                                                   >> 066   if (! kernel_heap_top)
                                                   >> 067     kernel_heap_top = _sos_brk(0);
                                                   >> 068 
                                                   >> 069   kernel_heap_top = _sos_brk(kernel_heap_top + increment);
                                                   >> 070   return kernel_heap_top;
                                                   >> 071 }
                                                   >> 072 
                                                   >> 073 
                                                   >> 074 void * calloc (size_t nmemb, size_t size)
                                                   >> 075 {
                                                   >> 076   return malloc(nmemb * size);
                                                   >> 077 }
                                                   >> 078 
                                                   >> 079 
                                                   >> 080 /**
                                                   >> 081  * The presence of this global variable without any protected access
                                                   >> 082  * to it explains why the "malloc/calloc" functions below are
                                                   >> 083  * MT-unsafe !
                                                   >> 084  */
                                                   >> 085 static void * malloc_heap_top = NULL;
                                                   >> 086 void * malloc (size_t size)
                                                   >> 087 {
                                                   >> 088   void * retval;
                                                   >> 089 
                                                   >> 090   if (size <= 0)
                                                   >> 091     return NULL;
                                                   >> 092 
                                                   >> 093   /* Align on a 4B boundary */
                                                   >> 094   size = ((size-1) & ~3) + 4;
                                                   >> 095 
                                                   >> 096   if (! kernel_heap_top)
                                                   >> 097     kernel_heap_top = _sos_brk(0);
                                                   >> 098 
                                                   >> 099   if (! malloc_heap_top)
                                                   >> 100     malloc_heap_top = kernel_heap_top;
                                                   >> 101 
                                                   >> 102   retval = malloc_heap_top;
                                                   >> 103   malloc_heap_top += size;
                                                   >> 104 
                                                   >> 105   return retval;
                                                   >> 106 }
                                                      

source navigation ] diff markup ] identifier search ] general search ]