0.8.5.49:
[sbcl/simd.git] / src / runtime / os-common.c
blob3becd185760596bf616815454e5e19bb4325e738
1 /*
2 * This software is part of the SBCL system. See the README file for
3 * more information.
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
12 #include <stdio.h>
13 #include <errno.h>
14 #include <strings.h>
16 #include "os.h"
17 #include "interr.h"
19 /* Except for os_zero, these routines are only called by Lisp code.
20 * These routines may also be replaced by os-dependent versions
21 * instead. See hpux-os.c for some useful restrictions on actual
22 * usage. */
24 void
25 os_zero(os_vm_address_t addr, os_vm_size_t length)
27 os_vm_address_t block_start;
28 os_vm_size_t block_size;
30 #ifdef DEBUG
31 fprintf(stderr,";;; os_zero: addr: 0x%08x, len: 0x%08x\n",addr,length);
32 #endif
34 block_start = os_round_up_to_page(addr);
36 length -= block_start-addr;
37 block_size = os_trunc_size_to_page(length);
39 if (block_start > addr)
40 bzero((char *)addr, block_start-addr);
41 if (block_size < length)
42 bzero((char *)block_start+block_size, length-block_size);
44 if (block_size != 0) {
45 /* Now deallocate and allocate the block so that it faults in
46 * zero-filled. */
48 os_invalidate(block_start, block_size);
49 addr = os_validate(block_start, block_size);
51 if (addr == NULL || addr != block_start)
52 lose("os_zero: block moved! 0x%08x ==> 0x%08x",
53 block_start,
54 addr);
58 os_vm_address_t
59 os_allocate(os_vm_size_t len)
61 return os_validate((os_vm_address_t)NULL, len);
64 os_vm_address_t
65 os_allocate_at(os_vm_address_t addr, os_vm_size_t len)
67 return os_validate(addr, len);
70 void
71 os_deallocate(os_vm_address_t addr, os_vm_size_t len)
73 os_invalidate(addr,len);
76 /* (This function once tried to grow the chunk by asking os_validate
77 * whether the space was available, but that really only works under
78 * Mach.) */
79 os_vm_address_t
80 os_reallocate(os_vm_address_t addr, os_vm_size_t old_len, os_vm_size_t len)
82 addr=os_trunc_to_page(addr);
83 len=os_round_up_size_to_page(len);
84 old_len=os_round_up_size_to_page(old_len);
86 if (addr==NULL)
87 return os_allocate(len);
88 else{
89 long len_diff=len-old_len;
91 if (len_diff<0)
92 os_invalidate(addr+len,-len_diff);
93 else{
94 if (len_diff!=0) {
95 os_vm_address_t new=os_allocate(len);
97 if(new!=NULL){
98 bcopy(addr,new,old_len);
99 os_invalidate(addr,old_len);
102 addr=new;
105 return addr;
110 os_get_errno(void)
112 return errno;