[f05756]: src / runtime / os.h Maximize Restore History

Download this file

os.h    214 lines (178 with data), 8.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* common interface for OS-dependent functions
*/
/*
* This software is part of the SBCL system. See the README file for
* more information.
*
* This software is derived from the CMU CL system, which was
* written at Carnegie Mellon University and released into the
* public domain. The software is in the public domain and is
* provided with absolutely no warranty. See the COPYING and CREDITS
* files for more information.
*/
#if !defined(_OS_H_INCLUDED_)
#define _OS_H_INCLUDED_
#include "sbcl.h"
#include "runtime.h"
/* Some standard preprocessor definitions and typedefs are needed from
* the OS-specific #include files. This is an attempt to document
* them on 20000729, by WHN the impatient reverse engineer.
*
* OS_VM_PROT_READ, OS_VM_PROT_WRITE, OS_VM_PROT_EXECUTE
* flags for mmap, mprotect, etc. controlling memory protection
* os_vm_prot_t
* type used for flags for mmap, mprotect, etc.
*
* os_vm_address_t
* the type used to represent addresses? (dunno why not just void*)
* os_vm_size_t, os_vm_off_t
* corresponding to standard (POSIX?) types size_t, off_t
* os_context_t
* the type used to represent context in a POSIX sigaction SA_SIGACTION
* handler, i.e. the actual type of the thing pointed to by the
* void* third argument of a handler */
#include "target-os.h"
#define OS_VM_PROT_ALL \
(OS_VM_PROT_READ | OS_VM_PROT_WRITE | OS_VM_PROT_EXECUTE)
#define OS_VM_PROT_NONE 0
extern os_vm_size_t os_vm_page_size;
/* Do anything we need to do when starting up the runtime environment
* in this OS. */
extern void os_init(char *argv[], char *envp[]);
/* Install any OS-dependent low-level signal handlers which are needed
* by the runtime environment. E.g. the signals raised by a violation
* of the gencgc write barrier need to be caught at a low level, and
* they may be SIGSEGV on one OS and SIGBUS on another, so we install
* them in an OS-dependent way. */
extern void os_install_interrupt_handlers(void);
/* Clear a possibly-huge region of memory using any tricks available to
* do it efficiently, e.g. possibly unmapping it and then remapping it.
*
* FIXME: For the x86 Linux/OpenBSD/FreeBSD ports, I'd be somewhat
* surprised if bzero() wasn't substantially as efficient as
* any tricks like this. It might make sense to benchmark it
* and simplify if the difference isn't too large. */
extern void os_zero(os_vm_address_t addr, os_vm_size_t length);
/* It looks as though this function allocates 'len' bytes at 'addr',
* or at an OS-chosen address if 'addr' is zero.
*
* FIXME: There was some documentation for these functions in
* "hp-ux.c" in the old CMU CL code. Perhaps move/merge it in here. */
extern os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len);
#ifdef LISP_FEATURE_WIN32
void* os_validate_recommit(os_vm_address_t addr, os_vm_size_t len);
#endif
/* This function seems to undo the effect of os_validate(..). */
extern void os_invalidate(os_vm_address_t addr, os_vm_size_t len);
/* This maps a file into memory, or calls lose(..) for various
* failures. */
extern os_vm_address_t os_map(int fd,
int offset,
os_vm_address_t addr,
os_vm_size_t len);
/* This presumably flushes the instruction cache, if that can be done
* explicitly. (It doesn't seem to be an issue for the i386 port,
* which is all that exists for SBCL. It might be important for some
* other architecture which CMU CL has been ported to, though. */
extern void os_flush_icache(os_vm_address_t addr, os_vm_size_t len);
/* This sets access rights for an area of memory, e.g.
* write-protecting a page so that the garbage collector can find out
* whether it's modified by handling the signal. */
extern void os_protect(os_vm_address_t addr,
os_vm_size_t len,
os_vm_prot_t protection);
/* This returns true for an address which makes sense at the Lisp level. */
extern boolean is_valid_lisp_addr(os_vm_address_t test);
/* Given a signal context, return the address for storage of the
* register, of the specified offset, for that context. The offset is
* defined in the storage class (SC) defined in the Lisp virtual
* machine (i.e. the file "vm.lisp" for the appropriate architecture). */
os_context_register_t *
os_context_register_addr(os_context_t *context, int offset);
/* FIXME: Pending investigation, this #ifdef stays as alpha. If it
* turns out that the alpha truly requires this, it can change to
* ARCH_HAS_FLOAT_REGISTERS (currently #defined in alpha-arch.h -- CSR
* 2002-02-04 */
#ifdef LISP_FEATURE_ALPHA
os_context_register_t *
os_context_float_register_addr(os_context_t *context, int offset);
#endif
/* Given a signal context, return the address for storage of the
* program counter for that context. */
os_context_register_t *os_context_pc_addr(os_context_t *context);
#ifdef ARCH_HAS_NPC_REGISTER
os_context_register_t *os_context_npc_addr(os_context_t *context);
#endif
#ifdef ARCH_HAS_LINK_REGISTER
os_context_register_t *os_context_lr_addr(os_context_t *context);
#endif
/* Given a signal context, return the address for storage of the
* system stack pointer for that context. */
#ifdef ARCH_HAS_STACK_POINTER
os_context_register_t *os_context_sp_addr(os_context_t *context);
#endif
/* Given a signal context, return the address for storage of the
* signal mask for that context. */
sigset_t *os_context_sigmask_addr(os_context_t *context);
/* (Note that there may be other accessors for os_context_t which
* depend not only on the OS, but also on the architecture, e.g.
* getting at EFL/EFLAGS on the x86. Such things are defined in the
* architecture-dependence files, not the OS-dependence files.) */
/* These are not architecture-specific functions, but are instead
* general utilities defined in terms of the architecture-specific
* function os_validate(..) and os_invalidate(..).
*/
extern os_vm_address_t os_allocate(os_vm_size_t len);
extern void os_deallocate(os_vm_address_t addr, os_vm_size_t len);
/* FIXME: The os_trunc_foo(..) and os_round_foo(..) macros here could
* be functions. */
#define os_trunc_to_page(addr) \
(os_vm_address_t)(((long)(addr))&~(os_vm_page_size-1))
#define os_round_up_to_page(addr) \
os_trunc_to_page((addr)+(os_vm_page_size-1))
#define os_trunc_size_to_page(size) \
(os_vm_size_t)(((long)(size))&~(os_vm_page_size-1))
#define os_round_up_size_to_page(size) \
os_trunc_size_to_page((size)+(os_vm_page_size-1))
/* KLUDGE: The errno error reporting system is an ugly nonreentrant
* botch which nonetheless wasn't too painful in the old days.
* However, it's obviously not good for multithreaded programs, and n
* order to accommodate multithreading while retaining the C-level
* syntax of the old UNIX interface, errno has now been changed from a
* true variable to a preprocessor definition which is too hairy for
* us to try to unscrew in Lisp code. Instead, Lisp code calls this
* service routine to do whatever hackery is necessary in C code, and
* to return the value in a way that Lisp can understand. */
int os_get_errno(void);
/* Return an absolute path to the runtime executable, or NULL if this
* information is unavailable. Unless external_path is non-zero the
* returned path may only be valid for the current process, ie:
* something like /proc/curproc/file. If a non-null pathname is
* returned, it must be 'free'd. */
extern char *os_get_runtime_executable_path(int external_path);
/* Write platforms specific ones when necessary. This is to get us off
* the ground. */
#if N_WORD_BITS == 32
# define OS_VM_SIZE_FMT "u"
# define OS_VM_SIZE_FMTX "x"
#else
# define OS_VM_SIZE_FMT "lu"
# define OS_VM_SIZE_FMTX "lx"
#endif
/* FIXME: this is not the right place for this, but here we have
* a convenient base type to hand. If it turns out we can just use
* size_t everywhere, this can more to runtime.h. */
typedef os_vm_size_t word_t;
#define WORD_FMTX OS_VM_SIZE_FMTX
#ifdef LISP_FEATURE_SB_THREAD
# ifndef CANNOT_USE_POSIX_SEM_T
# include <semaphore.h>
typedef sem_t os_sem_t;
# endif
void os_sem_init(os_sem_t *sem, unsigned int value);
void os_sem_wait(os_sem_t *sem, char *what);
void os_sem_post(os_sem_t *sem, char *what);
void os_sem_destroy(os_sem_t *sem);
#endif
#endif