home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / kludge03.tz / kludge03 / mk74 / user / libmach / sbrk.c < prev    next >
C/C++ Source or Header  |  1992-02-26  |  4KB  |  155 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie the
  24.  * rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    sbrk.c,v $
  29.  * Revision 2.3  92/02/23  19:47:44  elf
  30.  *     Added luna88k goop.
  31.  *     [92/02/20            danner]
  32.  * 
  33.  * Revision 2.2  92/01/16  00:01:23  rpd
  34.  *     Moved from user collection to mk collection.
  35.  * 
  36.  * Revision 2.2  91/03/26  17:46:40  mrt
  37.  *     First checkin
  38.  * 
  39.  */
  40. /*
  41.  *    File:    sbrk.c
  42.  *    Author: Avadis Tevanian, Carnegie Mellon University
  43.  *    Date:    June 1986
  44.  *
  45.  *    Unix compatibility for sbrk system call.
  46.  */
  47.  
  48. #define  EXPORT_BOOLEAN
  49. #include <mach.h>        /* for vm_allocate, vm_offset_t */
  50. #include <stdio.h>        /* for stderr */
  51. #include <sys/types.h>        /* for caddr_t */
  52. #include <mach_init.h>        /* for vm_page_size */
  53.  
  54. #if defined(luna88k)
  55. asm("        global _curbrk");
  56. asm("        global _minbrk");
  57. asm("        global _end");
  58. asm("        data");
  59. asm("_minbrk:    word _end");
  60. asm("_curbrk:    word _end");
  61. #endif
  62.  
  63. #if    (defined(vax) || defined(ibmrt) || defined(ns32000) || defined(sun) || defined(i386))
  64. #if    multimax
  65. DEF_FUNC()
  66. {
  67. #endif    multimax
  68. asm(".data");
  69. asm(".globl    curbrk");
  70. asm(".globl    minbrk");
  71. asm(".globl    _curbrk");
  72. asm(".globl    _minbrk");
  73. asm(".globl    _end");
  74. #if    multimax
  75. asm("_minbrk:");
  76. asm("minbrk:    .double    _end");
  77. asm("_curbrk:");
  78. asm("curbrk:    .double    _end");
  79. asm(".text");
  80. }
  81. #else    multimax
  82. asm("_minbrk:");
  83. asm("minbrk:    .long    _end");
  84. asm("_curbrk:");
  85. asm("curbrk:    .long    _end");
  86. asm(".text");
  87. #endif    multimax
  88. #else    (defined(vax) || defined(ibmrt) || defined(ns32000) || defined(sun) || defined (i386) 
  89.  
  90. /* Will not find get "assembler" forms of cubrk, minbrk. */
  91.  
  92. #ifdef    mips
  93. extern char end;
  94. #define curbrk _curbrk
  95. #define minbrk _minbrk
  96. caddr_t curbrk = &end;
  97. caddr_t minbrk = &end;
  98. #endif    mips
  99.  
  100. #endif    (defined(vax) || defined(ibmrt) || defined(ns32000) || defined(sun) || defined(i386) 
  101.  
  102. #ifdef lint
  103.    /* lint doesn't see asm stuff */
  104. caddr_t    curbrk;
  105. caddr_t    minbrk;
  106. #else lint
  107. extern caddr_t curbrk;
  108. extern caddr_t minbrk;
  109. #endif lint
  110.  
  111. #define    roundup(a,b)    ((((a) + (b) - 1) / (b)) * (b))
  112.  
  113. static int sbrk_needs_init = FALSE;
  114.  
  115. caddr_t sbrk(size)
  116.     int    size;
  117. {
  118.     vm_offset_t    addr;
  119.     kern_return_t    ret;
  120.     caddr_t        ocurbrk;
  121.  
  122.     if (sbrk_needs_init) {
  123.         sbrk_needs_init = FALSE;
  124.         /*
  125.          *    Get "curbrk"
  126.          */
  127.  
  128.     }
  129.     
  130.     if (size <= 0)
  131.         return(curbrk);
  132.     addr = (vm_offset_t) roundup((int)curbrk,vm_page_size);
  133.     ocurbrk = curbrk;
  134.     if (((int)curbrk+size) > addr)
  135.     {    ret = vm_allocate(mach_task_self(), &addr, 
  136.                 (vm_size_t) size -((int)addr-(int)curbrk), FALSE);
  137.         if (ret == KERN_NO_SPACE) {
  138.             ret = vm_allocate(mach_task_self(), &addr, (vm_size_t) size, TRUE);
  139.             ocurbrk = (caddr_t)addr;
  140.         }
  141.         if (ret != KERN_SUCCESS) 
  142.             return((caddr_t) -1);
  143.     }
  144.  
  145.     curbrk = (caddr_t)ocurbrk + size;
  146.     return(ocurbrk);
  147.  
  148. }
  149.  
  150. void brk(x)
  151.     caddr_t x;
  152. {
  153.     fprintf(stderr, "brk: not implemented\n");
  154. }
  155.