Initial Spring 2016 commit.

This commit is contained in:
Geoffrey Challen
2015-12-23 00:50:04 +00:00
commit cafa9f5690
732 changed files with 92195 additions and 0 deletions

132
kern/include/addrspace.h Normal file
View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ADDRSPACE_H_
#define _ADDRSPACE_H_
/*
* Address space structure and operations.
*/
#include <vm.h>
#include "opt-dumbvm.h"
struct vnode;
/*
* Address space - data structure associated with the virtual memory
* space of a process.
*
* You write this.
*/
struct addrspace {
#if OPT_DUMBVM
vaddr_t as_vbase1;
paddr_t as_pbase1;
size_t as_npages1;
vaddr_t as_vbase2;
paddr_t as_pbase2;
size_t as_npages2;
paddr_t as_stackpbase;
#else
/* Put stuff here for your VM system */
#endif
};
/*
* Functions in addrspace.c:
*
* as_create - create a new empty address space. You need to make
* sure this gets called in all the right places. You
* may find you want to change the argument list. May
* return NULL on out-of-memory error.
*
* as_copy - create a new address space that is an exact copy of
* an old one. Probably calls as_create to get a new
* empty address space and fill it in, but that's up to
* you.
*
* as_activate - make curproc's address space the one currently
* "seen" by the processor.
*
* as_deactivate - unload curproc's address space so it isn't
* currently "seen" by the processor. This is used to
* avoid potentially "seeing" it while it's being
* destroyed.
*
* as_destroy - dispose of an address space. You may need to change
* the way this works if implementing user-level threads.
*
* as_define_region - set up a region of memory within the address
* space.
*
* as_prepare_load - this is called before actually loading from an
* executable into the address space.
*
* as_complete_load - this is called when loading from an executable
* is complete.
*
* as_define_stack - set up the stack region in the address space.
* (Normally called *after* as_complete_load().) Hands
* back the initial stack pointer for the new process.
*
* Note that when using dumbvm, addrspace.c is not used and these
* functions are found in dumbvm.c.
*/
struct addrspace *as_create(void);
int as_copy(struct addrspace *src, struct addrspace **ret);
void as_activate(void);
void as_deactivate(void);
void as_destroy(struct addrspace *);
int as_define_region(struct addrspace *as,
vaddr_t vaddr, size_t sz,
int readable,
int writeable,
int executable);
int as_prepare_load(struct addrspace *as);
int as_complete_load(struct addrspace *as);
int as_define_stack(struct addrspace *as, vaddr_t *initstackptr);
/*
* Functions in loadelf.c
* load_elf - load an ELF user program executable into the current
* address space. Returns the entry point (initial PC)
* in the space pointed to by ENTRYPOINT.
*/
int load_elf(struct vnode *v, vaddr_t *entrypoint);
#endif /* _ADDRSPACE_H_ */

269
kern/include/array.h Normal file
View File

@@ -0,0 +1,269 @@
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by David A. Holland.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARRAY_H_
#define _ARRAY_H_
#include <cdefs.h>
#include <lib.h>
#define ARRAYS_CHECKED
#ifdef ARRAYS_CHECKED
#define ARRAYASSERT KASSERT
#else
#define ARRAYASSERT(x) ((void)(x))
#endif
#ifndef ARRAYINLINE
#define ARRAYINLINE INLINE
#endif
/*
* Base array type (resizeable array of void pointers) and operations.
*
* create - allocate an array.
* destroy - destroy an allocated array.
* init - initialize an array in space externally allocated.
* cleanup - clean up an array in space externally allocated.
* num - return number of elements in array.
* get - return element no. INDEX.
* set - set element no. INDEX to VAL.
* preallocate - allocate space without changing size; may fail and
* return error.
* setsize - change size to NUM elements; may fail and return error.
* add - append VAL to end of array; return its index in INDEX_RET if
* INDEX_RET isn't null; may fail and return error.
* remove - excise entry INDEX and slide following entries down to
* close the resulting gap.
*
* Note that expanding an array with setsize doesn't initialize the new
* elements. (Usually the caller is about to store into them anyway.)
*/
struct array {
void **v;
unsigned num, max;
};
struct array *array_create(void);
void array_destroy(struct array *);
void array_init(struct array *);
void array_cleanup(struct array *);
ARRAYINLINE unsigned array_num(const struct array *);
ARRAYINLINE void *array_get(const struct array *, unsigned index);
ARRAYINLINE void array_set(const struct array *, unsigned index, void *val);
int array_preallocate(struct array *, unsigned num);
int array_setsize(struct array *, unsigned num);
ARRAYINLINE int array_add(struct array *, void *val, unsigned *index_ret);
void array_remove(struct array *, unsigned index);
/*
* Inlining for base operations
*/
ARRAYINLINE unsigned
array_num(const struct array *a)
{
return a->num;
}
ARRAYINLINE void *
array_get(const struct array *a, unsigned index)
{
ARRAYASSERT(index < a->num);
return a->v[index];
}
ARRAYINLINE void
array_set(const struct array *a, unsigned index, void *val)
{
ARRAYASSERT(index < a->num);
a->v[index] = val;
}
ARRAYINLINE int
array_add(struct array *a, void *val, unsigned *index_ret)
{
unsigned index;
int ret;
index = a->num;
ret = array_setsize(a, index+1);
if (ret) {
return ret;
}
a->v[index] = val;
if (index_ret != NULL) {
*index_ret = index;
}
return 0;
}
/*
* Bits for declaring and defining typed arrays.
*
* Usage:
*
* DECLARRAY_BYTYPE(foo, bar) declares "struct foo", which is
* an array of pointers to "bar", plus the operations on it.
*
* DECLARRAY(foo) is equivalent to DECLARRAY_BYTYPE(fooarray, struct foo).
*
* DEFARRAY_BYTYPE and DEFARRAY are the same as DECLARRAY except that
* they define the operations, and both take an extra argument INLINE.
* For C99 this should be INLINE in header files and empty in the
* master source file, the same as the usage of ARRAYINLINE above and
* in array.c.
*
* Example usage in e.g. item.h of some game:
*
* DECLARRAY_BYTYPE(stringarray, char);
* DECLARRAY(potion);
* DECLARRAY(sword);
*
* #ifndef ITEMINLINE
* #define ITEMINLINE INLINE
* #endif
*
* DEFARRAY_BYTYPE(stringarray, char, ITEMINLINE);
* DEFARRAY(potion, ITEMINLINE);
* DEFARRAY(sword, ITEMINLINE);
*
* Then item.c would do "#define ITEMINLINE" before including item.h.
*
* This creates types "struct stringarray", "struct potionarray",
* and "struct swordarray", with operations such as "swordarray_num".
*
* The operations on typed arrays are the same as the operations on
* the base array, except typed.
*/
#define DECLARRAY_BYTYPE(ARRAY, T, INLINE) \
struct ARRAY { \
struct array arr; \
}; \
\
INLINE struct ARRAY *ARRAY##_create(void); \
INLINE void ARRAY##_destroy(struct ARRAY *a); \
INLINE void ARRAY##_init(struct ARRAY *a); \
INLINE void ARRAY##_cleanup(struct ARRAY *a); \
INLINE unsigned ARRAY##_num(const struct ARRAY *a); \
INLINE T *ARRAY##_get(const struct ARRAY *a, unsigned index); \
INLINE void ARRAY##_set(struct ARRAY *a, unsigned index, T *val); \
INLINE int ARRAY##_preallocate(struct ARRAY *a, unsigned num); \
INLINE int ARRAY##_setsize(struct ARRAY *a, unsigned num); \
INLINE int ARRAY##_add(struct ARRAY *a, T *val, unsigned *index_ret); \
INLINE void ARRAY##_remove(struct ARRAY *a, unsigned index)
#define DEFARRAY_BYTYPE(ARRAY, T, INLINE) \
INLINE struct ARRAY * \
ARRAY##_create(void) \
{ \
struct ARRAY *a = kmalloc(sizeof(*a)); \
if (a == NULL) { \
return NULL; \
} \
array_init(&a->arr); \
return a; \
} \
\
INLINE void \
ARRAY##_destroy(struct ARRAY *a) \
{ \
array_cleanup(&a->arr); \
kfree(a); \
} \
\
INLINE void \
ARRAY##_init(struct ARRAY *a) \
{ \
array_init(&a->arr); \
} \
\
INLINE void \
ARRAY##_cleanup(struct ARRAY *a) \
{ \
array_cleanup(&a->arr); \
} \
\
INLINE unsigned \
ARRAY##_num(const struct ARRAY *a) \
{ \
return array_num(&a->arr); \
} \
\
INLINE T * \
ARRAY##_get(const struct ARRAY *a, unsigned index) \
{ \
return (T *)array_get(&a->arr, index); \
} \
\
INLINE void \
ARRAY##_set(struct ARRAY *a, unsigned index, T *val) \
{ \
array_set(&a->arr, index, (void *)val); \
} \
\
INLINE int \
ARRAY##_preallocate(struct ARRAY *a, unsigned num) \
{ \
return array_preallocate(&a->arr, num); \
} \
\
INLINE int \
ARRAY##_setsize(struct ARRAY *a, unsigned num) \
{ \
return array_setsize(&a->arr, num); \
} \
\
INLINE int \
ARRAY##_add(struct ARRAY *a, T *val, unsigned *index_ret) \
{ \
return array_add(&a->arr, (void *)val, index_ret); \
} \
\
INLINE void \
ARRAY##_remove(struct ARRAY *a, unsigned index) \
{ \
array_remove(&a->arr, index); \
}
#define DECLARRAY(T, INLINE) DECLARRAY_BYTYPE(T##array, struct T, INLINE)
#define DEFARRAY(T, INLINE) DEFARRAY_BYTYPE(T##array, struct T, INLINE)
/*
* This is how you declare an array of strings; it works out as
* an array of pointers to char.
*/
DECLARRAY_BYTYPE(stringarray, char, ARRAYINLINE);
DEFARRAY_BYTYPE(stringarray, char, ARRAYINLINE);
#endif /* ARRAY_H */

59
kern/include/bitmap.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2000, 2001
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _BITMAP_H_
#define _BITMAP_H_
/*
* Fixed-size array of bits. (Intended for storage management.)
*
* Functions:
* bitmap_create - allocate a new bitmap object.
* Returns NULL on error.
* bitmap_getdata - return pointer to raw bit data (for I/O).
* bitmap_alloc - locate a cleared bit, set it, and return its index.
* bitmap_mark - set a clear bit by its index.
* bitmap_unmark - clear a set bit by its index.
* bitmap_isset - return whether a particular bit is set or not.
* bitmap_destroy - destroy bitmap.
*/
struct bitmap; /* Opaque. */
struct bitmap *bitmap_create(unsigned nbits);
void *bitmap_getdata(struct bitmap *);
int bitmap_alloc(struct bitmap *, unsigned *index);
void bitmap_mark(struct bitmap *, unsigned index);
void bitmap_unmark(struct bitmap *, unsigned index);
int bitmap_isset(struct bitmap *, unsigned index);
void bitmap_destroy(struct bitmap *);
#endif /* _BITMAP_H_ */

141
kern/include/cdefs.h Normal file
View File

@@ -0,0 +1,141 @@
/*
* Copyright (c) 2003, 2006, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _CDEFS_H_
#define _CDEFS_H_
/*
* Some miscellaneous C language definitions and related matters.
*/
/*
* Build-time assertion. Doesn't generate any code. The error message
* on failure is less than ideal, but you can't have everything.
*/
#define COMPILE_ASSERT(x) ((void)sizeof(struct { unsigned : ((x)?1:-1); }))
/*
* Handy macro for the number of elements in a static array.
*/
#define ARRAYCOUNT(arr) (sizeof(arr) / sizeof((arr)[0]))
/*
* Tell GCC how to check printf formats. Also tell it about functions
* that don't return, as this is helpful for avoiding bogus warnings
* about uninitialized variables.
*/
#ifdef __GNUC__
#define __PF(a,b) __attribute__((__format__(__printf__, a, b)))
#define __DEAD __attribute__((__noreturn__))
#define __UNUSED __attribute__((__unused__))
#else
#define __PF(a,b)
#define __DEAD
#define __UNUSED
#endif
/*
* Material for supporting inline functions.
*
* A function marked inline can be handled by the compiler in three
* ways: in addition to possibly inlining into the code for other
* functions, the compiler can (1) generate a file-static out-of-line
* copy of the function, (2) generate a global out-of-line copy of the
* function, or (3) generate no out-of-line copy of the function.
*
* None of these alone is thoroughly satisfactory. Since an inline
* function may or may not be inlined at the compiler's discretion, if
* no out-of-line copy exists the build may fail at link time with
* undefined symbols. Meanwhile, if the compiler is told to generate a
* global out-of-line copy, it will generate one such copy for every
* source file where the inline definition is visible; since inline
* functions tend to appear in header files, this leads to multiply
* defined symbols and build failure. The file-static option isn't
* really an improvement, either: one tends to get compiler warnings
* about inline functions that haven't been used, which for any
* particular source file tends to be at least some of the ones that
* have been defined. Furthermore, this method leads to one
* out-of-line copy of the inline function per source file that uses
* it, which not only wastes space but makes debugging painful.
*
* Therefore, we use the following scheme.
*
* In the header file containing the inline functions for the module
* "foo", we put
*
* #ifndef FOO_INLINE
* #define FOO_INLINE INLINE
* #endif
*
* where INLINE selects the compiler behavior that does *not* generate
* an out-of-line version. Then we define the inline functions
* themselves as FOO_INLINE. This allows the compiler to inline the
* functions anywhere it sees fit with a minimum of hassles. Then,
* when compiling foo.c, before including headers we put
*
* #define FOO_INLINE // empty
*
* which causes the inline functions to appear as ordinary function
* definitions, not inline at all, when foo.c is compiled. This
* ensures that an out-of-line definition appears, and furthermore
* ensures that the out-of-line definition is the same as the inline
* definition.
*
* The situation is complicated further because gcc is historically
* not compliant with the C standard. In C99, "inline" means "do not
* generate an out-of-line copy" and "extern inline" means "generate a
* global out-of-line copy". In gcc, going back far longer than C99,
* the meanings were reversed. This eventually changed, but varies
* with compiler version and options. The macro __GNUC_STDC_INLINE__
* is defined if the behavior is C99-compliant.
*
* (Note that inline functions that appear only within a single source
* file can safely be declared "static inline"; to avoid whining from
* compiler in some contexts you may also want to add __UNUSED to
* that.)
*/
#if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__)
/* gcc's non-C99 inline semantics */
#define INLINE extern inline
#elif defined(__STDC__) && __STDC_VERSION__ >= 199901L
/* C99 */
#define INLINE inline
#else
/* something else; static inline is safest */
#define INLINE static __UNUSED inline
#endif
#endif /* _CDEFS_H_ */

83
kern/include/clock.h Normal file
View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _CLOCK_H_
#define _CLOCK_H_
/*
* Time-related definitions.
*/
#include <kern/time.h>
/*
* hardclock() is called on every CPU HZ times a second, possibly only
* when the CPU is not idle, for scheduling.
*/
/* hardclocks per second */
#define HZ 100
void hardclock_bootstrap(void);
void hardclock(void);
/*
* timerclock() is called on one CPU once a second to allow simple
* timed operations. (This is a fairly simpleminded interface.)
*/
void timerclock(void);
/*
* gettime() may be used to fetch the current time of day.
*/
void gettime(struct timespec *ret);
/*
* arithmetic on times
*
* add: ret = t1 + t2
* sub: ret = t1 - t2
*/
void timespec_add(const struct timespec *t1,
const struct timespec *t2,
struct timespec *ret);
void timespec_sub(const struct timespec *t1,
const struct timespec *t2,
struct timespec *ret);
/*
* clocksleep() suspends execution for the requested number of seconds,
* like userlevel sleep(3). (Don't confuse it with wchan_sleep.)
*/
void clocksleep(int seconds);
#endif /* _CLOCK_H_ */

73
kern/include/copyinout.h Normal file
View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _COPYINOUT_H_
#define _COPYINOUT_H_
/*
* copyin/copyout/copyinstr/copyoutstr are standard BSD kernel functions.
*
* copyin copies LEN bytes from a user-space address USERSRC to a
* kernel-space address DEST.
*
* copyout copies LEN bytes from a kernel-space address SRC to a
* user-space address USERDEST.
*
* copyinstr copies a null-terminated string of at most LEN bytes from
* a user-space address USERSRC to a kernel-space address DEST, and
* returns the actual length of string found in GOT. DEST is always
* null-terminated on success. LEN and GOT include the null terminator.
*
* copyoutstr copies a null-terminated string of at most LEN bytes from
* a kernel-space address SRC to a user-space address USERDEST, and
* returns the actual length of string found in GOT. DEST is always
* null-terminated on success. LEN and GOT include the null terminator.
*
* All of these functions return 0 on success, EFAULT if a memory
* addressing error was encountered, or (for the string versions)
* ENAMETOOLONG if the space available was insufficient.
*
* NOTE that the order of the arguments is the same as bcopy() or
* cp/mv, that is, source on the left, NOT the same as strcpy().
* The const qualifiers and types will help protect against mistakes
* in this regard but are obviously not foolproof.
*
* These functions are machine-dependent; however, a common version
* that can be used by a number of machine types is found in
* vm/copyinout.c.
*/
int copyin(const_userptr_t usersrc, void *dest, size_t len);
int copyout(const void *src, userptr_t userdest, size_t len);
int copyinstr(const_userptr_t usersrc, char *dest, size_t len, size_t *got);
int copyoutstr(const char *src, userptr_t userdest, size_t len, size_t *got);
#endif /* _COPYINOUT_H_ */

174
kern/include/cpu.h Normal file
View File

@@ -0,0 +1,174 @@
/*
* Copyright (c) 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _CPU_H_
#define _CPU_H_
#include <spinlock.h>
#include <threadlist.h>
#include <machine/vm.h> /* for TLBSHOOTDOWN_MAX */
/*
* Per-cpu structure
*
* Note: curcpu is defined by <current.h>.
*
* cpu->c_self should always be used when *using* the address of curcpu
* (as opposed to merely dereferencing it) in case curcpu is defined as
* a pointer with a fixed address and a per-cpu mapping in the MMU.
*/
struct cpu {
/*
* Fixed after allocation.
*/
struct cpu *c_self; /* Canonical address of this struct */
unsigned c_number; /* This cpu's cpu number */
unsigned c_hardware_number; /* Hardware-defined cpu number */
/*
* Accessed only by this cpu.
*/
struct thread *c_curthread; /* Current thread on cpu */
struct threadlist c_zombies; /* List of exited threads */
unsigned c_hardclocks; /* Counter of hardclock() calls */
unsigned c_spinlocks; /* Counter of spinlocks held */
/*
* Accessed by other cpus.
* Protected by the runqueue lock.
*/
bool c_isidle; /* True if this cpu is idle */
struct threadlist c_runqueue; /* Run queue for this cpu */
struct spinlock c_runqueue_lock;
/*
* Accessed by other cpus.
* Protected by the IPI lock.
*
* If c_numshootdown is -1 (TLBSHOOTDOWN_ALL), all mappings
* should be invalidated. This is used if more than
* TLBSHOOTDOWN_MAX mappings are going to be invalidated at
* once. TLBSHOOTDOWN_MAX is MD and chosen based on when it
* becomes more efficient just to flush the whole TLB.
*
* struct tlbshootdown is machine-dependent and might
* reasonably be either an address space and vaddr pair, or a
* paddr, or something else.
*/
uint32_t c_ipi_pending; /* One bit for each IPI number */
struct tlbshootdown c_shootdown[TLBSHOOTDOWN_MAX];
int c_numshootdown;
struct spinlock c_ipi_lock;
};
#define TLBSHOOTDOWN_ALL (-1)
/*
* Initialization functions.
*
* cpu_create creates a cpu; it is suitable for calling from driver-
* or bus-specific code that looks for secondary CPUs.
*
* cpu_create calls cpu_machdep_init.
*
* cpu_start_secondary is the platform-dependent assembly language
* entry point for new CPUs; it can be found in start.S. It calls
* cpu_hatch after having claimed the startup stack and thread created
* for the cpu.
*/
struct cpu *cpu_create(unsigned hardware_number);
void cpu_machdep_init(struct cpu *);
/*ASMLINKAGE*/ void cpu_start_secondary(void);
void cpu_hatch(unsigned software_number);
/*
* Produce a string describing the CPU type.
*/
void cpu_identify(char *buf, size_t max);
/*
* Hardware-level interrupt on/off, for the current CPU.
*
* These should only be used by the spl code.
*/
void cpu_irqoff(void);
void cpu_irqon(void);
/*
* Idle or shut down (respectively) the processor.
*
* cpu_idle() sits around (in a low-power state if possible) until it
* thinks something interesting may have happened, such as an
* interrupt. Then it returns. (It may be wrong, so it should always
* be called in a loop checking some other condition.) It must be
* called with interrupts off to avoid race conditions, although
* interrupts may be delivered before it returns.
*
* cpu_halt sits around (in a low-power state if possible) until the
* external reset is pushed. Interrupts should be disabled. It does
* not return. It should not allow interrupts to be delivered.
*/
void cpu_idle(void);
void cpu_halt(void);
/*
* Interprocessor interrupts.
*
* From time to time it is necessary to poke another CPU. System
* boards of multiprocessor machines provide a way to do this.
*
* TLB shootdown is done by the VM system when more than one processor
* has (or may have) a page mapped in the MMU and it is being changed
* or otherwise needs to be invalidated across all CPUs.
*
* ipi_send sends an IPI to one CPU.
* ipi_broadcast sends an IPI to all CPUs except the current one.
* ipi_tlbshootdown is like ipi_send but carries TLB shootdown data.
*
* interprocessor_interrupt is called on the target CPU when an IPI is
* received.
*/
/* IPI types */
#define IPI_PANIC 0 /* System has called panic() */
#define IPI_OFFLINE 1 /* CPU is requested to go offline */
#define IPI_UNIDLE 2 /* Runnable threads are available */
#define IPI_TLBSHOOTDOWN 3 /* MMU mapping(s) need invalidation */
void ipi_send(struct cpu *target, int code);
void ipi_broadcast(int code);
void ipi_tlbshootdown(struct cpu *target, const struct tlbshootdown *mapping);
void interprocessor_interrupt(void);
#endif /* _CPU_H_ */

93
kern/include/current.h Normal file
View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _CURRENT_H_
#define _CURRENT_H_
/*
* Definition of curcpu and curthread.
*
* The machine-dependent header should define either curcpu or curthread
* as a macro (but not both); then we use one to get the other, and include
* the header file needed to make that reference. (These includes are why
* this file isn't rolled into either cpu.h or thread.h.)
*
* This material is machine-dependent because on some platforms it is
* better/easier to keep track of curcpu and make curthread be
* curcpu->c_curthread, and on others to keep track of curthread and
* make curcpu be curthread->t_cpu.
*
* Either way we don't want retrieving curthread or curcpu to be
* expensive; digging around in system board registers and whatnot is
* not a very good idea. So we want to keep either curthread or curcpu
* on-chip somewhere in some fashion.
*
* There are various possible approaches; for example, one might use
* the MMU on each CPU to map that CPU's cpu structure to a fixed
* virtual address that's the same on all CPUs. Then curcpu can be a
* constant. (But one has to remember to use curcpu->c_self as the
* canonical form of the pointer anywhere that's visible to other
* CPUs.) On some CPUs the CPU number or cpu structure base address
* can be stored in a supervisor-mode register, where it can be set up
* during boot and then left alone. An alternative approach is to
* reserve a register to hold curthread, and update it during context
* switch.
*
* See each platform's machine/current.h for a discussion of what it
* does and why.
*/
#include <machine/current.h>
#if defined(__NEED_CURTHREAD)
#include <cpu.h>
#define curthread curcpu->c_curthread
#define CURCPU_EXISTS() (curcpu != NULL)
#endif
#if defined(__NEED_CURCPU)
#include <thread.h>
#define curcpu curthread->t_cpu
#define CURCPU_EXISTS() (curthread != NULL)
#endif
/*
* Definition of curproc.
*
* curproc is always the current thread's process.
*/
#define curproc (curthread->t_proc)
#endif /* _CURRENT_H_ */

87
kern/include/device.h Normal file
View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _DEVICE_H_
#define _DEVICE_H_
/*
* Devices.
*/
struct uio; /* in <uio.h> */
/*
* Filesystem-namespace-accessible device.
*/
struct device {
const struct device_ops *d_ops;
blkcnt_t d_blocks;
blksize_t d_blocksize;
dev_t d_devnumber; /* serial number for this device */
void *d_data; /* device-specific data */
};
/*
* Device operations.
* devop_eachopen - called on each open call to allow denying the open
* devop_io - for both reads and writes (the uio indicates the direction)
* devop_ioctl - miscellaneous control operations
*/
struct device_ops {
int (*devop_eachopen)(struct device *, int flags_from_open);
int (*devop_io)(struct device *, struct uio *);
int (*devop_ioctl)(struct device *, int op, userptr_t data);
};
/*
* Macros to shorten the calling sequences.
*/
#define DEVOP_EACHOPEN(d, f) ((d)->d_ops->devop_eachopen(d, f))
#define DEVOP_IO(d, u) ((d)->d_ops->devop_io(d, u))
#define DEVOP_IOCTL(d, op, p) ((d)->d_ops->devop_ioctl(d, op, p))
/* Create vnode for a vfs-level device. */
struct vnode *dev_create_vnode(struct device *dev);
/* Undo dev_create_vnode. */
void dev_uncreate_vnode(struct vnode *vn);
/* Initialization functions for builtin vfs-level devices. */
void devnull_create(void);
/* Function that kicks off device probe and attach. */
void dev_bootstrap(void);
#endif /* _DEVICE_H_ */

200
kern/include/elf.h Normal file
View File

@@ -0,0 +1,200 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ELF_H_
#define _ELF_H_
/*
* Simplified ELF definitions for OS/161 and System/161.
*
* Restrictions:
* 32-bit only
* No support for .o files or linker structures
* Does not define all the random symbols a standard elf header would.
*/
/* Get MD bits */
#include <machine/elf.h>
/*
* ELF file header. This appears at the very beginning of an ELF file.
*/
#define ELF_NIDENT 16
typedef struct {
unsigned char e_ident[ELF_NIDENT]; /* magic number et al. */
uint16_t e_type; /* type of file this is */
uint16_t e_machine; /* processor type file is for */
uint32_t e_version; /* ELF version */
uint32_t e_entry; /* address of program entry point */
uint32_t e_phoff; /* location in file of phdrs */
uint32_t e_shoff; /* ignore */
uint32_t e_flags; /* ignore */
uint16_t e_ehsize; /* actual size of file header */
uint16_t e_phentsize; /* actual size of phdr */
uint16_t e_phnum; /* number of phdrs */
uint16_t e_shentsize; /* ignore */
uint16_t e_shnum; /* ignore */
uint16_t e_shstrndx; /* ignore */
} Elf32_Ehdr;
/* Offsets for the 1-byte fields within e_ident[] */
#define EI_MAG0 0 /* '\177' */
#define EI_MAG1 1 /* 'E' */
#define EI_MAG2 2 /* 'L' */
#define EI_MAG3 3 /* 'F' */
#define EI_CLASS 4 /* File class - always ELFCLASS32 */
#define EI_DATA 5 /* Data encoding - ELFDATA2LSB or ELFDATA2MSB*/
#define EI_VERSION 6 /* ELF version - EV_CURRENT*/
#define EI_OSABI 7 /* OS/syscall ABI identification */
#define EI_ABIVERSION 8 /* syscall ABI version */
#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
/* Values for these fields */
/* For e_ident[EI_MAG0..3] */
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
/* For e_ident[EI_CLASS] */
#define ELFCLASSNONE 0 /* Invalid class */
#define ELFCLASS32 1 /* 32-bit objects */
#define ELFCLASS64 2 /* 64-bit objects */
/* e_ident[EI_DATA] */
#define ELFDATANONE 0 /* Invalid data encoding */
#define ELFDATA2LSB 1 /* 2's complement values, LSB first */
#define ELFDATA2MSB 2 /* 2's complement values, MSB first */
/* e_ident[EI_VERSION] */
#define EV_NONE 0 /* Invalid version */
#define EV_CURRENT 1 /* Current version */
/* e_ident[EI_OSABI] */
#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
#define ELFOSABI_HPUX 1 /* HP-UX operating system */
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
/*
* Values for e_type
*/
#define ET_NONE 0 /* No file type */
#define ET_REL 1 /* Relocatable file */
#define ET_EXEC 2 /* Executable file */
#define ET_DYN 3 /* Shared object file */
#define ET_CORE 4 /* Core file */
#define ET_NUM 5
/*
* Values for e_machine
*/
#define EM_NONE 0 /* No machine */
#define EM_M32 1 /* AT&T WE 32100 */
#define EM_SPARC 2 /* SPARC */
#define EM_386 3 /* Intel 80386 */
#define EM_68K 4 /* Motorola 68000 */
#define EM_88K 5 /* Motorola 88000 */
#define EM_486 6 /* Intel 80486 */
#define EM_860 7 /* Intel 80860 */
#define EM_MIPS 8 /* MIPS I Architecture */
#define EM_S370 9 /* Amdahl UTS on System/370 */
#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
#define EM_NCUBE 16 /* NCube XXX reserved */
#define EM_VPP500 17 /* Fujitsu VPP500 */
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
#define EM_960 19 /* Intel 80960 */
#define EM_PPC 20 /* PowerPC */
#define EM_V800 36 /* NEC V800 */
#define EM_FR20 37 /* Fujitsu FR20 */
#define EM_RH32 38 /* TRW RH-32 */
#define EM_RCE 39 /* Motorola RCE */
#define EM_ARM 40 /* Advanced RISC Machines ARM */
#define EM_ALPHA 41 /* DIGITAL Alpha */
#define EM_SH 42 /* Hitachi Super-H */
#define EM_SPARCV9 43 /* SPARC Version 9 */
#define EM_TRICORE 44 /* Siemens Tricore */
#define EM_ARC 45 /* Argonaut RISC Core */
#define EM_H8_300 46 /* Hitachi H8/300 */
#define EM_H8_300H 47 /* Hitachi H8/300H */
#define EM_H8S 48 /* Hitachi H8S */
#define EM_H8_500 49 /* Hitachi H8/500 */
#define EM_IA_64 50 /* Intel Merced Processor */
#define EM_MIPS_X 51 /* Stanford MIPS-X */
#define EM_COLDFIRE 52 /* Motorola Coldfire */
#define EM_68HC12 53 /* Motorola MC68HC12 */
#define EM_VAX 75 /* DIGITAL VAX */
#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
#define EM_NUM 36903
/*
* "Program Header" - runtime segment header.
* There are Ehdr.e_phnum of these located at one position within the file.
*
* Note: if p_memsz > p_filesz, the leftover space should be zero-filled.
*/
typedef struct {
uint32_t p_type; /* Type of segment */
uint32_t p_offset; /* Location of data within file */
uint32_t p_vaddr; /* Virtual address */
uint32_t p_paddr; /* Ignore */
uint32_t p_filesz; /* Size of data within file */
uint32_t p_memsz; /* Size of data to be loaded into memory*/
uint32_t p_flags; /* Flags */
uint32_t p_align; /* Required alignment - can ignore */
} Elf32_Phdr;
/* values for p_type */
#define PT_NULL 0 /* Program header table entry unused */
#define PT_LOAD 1 /* Loadable program segment */
#define PT_DYNAMIC 2 /* Dynamic linking information */
#define PT_INTERP 3 /* Program interpreter */
#define PT_NOTE 4 /* Auxiliary information */
#define PT_SHLIB 5 /* Reserved, unspecified semantics */
#define PT_PHDR 6 /* Entry for header table itself */
#define PT_NUM 7
#define PT_MIPS_REGINFO 0x70000000
/* values for p_flags */
#define PF_R 0x4 /* Segment is readable */
#define PF_W 0x2 /* Segment is writable */
#define PF_X 0x1 /* Segment is executable */
typedef Elf32_Ehdr Elf_Ehdr;
typedef Elf32_Phdr Elf_Phdr;
#endif /* _ELF_H_ */

58
kern/include/emufs.h Normal file
View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _EMUFS_H_
#define _EMUFS_H_
/*
* Get abstract structure definitions
*/
#include <fs.h>
#include <vnode.h>
/*
* Our structures
*/
struct emufs_vnode {
struct vnode ev_v; /* abstract vnode structure */
struct emu_softc *ev_emu; /* device */
uint32_t ev_handle; /* file handle */
};
struct emufs_fs {
struct fs ef_fs; /* abstract filesystem structure */
struct emu_softc *ef_emu; /* device */
struct emufs_vnode *ef_root; /* root vnode */
struct vnodearray *ef_vnodes; /* table of loaded vnodes */
};
#endif /* _EMUFS_H_ */

55
kern/include/endian.h Normal file
View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ENDIAN_H_
#define _ENDIAN_H_
#include <kern/endian.h>
/*
* Byte swap functions for the kernel.
*/
uint16_t bswap16(uint16_t);
uint32_t bswap32(uint32_t);
uint64_t bswap64(uint64_t);
uint16_t ntohs(uint16_t);
uint16_t htons(uint16_t);
uint32_t ntohl(uint32_t);
uint32_t htonl(uint32_t);
uint64_t ntohll(uint64_t);
uint64_t htonll(uint64_t);
/* Utility functions for handling 64-bit values; see bswap.c for description */
void join32to64(uint32_t x1, uint32_t x2, uint64_t *y2);
void split64to32(uint64_t x, uint32_t *y1, uint32_t *y2);
#endif /* _ENDIAN_H_ */

91
kern/include/fs.h Normal file
View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _FS_H_
#define _FS_H_
struct vnode; /* in vnode.h */
/*
* Abstract file system. (Or device accessible as a file.)
*
* fs_data is a pointer to filesystem-specific data.
*/
struct fs {
void *fs_data;
const struct fs_ops *fs_ops;
};
/*
* Abstraction operations on a file system:
*
* fsop_sync - Flush all dirty buffers to disk.
* fsop_getvolname - Return volume name of filesystem.
* fsop_getroot - Return root vnode of filesystem.
* fsop_unmount - Attempt unmount of filesystem.
*
* fsop_getvolname may return NULL on filesystem types that don't
* support the concept of a volume name. The string returned is
* assumed to point into the filesystem's private storage and live
* until unmount time.
*
* If the volume name changes on the fly, there is no way at present
* to make sure such changes don't cause name conflicts. So it probably
* should be considered fixed.
*
* fsop_getroot should increment the refcount of the vnode returned.
* It should not ever return NULL.
*
* If fsop_unmount returns an error, the filesystem stays mounted, and
* consequently the struct fs instance should remain valid. On success,
* however, the filesystem object and all storage associated with the
* filesystem should have been discarded/released.
*/
struct fs_ops {
int (*fsop_sync)(struct fs *);
const char *(*fsop_getvolname)(struct fs *);
int (*fsop_getroot)(struct fs *, struct vnode **);
int (*fsop_unmount)(struct fs *);
};
/*
* Macros to shorten the calling sequences.
*/
#define FSOP_SYNC(fs) ((fs)->fs_ops->fsop_sync(fs))
#define FSOP_GETVOLNAME(fs) ((fs)->fs_ops->fsop_getvolname(fs))
#define FSOP_GETROOT(fs, ret) ((fs)->fs_ops->fsop_getroot(fs, ret))
#define FSOP_UNMOUNT(fs) ((fs)->fs_ops->fsop_unmount(fs))
/* Initialization functions for builtin fake file systems. */
void semfs_bootstrap(void);
#endif /* _FS_H_ */

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_ENDIAN_H_
#define _KERN_ENDIAN_H_
/*
* Machine-independent and exported endianness definitions.
*
* Note: get these via <endian.h> in the kernel and <arpa/inet.h> in
* userland.
*
* This is the historic BSD way of defining endianness.
*/
#define _LITTLE_ENDIAN 1234
#define _BIG_ENDIAN 4321
#define _PDP_ENDIAN 3412
/* This defines _BYTE_ORDER to one of the above. */
#include <kern/machine/endian.h>
#endif /* _KERN_ENDIAN_H_ */

114
kern/include/kern/errmsg.h Normal file
View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_ERRMSG_H_
#define _KERN_ERRMSG_H_
/*
* Error strings.
* This table must agree with kern/errno.h.
*
* Note that since this actually defines sys_errlist and sys_nerrlist, it
* should only be included in one file. For the kernel, that file is
* lib/misc.c; for userland it's lib/libc/strerror.c.
*/
const char *const sys_errlist[] = {
"Operation succeeded", /* 0 */
"Function not implemented", /* ENOSYS */
"(undefined error 2)", /* unused */
"Out of memory", /* ENOMEM */
"Operation would block", /* EAGAIN (also EWOULDBLOCK) */
"Interrupted system call", /* EINTR */
"Bad memory reference", /* EFAULT */
"String too long", /* ENAMETOOLONG */
"Invalid argument", /* EINVAL */
"Operation not permitted", /* EPERM */
"Permission denied", /* EACCES */
"Too many processes", /* EMPROC (EPROCLIM in Unix) */
"Too many processes in system",/* ENPROC */
"File is not executable", /* ENOEXEC */
"Argument list too long", /* E2BIG */
"No such process", /* ESRCH */
"No child processes", /* ECHILD */
"Not a directory", /* ENOTDIR */
"Is a directory", /* EISDIR */
"No such file or directory", /* ENOENT */
"Too many levels of symbolic links",/* ELOOP */
"Directory not empty", /* ENOTEMPTY */
"File or object exists", /* EEXIST */
"Too many hard links", /* EMLINK */
"Cross-device link", /* EXDEV */
"No such device", /* ENODEV */
"Device not available", /* ENXIO */
"Device or resource busy", /* EBUSY */
"Too many open files", /* EMFILE */
"Too many open files in system",/* ENFILE */
"Bad file number", /* EBADF */
"Invalid or inappropriate ioctl",/* EIOCTL (ENOTTY in Unix) */
"Input/output error", /* EIO */
"Illegal seek", /* ESPIPE */
"Broken pipe", /* EPIPE */
"Read-only file system", /* EROFS */
"No space left on device", /* ENOSPC */
"Disc quota exceeded", /* EDQUOT */
"File too large", /* EFBIG */
"Invalid file type or format",/* EFTYPE */
"Argument out of range", /* EDOM */
"Result out of range", /* ERANGE */
"Invalid multibyte character sequence",/* EILSEQ */
"Not a socket", /* ENOTSOCK */
"Is a socket", /* EISSOCK (EOPNOTSUPP in Unix) */
"Socket is already connected",/* EISCONN */
"Socket is not connected", /* ENOTCONN */
"Socket has been shut down", /* ESHUTDOWN */
"Protocol family not supported",/* EPFNOSUPPORT */
"Socket type not supported", /* ESOCKTNOSUPPORT */
"Protocol not supported", /* EPROTONOSUPPORT */
"Protocol wrong type for socket",/* EPROTOTYPE */
"Address family not supported by protocol family",/* EAFNOSUPPORT */
"Protocol option not available",/* ENOPROTOOPT */
"Address already in use", /* EADDRINUSE */
"Cannot assign requested address",/* EADDRNOTAVAIL */
"Network is down", /* ENETDOWN */
"Network is unreachable", /* ENETUNREACH */
"Host is down", /* EHOSTDOWN */
"Host is unreachable", /* EHOSTUNREACH */
"Connection refused", /* ECONNREFUSED */
"Connection timed out", /* ETIMEDOUT */
"Connection reset by peer", /* ECONNRESET */
"Message too large", /* EMSGSIZE */
"Threads operation not supported",/* ENOTSUP */
};
/*
* Number of entries in sys_errlist.
*/
const int sys_nerr = sizeof(sys_errlist)/sizeof(const char *);
#endif /* _KERN_ERRMSG_H_ */

111
kern/include/kern/errno.h Normal file
View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_ERRNO_H_
#define _KERN_ERRNO_H_
/*
* If you change this, be sure to make appropriate corresponding changes
* to kern/errmsg.h as well. You might also want to change the man page
* for errno to document the new error.
*
* This has been changed relative to OS/161 1.x to make the grouping
* more logical.
*
* Also note that this file has to work from assembler, so it should
* contain only symbolic constants.
*/
#define ENOSYS 1 /* Function not implemented */
/* unused 2 */
#define ENOMEM 3 /* Out of memory */
#define EAGAIN 4 /* Operation would block */
#define EINTR 5 /* Interrupted system call */
#define EFAULT 6 /* Bad memory reference */
#define ENAMETOOLONG 7 /* String too long */
#define EINVAL 8 /* Invalid argument */
#define EPERM 9 /* Operation not permitted */
#define EACCES 10 /* Permission denied */
#define EMPROC 11 /* Too many processes */
#define ENPROC 12 /* Too many processes in system */
#define ENOEXEC 13 /* File is not executable */
#define E2BIG 14 /* Argument list too long */
#define ESRCH 15 /* No such process */
#define ECHILD 16 /* No child processes */
#define ENOTDIR 17 /* Not a directory */
#define EISDIR 18 /* Is a directory */
#define ENOENT 19 /* No such file or directory */
#define ELOOP 20 /* Too many levels of symbolic links */
#define ENOTEMPTY 21 /* Directory not empty */
#define EEXIST 22 /* File or object exists */
#define EMLINK 23 /* Too many hard links */
#define EXDEV 24 /* Cross-device link */
#define ENODEV 25 /* No such device */
#define ENXIO 26 /* Device not available */
#define EBUSY 27 /* Device or resource busy */
#define EMFILE 28 /* Too many open files */
#define ENFILE 29 /* Too many open files in system */
#define EBADF 30 /* Bad file number */
#define EIOCTL 31 /* Invalid or inappropriate ioctl */
#define EIO 32 /* Input/output error */
#define ESPIPE 33 /* Illegal seek */
#define EPIPE 34 /* Broken pipe */
#define EROFS 35 /* Read-only file system */
#define ENOSPC 36 /* No space left on device */
#define EDQUOT 37 /* Disc quota exceeded */
#define EFBIG 38 /* File too large */
#define EFTYPE 39 /* Invalid file type or format */
#define EDOM 40 /* Argument out of range */
#define ERANGE 41 /* Result out of range */
#define EILSEQ 42 /* Invalid multibyte character sequence */
#define ENOTSOCK 43 /* Not a socket */
#define EISSOCK 44 /* Is a socket */
#define EISCONN 45 /* Socket is already connected */
#define ENOTCONN 46 /* Socket is not connected */
#define ESHUTDOWN 47 /* Socket has been shut down */
#define EPFNOSUPPORT 48 /* Protocol family not supported */
#define ESOCKTNOSUPPORT 49 /* Socket type not supported */
#define EPROTONOSUPPORT 50 /* Protocol not supported */
#define EPROTOTYPE 51 /* Protocol wrong type for socket */
#define EAFNOSUPPORT 52 /* Address family not supported by protocol family */
#define ENOPROTOOPT 53 /* Protocol option not available */
#define EADDRINUSE 54 /* Address already in use */
#define EADDRNOTAVAIL 55 /* Cannot assign requested address */
#define ENETDOWN 56 /* Network is down */
#define ENETUNREACH 57 /* Network is unreachable */
#define EHOSTDOWN 58 /* Host is down */
#define EHOSTUNREACH 59 /* Host is unreachable */
#define ECONNREFUSED 60 /* Connection refused */
#define ETIMEDOUT 61 /* Connection timed out */
#define ECONNRESET 62 /* Connection reset by peer */
#define EMSGSIZE 63 /* Message too large */
#define ENOTSUP 64 /* Threads operation not supported */
#endif /* _KERN_ERRNO_H_ */

100
kern/include/kern/fcntl.h Normal file
View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_FCNTL_H_
#define _KERN_FCNTL_H_
/*
* Constants for libc's <fcntl.h>.
*/
/*
* Important
*/
/* Flags for open: choose one of these: */
#define O_RDONLY 0 /* Open for read */
#define O_WRONLY 1 /* Open for write */
#define O_RDWR 2 /* Open for read and write */
/* then or in any of these: */
#define O_CREAT 4 /* Create file if it doesn't exist */
#define O_EXCL 8 /* With O_CREAT, fail if file already exists */
#define O_TRUNC 16 /* Truncate file upon open */
#define O_APPEND 32 /* All writes happen at EOF (optional feature) */
#define O_NOCTTY 64 /* Required by POSIX, != 0, but does nothing */
/* Additional related definition */
#define O_ACCMODE 3 /* mask for O_RDONLY/O_WRONLY/O_RDWR */
/*
* Not so important
*/
/* operation codes for flock() */
#define LOCK_SH 1 /* shared lock */
#define LOCK_EX 2 /* exclusive lock */
#define LOCK_UN 3 /* release the lock */
#define LOCK_NB 4 /* flag: don't block */
/*
* Mostly pretty useless
*/
/* fcntl() operations */
#define F_DUPFD 0 /* like dup() but not quite */
#define F_GETFD 1 /* get per-handle flags */
#define F_SETFD 2 /* set per-handle flags */
#define F_GETFL 3 /* get per-file flags (O_* open flags) */
#define F_SETFL 4 /* set per-file flags (O_* open flags) */
#define F_GETOWN 5 /* get process/pgroup for SIGURG and SIGIO */
#define F_SETOWN 6 /* set process/pgroup for SIGURG and SIGIO */
#define F_GETLK 7 /* inspect record locks */
#define F_SETLK 8 /* acquire record locks nonblocking */
#define F_SETLKW 9 /* acquire record locks and wait */
/* flag for F_GETFD and F_SETFD */
#define FD_CLOEXEC 1 /* close-on-exec */
/* modes for fcntl (F_GETLK/SETLK) locking */
#define F_RDLCK 0 /* shared lock */
#define F_WRLCK 1 /* exclusive lock */
#define F_UNLCK 2 /* unlock */
/* struct for fcntl (F_GETLK/SETLK) locking */
struct flock {
off_t l_start; /* place in file */
int l_whence; /* SEEK_SET, SEEK_CUR, or SEEK_END */
int l_type; /* F_RDLCK or F_WRLCK */
off_t l_len; /* length of locked region */
pid_t l_pid; /* process that holds the lock */
};
#endif /* _KERN_FCNTL_H_ */

39
kern/include/kern/ioctl.h Normal file
View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_IOCTL_H_
#define _KERN_IOCTL_H_
/*
* ioctl operation codes
*/
/* (none yet) */
#endif /* _KERN_IOCTL_H_*/

68
kern/include/kern/iovec.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_IOVEC_H_
#define _KERN_IOVEC_H_
/*
* iovec structure, used in the readv/writev scatter/gather I/O calls,
* and within the kernel for keeping track of blocks of data for I/O.
*/
struct iovec {
/*
* For maximum type safety, when in the kernel, distinguish
* user pointers from kernel pointers.
*
* (A pointer is a user pointer if it *came* from userspace,
* not necessarily if it *points* to userspace. If a system
* call passes 0xdeadbeef, it points to the kernel, but it's
* still a user pointer.)
*
* In userspace, there are only user pointers; also, the name
* iov_base is defined by POSIX.
*
* Note that to work properly (without extra unwanted fiddling
* around) this scheme requires that void* and userptr_t have
* the same machine representation. Machines where this isn't
* true are theoretically possible under the C standard, but
* do not exist in practice.
*/
#ifdef _KERNEL
union {
userptr_t iov_ubase; /* user-supplied pointer */
void *iov_kbase; /* kernel-supplied pointer */
};
#else
void *iov_base; /* user-supplied pointer */
#endif
size_t iov_len; /* Length of data */
};
#endif /* _KERN_IOVEC_H_ */

109
kern/include/kern/limits.h Normal file
View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_LIMITS_H_
#define _KERN_LIMITS_H_
/*
* Constants for libc's <limits.h> - system limits.
*
* The symbols are prefixed with __ here to avoid namespace pollution
* in libc. Use <limits.h> (in either userspace or the kernel) to get
* the proper names.
*
* These are Unix-style limits that Unix defines; you can change them
* around or add others as needed or as are appropriate to your system
* design.
*
* Likewise, the default values provided here are fairly reasonable,
* but you can change them around pretty freely and userspace code
* should adapt. Do change these as needed to match your
* implementation.
*/
/*
* Important, both as part of the system call API and for system behavior.
*
* 255 for NAME_MAX and 1024 for PATH_MAX are conventional. ARG_MAX
* should be at least 16K. In real systems it often runs to 256K or
* more.
*/
/* Longest filename (without directory) not including null terminator */
#define __NAME_MAX 255
/* Longest full path name */
#define __PATH_MAX 1024
/* Max bytes for an exec function (should be at least 16K) */
#define __ARG_MAX (64 * 1024)
/*
* Important for system behavior, but not a big part of the API.
*
* Most modern systems don't have OPEN_MAX at all, and instead go by
* whatever limit is set with setrlimit().
*/
/* Min value for a process ID (that can be assigned to a user process) */
#define __PID_MIN 2
/* Max value for a process ID (change this to match your implementation) */
#define __PID_MAX 32767
/* Max open files per process */
#define __OPEN_MAX 128
/* Max bytes for atomic pipe I/O -- see description in the pipe() man page */
#define __PIPE_BUF 512
/*
* Not so important parts of the API. (Especially in OS/161 where we
* don't do credentials by default.)
*/
/* Max number of supplemental group IDs in process credentials */
#define __NGROUPS_MAX 32
/* Max login name size (for setlogin/getlogin), incl. null */
#define __LOGIN_NAME_MAX 17
/*
* Not very important at all.
*/
/* Max number of iovec structures at once for readv/writev/preadv/pwritev */
#define __IOV_MAX 1024
#endif /* _KERN_LIMITS_H_ */

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_REBOOT_H_
#define _KERN_REBOOT_H_
/*
* Constants for libc's <sys/reboot.h> and the reboot() system call.
* (Not all that important.)
*/
/* Codes for reboot */
#define RB_REBOOT 0 /* Reboot system */
#define RB_HALT 1 /* Halt system and do not reboot */
#define RB_POWEROFF 2 /* Halt system and power off */
#endif /* _KERN_REBOOT_H_ */

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2004, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_RESOURCE_H_
#define _KERN_RESOURCE_H_
/*
* Definitions for resource usage and limits.
*
* Not very important.
*/
/* priorities for setpriority() */
#define PRIO_MIN (-20)
#define PRIO_MAX 20
/* "which" codes for setpriority() */
#define PRIO_PROCESS 0
#define PRIO_PGRP 1
#define PRIO_USER 2
/* flags for getrusage() */
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN (-1)
struct rusage {
struct timeval ru_utime;
struct timeval ru_stime;
__size_t ru_maxrss; /* maximum RSS during lifespan (kb) */
__counter_t ru_ixrss; /* text memory usage (kb-ticks) */
__counter_t ru_idrss; /* data memory usage (kb-ticks) */
__counter_t ru_isrss; /* stack memory usage (kb-ticks) */
__counter_t ru_minflt; /* minor VM faults (count) */
__counter_t ru_majflt; /* major VM faults (count) */
__counter_t ru_nswap; /* whole-process swaps (count) */
__counter_t ru_inblock; /* file blocks read (count) */
__counter_t ru_oublock; /* file blocks written (count) */
__counter_t ru_msgrcv; /* socket/pipe packets rcv'd (count) */
__counter_t ru_msgsnd; /* socket/pipe packets sent (count) */
__counter_t ru_nsignals; /* signals delivered (count) */
__counter_t ru_nvcsw; /* voluntary context switches (count)*/
__counter_t ru_nivcsw; /* involuntary ditto (count) */
};
/* limit codes for getrusage/setrusage */
#define RLIMIT_NPROC 0 /* max procs per user (count) */
#define RLIMIT_NOFILE 1 /* max open files per proc (count) */
#define RLIMIT_CPU 2 /* cpu usage (seconds) */
#define RLIMIT_DATA 3 /* max .data/sbrk size (bytes) */
#define RLIMIT_STACK 4 /* max stack size (bytes) */
#define RLIMIT_MEMLOCK 5 /* max locked memory region (bytes) */
#define RLIMIT_RSS 6 /* max RSS (bytes) */
#define RLIMIT_CORE 7 /* core file size (bytes) */
#define RLIMIT_FSIZE 8 /* max file size (bytes) */
#define __RLIMIT_NUM 9 /* number of limits */
struct rlimit {
__rlim_t rlim_cur; /* soft limit */
__rlim_t rlim_max; /* hard limit */
};
#define RLIM_INFINITY (~(__rlim_t)0)
#endif /* _KERN_RESOURCE_H_ */

47
kern/include/kern/seek.h Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_SEEK_H_
#define _KERN_SEEK_H_
/*
* Codes for lseek(), which are shared in libc between <fcntl.h> and
* <unistd.h> and thus get their own file.
*
* These are pretty important. Back in the day (like 20+ years ago)
* people would often just write the values 0, 1, and 2, but that's
* really not recommended.
*/
#define SEEK_SET 0 /* Seek relative to beginning of file */
#define SEEK_CUR 1 /* Seek relative to current position in file */
#define SEEK_END 2 /* Seek relative to end of file */
#endif /* _KERN_SEEK_H_ */

101
kern/include/kern/sfs.h Normal file
View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2014
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_SFS_H_
#define _KERN_SFS_H_
/*
* SFS definitions visible to userspace. This covers the on-disk format
* and is used by tools that work on SFS volumes, such as mksfs.
*/
#define SFS_MAGIC 0xabadf001 /* magic number identifying us */
#define SFS_BLOCKSIZE 512 /* size of our blocks */
#define SFS_VOLNAME_SIZE 32 /* max length of volume name */
#define SFS_NDIRECT 15 /* # of direct blocks in inode */
#define SFS_NINDIRECT 1 /* # of indirect blocks in inode */
#define SFS_NDINDIRECT 0 /* # of 2x indirect blocks in inode */
#define SFS_NTINDIRECT 0 /* # of 3x indirect blocks in inode */
#define SFS_DBPERIDB 128 /* # direct blks per indirect blk */
#define SFS_NAMELEN 60 /* max length of filename */
#define SFS_SUPER_BLOCK 0 /* block the superblock lives in */
#define SFS_FREEMAP_START 2 /* 1st block of the freemap */
#define SFS_NOINO 0 /* inode # for free dir entry */
#define SFS_ROOTDIR_INO 1 /* loc'n of the root dir inode */
/* Number of bits in a block */
#define SFS_BITSPERBLOCK (SFS_BLOCKSIZE * CHAR_BIT)
/* Utility macro */
#define SFS_ROUNDUP(a,b) ((((a)+(b)-1)/(b))*b)
/* Size of free block bitmap (in bits) */
#define SFS_FREEMAPBITS(nblocks) SFS_ROUNDUP(nblocks, SFS_BITSPERBLOCK)
/* Size of free block bitmap (in blocks) */
#define SFS_FREEMAPBLOCKS(nblocks) (SFS_FREEMAPBITS(nblocks)/SFS_BITSPERBLOCK)
/* File types for sfi_type */
#define SFS_TYPE_INVAL 0 /* Should not appear on disk */
#define SFS_TYPE_FILE 1
#define SFS_TYPE_DIR 2
/*
* On-disk superblock
*/
struct sfs_superblock {
uint32_t sb_magic; /* Magic number; should be SFS_MAGIC */
uint32_t sb_nblocks; /* Number of blocks in fs */
char sb_volname[SFS_VOLNAME_SIZE]; /* Name of this volume */
uint32_t reserved[118]; /* unused, set to 0 */
};
/*
* On-disk inode
*/
struct sfs_dinode {
uint32_t sfi_size; /* Size of this file (bytes) */
uint16_t sfi_type; /* One of SFS_TYPE_* above */
uint16_t sfi_linkcount; /* # hard links to this file */
uint32_t sfi_direct[SFS_NDIRECT]; /* Direct blocks */
uint32_t sfi_indirect; /* Indirect block */
uint32_t sfi_waste[128-3-SFS_NDIRECT]; /* unused space, set to 0 */
};
/*
* On-disk directory entry
*/
struct sfs_direntry {
uint32_t sfd_ino; /* Inode number */
char sfd_name[SFS_NAMELEN]; /* Filename */
};
#endif /* _KERN_SFS_H_ */

131
kern/include/kern/signal.h Normal file
View File

@@ -0,0 +1,131 @@
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)signal.h 8.4 (Berkeley) 5/4/95
*/
#ifndef _KERN_SIGNAL_H_
#define _KERN_SIGNAL_H_
/*
* Machine-independent definitions for signals.
*/
/*
* The signals.
*
* The values of many of these are "well known", particularly 1, 9,
* 10, and 11.
*
* Note that Unix signals are a semantic cesspool; many have special
* properties or are supposed to interact with the system in special
* ways. It is gross.
*/
#define SIGHUP 1 /* Hangup */
#define SIGINT 2 /* Interrupt (^C) */
#define SIGQUIT 3 /* Quit (typically ^\) */
#define SIGILL 4 /* Illegal instruction */
#define SIGTRAP 5 /* Breakpoint trap */
#define SIGABRT 6 /* abort() call */
#define SIGEMT 7 /* Emulator trap */
#define SIGFPE 8 /* Floating point exception */
#define SIGKILL 9 /* Hard kill (unblockable) */
#define SIGBUS 10 /* Bus error, typically bad pointer alignment*/
#define SIGSEGV 11 /* Segmentation fault */
#define SIGSYS 12 /* Bad system call */
#define SIGPIPE 13 /* Broken pipe */
#define SIGALRM 14 /* alarm() expired */
#define SIGTERM 15 /* Termination requested (default kill) */
#define SIGURG 16 /* Urgent data on socket */
#define SIGSTOP 17 /* Hard process stop (unblockable) */
#define SIGTSTP 18 /* Terminal stop (^Z) */
#define SIGCONT 19 /* Time to continue after stop */
#define SIGCHLD 20 /* Child process exited */
#define SIGTTIN 21 /* Stop on tty read while in background */
#define SIGTTOU 22 /* Stop on tty write while in background */
#define SIGIO 23 /* Nonblocking or async I/O is now ready */
#define SIGXCPU 24 /* CPU time resource limit exceeded */
#define SIGXFSZ 25 /* File size resource limit exceeded */
#define SIGVTALRM 26 /* Like SIGALRM but in virtual time */
#define SIGPROF 27 /* Profiling timer */
#define SIGWINCH 28 /* Window size change on tty */
#define SIGINFO 29 /* Information request (typically ^T) */
#define SIGUSR1 20 /* Application-defined */
#define SIGUSR2 31 /* Application-defined */
#define SIGPWR 32 /* Power failure */
#define _NSIG 32
/* Type for a set of signals; used by e.g. sigprocmask(). */
typedef __u32 sigset_t;
/* flags for sigaction.sa_flags */
#define SA_ONSTACK 1 /* Use sigaltstack() stack. */
#define SA_RESTART 2 /* Restart syscall instead of interrupting. */
#define SA_RESETHAND 4 /* Clear handler after one usage. */
/* codes for sigprocmask() */
#define SIG_BLOCK 1 /* Block selected signals. */
#define SIG_UNBLOCK 2 /* Unblock selected signals. */
#define SIG_SETMASK 3 /* Set mask to the selected signals. */
/* Type for a signal handler function. */
typedef void (*__sigfunc)(int);
/* Magic values for signal handlers. */
#define SIG_DFL ((__sigfunc) 0) /* Default behavior. */
#define SIG_IGN ((__sigfunc) 1) /* Ignore the signal. */
/*
* Struct for sigaction().
*/
struct sigaction {
__sigfunc sa_handler;
sigset_t sa_mask;
unsigned sa_flags;
};
/*
* Struct for sigaltstack().
* (not very important)
*/
struct sigaltstack {
void *ss_sp;
size_t ss_size;
unsigned ss_flags;
};
#endif /* _KERN_SIGNAL_H_ */

116
kern/include/kern/socket.h Normal file
View File

@@ -0,0 +1,116 @@
/*
* Copyright (c) 2004, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_SOCKET_H_
#define _KERN_SOCKET_H_
/*
* Socket-related definitions, for <sys/socket.h>.
*/
/*
* Important
*/
/* Socket types that we (might) support. */
#define SOCK_STREAM 1 /* stream */
#define SOCK_DGRAM 2 /* packet */
#define SOCK_RAW 3 /* raw packet */
/* Address families that we (might) support. */
#define AF_UNSPEC 0
#define AF_UNIX 1
#define AF_INET 2
#define AF_INET6 3
/* Protocol families. Pointless layer of indirection in the standard API. */
#define PF_UNSPEC AF_UNSPEC
#define PF_UNIX AF_UNIX
#define PF_INET AF_INET
#define PF_INET6 AF_INET6
/*
* Socket address structures. Socket addresses are polymorphic, and
* the polymorphism is handled by casting pointers. It's fairly gross,
* but way too deeply standardized to ever change.
*
* Each address family defines a sockaddr type (sockaddr_un,
* sockaddr_in, etc.) struct sockaddr is the common prefix of all
* these, and struct sockaddr_storage is defined to be large enough to
* hold any of them.
*
* The complex padding in sockaddr_storage forces it to be aligned,
* which wouldn't happen if it were just a char array.
*/
struct sockaddr {
__u8 sa_len;
__u8 sa_family;
};
#define _SS_SIZE 128
struct sockaddr_storage {
__u8 ss_len;
__u8 ss_family;
__u8 __ss_pad1;
__u8 __ss_pad2;
__u32 __ss_pad3;
__u64 __ss_pad4;
char __ss_pad5[_SS_SIZE - sizeof(__u64) - sizeof(__u32) - 4*sizeof(__u8)];
};
/*
* Not very important.
*/
/*
* msghdr structures for sendmsg() and recvmsg().
*/
struct msghdr {
void *msg_name; /* really sockaddr; address, or null */
socklen_t msg_namelen; /* size of msg_name object, or 0 */
struct iovec *msg_iov; /* I/O buffers */
int msg_iovlen; /* number of iovecs */
void *msg_control; /* auxiliary data area, or null */
socklen_t msg_controllen; /* size of msg_control area */
int msg_flags; /* flags */
};
struct cmsghdr {
socklen_t cmsg_len; /* length of control data, including header */
int cmsg_level; /* protocol layer item originates from */
int cmsg_type; /* protocol-specific message type */
/* char cmsg_data[];*/ /* data follows the header */
};
#endif /* _KERN_SOCKET_H_ */

71
kern/include/kern/stat.h Normal file
View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_STAT_H_
#define _KERN_STAT_H_
/*
* The stat structure, for returning file information via stat(),
* fstat(), and lstat().
*
* Fields corresponding to things you aren't implementing should be
* set to zero.
*
* The file types are in kern/stattypes.h.
*/
struct stat {
/* Essential fields */
off_t st_size; /* file size in bytes */
mode_t st_mode; /* file type and protection mode */
nlink_t st_nlink; /* number of hard links */
blkcnt_t st_blocks; /* number of blocks file is using */
/* Identity */
dev_t st_dev; /* device object lives on */
ino_t st_ino; /* inode number (serial number) of object */
dev_t st_rdev; /* device object is (if a device) */
/* Timestamps */
time_t st_atime; /* last access time: seconds */
time_t st_ctime; /* inode change time: seconds */
time_t st_mtime; /* modification time: seconds */
__u32 st_atimensec; /* last access time: nanoseconds */
__u32 st_ctimensec; /* inode change time: nanoseconds */
__u32 st_mtimensec; /* modification time: nanoseconds */
/* Permissions (also st_mode) */
uid_t st_uid; /* owner */
gid_t st_gid; /* group */
/* Other */
__u32 st_gen; /* file generation number (root only) */
blksize_t st_blksize; /* recommended I/O block size */
};
#endif /* _KERN_STAT_H_ */

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_STATTYPES_H_
#define _KERN_STATTYPES_H_
/*
* Further supporting material for stat(), fstat(), and lstat().
*
* File types for st_mode. (The permissions are the low 12 bits.)
*
* These are also used, shifted right by those 12 bits, in struct
* dirent in libc, which is why they get their own file.
*
* Non-underscore versions of the names can be gotten from <stat.h>
* (kernel) or <sys/stat.h> (userland).
*/
#define _S_IFMT 070000 /* mask for type of file */
#define _S_IFREG 010000 /* ordinary regular file */
#define _S_IFDIR 020000 /* directory */
#define _S_IFLNK 030000 /* symbolic link */
#define _S_IFIFO 040000 /* pipe or named pipe */
#define _S_IFSOCK 050000 /* socket */
#define _S_IFCHR 060000 /* character device */
#define _S_IFBLK 070000 /* block device */
#endif /* _KERN_STATTYPES_H_ */

203
kern/include/kern/syscall.h Normal file
View File

@@ -0,0 +1,203 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_SYSCALL_H_
#define _KERN_SYSCALL_H_
/*
* System call numbers.
*
* To foster compatibility, this file contains a number for every
* more-or-less standard Unix system call that someone might
* conceivably implement on OS/161. The commented-out ones are ones
* we're pretty sure you won't be implementing. The others, you might
* or might not. Check your own course materials to find out what's
* specifically required of you.
*
* Caution: this file is parsed by a shell script to generate the assembly
* language system call stubs. Don't add weird stuff between the markers.
*/
/*CALLBEGIN*/
// -- Process-related --
#define SYS_fork 0
#define SYS_vfork 1
#define SYS_execv 2
#define SYS__exit 3
#define SYS_waitpid 4
#define SYS_getpid 5
#define SYS_getppid 6
// (virtual memory)
#define SYS_sbrk 7
#define SYS_mmap 8
#define SYS_munmap 9
#define SYS_mprotect 10
//#define SYS_madvise 11
//#define SYS_mincore 12
//#define SYS_mlock 13
//#define SYS_munlock 14
//#define SYS_munlockall 15
//#define SYS_minherit 16
// (security/credentials)
#define SYS_umask 17
#define SYS_issetugid 18
#define SYS_getresuid 19
#define SYS_setresuid 20
#define SYS_getresgid 21
#define SYS_setresgid 22
#define SYS_getgroups 23
#define SYS_setgroups 24
#define SYS___getlogin 25
#define SYS___setlogin 26
// (signals)
#define SYS_kill 27
#define SYS_sigaction 28
#define SYS_sigpending 29
#define SYS_sigprocmask 30
#define SYS_sigsuspend 31
#define SYS_sigreturn 32
//#define SYS_sigaltstack 33
// (resource tracking and usage)
//#define SYS_wait4 34
//#define SYS_getrusage 35
// (resource limits)
//#define SYS_getrlimit 36
//#define SYS_setrlimit 37
// (process priority control)
//#define SYS_getpriority 38
//#define SYS_setpriority 39
// (process groups, sessions, and job control)
//#define SYS_getpgid 40
//#define SYS_setpgid 41
//#define SYS_getsid 42
//#define SYS_setsid 43
// (userlevel debugging)
//#define SYS_ptrace 44
// -- File-handle-related --
#define SYS_open 45
#define SYS_pipe 46
#define SYS_dup 47
#define SYS_dup2 48
#define SYS_close 49
#define SYS_read 50
#define SYS_pread 51
//#define SYS_readv 52
//#define SYS_preadv 53
#define SYS_getdirentry 54
#define SYS_write 55
#define SYS_pwrite 56
//#define SYS_writev 57
//#define SYS_pwritev 58
#define SYS_lseek 59
#define SYS_flock 60
#define SYS_ftruncate 61
#define SYS_fsync 62
#define SYS_fcntl 63
#define SYS_ioctl 64
#define SYS_select 65
#define SYS_poll 66
// -- Pathname-related --
#define SYS_link 67
#define SYS_remove 68
#define SYS_mkdir 69
#define SYS_rmdir 70
#define SYS_mkfifo 71
#define SYS_rename 72
#define SYS_access 73
// (current directory)
#define SYS_chdir 74
#define SYS_fchdir 75
#define SYS___getcwd 76
// (symbolic links)
#define SYS_symlink 77
#define SYS_readlink 78
// (mount)
#define SYS_mount 79
#define SYS_unmount 80
// -- Any-file-related --
#define SYS_stat 81
#define SYS_fstat 82
#define SYS_lstat 83
// (timestamps)
#define SYS_utimes 84
#define SYS_futimes 85
#define SYS_lutimes 86
// (security/permissions)
#define SYS_chmod 87
#define SYS_chown 88
#define SYS_fchmod 89
#define SYS_fchown 90
#define SYS_lchmod 91
#define SYS_lchown 92
// (file system info)
//#define SYS_statfs 93
//#define SYS_fstatfs 94
//#define SYS_getfsstat 95
// (POSIX dynamic system limits stuff)
//#define SYS_pathconf 96
//#define SYS_fpathconf 97
// -- Sockets and networking --
#define SYS_socket 98
#define SYS_bind 99
#define SYS_connect 100
#define SYS_listen 101
#define SYS_accept 102
//#define SYS_socketpair 103
#define SYS_shutdown 104
#define SYS_getsockname 105
#define SYS_getpeername 106
#define SYS_getsockopt 107
#define SYS_setsockopt 108
//#define SYS_recvfrom 109
//#define SYS_sendto 110
//#define SYS_recvmsg 111
//#define SYS_sendmsg 112
// -- Time-related --
#define SYS___time 113
#define SYS___settime 114
#define SYS_nanosleep 115
//#define SYS_getitimer 116
//#define SYS_setitimer 117
// -- Other --
#define SYS_sync 118
#define SYS_reboot 119
//#define SYS___sysctl 120
/*CALLEND*/
#endif /* _KERN_SYSCALL_H_ */

70
kern/include/kern/time.h Normal file
View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2004, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_TIME_H_
#define _KERN_TIME_H_
/*
* Time-related definitions, for <sys/time.h> and others.
*/
/*
* Time with fractional seconds. Important. Unfortunately, to be
* compatible, we need both timeval and timespec.
*/
struct timeval {
__time_t tv_sec; /* seconds */
__i32 tv_usec; /* microseconds */
};
struct timespec {
__time_t tv_sec; /* seconds */
__i32 tv_nsec; /* nanoseconds */
};
/*
* Bits for interval timers. Obscure and not really that important.
*/
/* codes for the various timers */
#define ITIMER_REAL 0 /* Real (wall-clock) time. */
#define ITIMER_VIRTUAL 1 /* Virtual (when process is executing) time. */
#define ITIMER_PROF 2 /* For execution profiling. */
/* structure for setitimer/getitimer */
struct itimerval {
struct timeval it_interval; /* Time to reload after expiry. */
struct timeval it_value; /* Time to count. */
};
#endif /* _KERN_TIME_H_ */

92
kern/include/kern/types.h Normal file
View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_TYPES_H_
#define _KERN_TYPES_H_
/* Get machine-dependent types. */
#include <kern/machine/types.h>
/*
* Machine-independent types visible to user level.
*
* Define everything with leading underscores to avoid polluting the C
* namespace for applications.
*
* The C standard (and additionally the POSIX standard) define rules
* for what families of symbol names are allowed to be used by
* application programmers, and what families of symbol names can be
* defined by various standard header files. The C library needs to
* conform to those rules, to the extent reasonably practical, to make
* sure that application code compiles and behaves as intended.
*
* Many of the C library's headers need to use one or more of these
* types in places where the "real" name of the type cannot be
* exposed, or expose the names of some of these types and not others.
* (For example, <string.h> is supposed to define size_t, but is not
* supposed to also define e.g. pid_t.)
*
* For this reason we define everything with two underscores in front
* of it; in C such symbol names are reserved for the implementation,
* which we are, so this file can be included anywhere in any libc
* header without causing namespace problems. The "real" type names
* are defined with an additional layer of typedefs; this happens for
* the kernel in <types.h> and for userland in (mostly) <sys/types.h>
* and also various other places as per relevant standards.
*/
typedef __u32 __blkcnt_t; /* Count of blocks */
typedef __u32 __blksize_t; /* Size of an I/O block */
typedef __u64 __counter_t; /* Event counter */
typedef __u32 __daddr_t; /* Disk block number */
typedef __u32 __dev_t; /* Hardware device ID */
typedef __u32 __fsid_t; /* Filesystem ID */
typedef __i32 __gid_t; /* Group ID */
typedef __u32 __in_addr_t; /* Internet address */
typedef __u32 __in_port_t; /* Internet port number */
typedef __u32 __ino_t; /* Inode number */
typedef __u32 __mode_t; /* File access mode */
typedef __u16 __nlink_t; /* Number of links (intentionally only 16 bits) */
typedef __i64 __off_t; /* Offset within file */
typedef __i32 __pid_t; /* Process ID */
typedef __u64 __rlim_t; /* Resource limit quantity */
typedef __u8 __sa_family_t;/* Socket address family */
typedef __i64 __time_t; /* Time in seconds */
typedef __i32 __uid_t; /* User ID */
typedef int __nfds_t; /* Number of file handles */
typedef int __socklen_t; /* Socket-related length */
/* See note in <stdarg.h> */
#ifdef __GNUC__
typedef __builtin_va_list __va_list;
#endif
#endif /* _KERN_TYPES_H_ */

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_UNISTD_H_
#define _KERN_UNISTD_H_
/* Constants for read/write/etc: special file handles */
#define STDIN_FILENO 0 /* Standard input */
#define STDOUT_FILENO 1 /* Standard output */
#define STDERR_FILENO 2 /* Standard error */
#endif /* _KERN_UNISTD_H_ */

79
kern/include/kern/wait.h Normal file
View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2003, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _KERN_WAIT_H_
#define _KERN_WAIT_H_
/*
* Definitions for wait().
*/
/* Flags for waitpid() and equivalent. */
#define WNOHANG 1 /* Nonblocking. */
#define WUNTRACED 2 /* Report stopping as well as exiting processes. */
/* Special "pids" to wait for. */
#define WAIT_ANY (-1) /* Any child process. */
#define WAIT_MYPGRP 0 /* Any process in the same process group. */
/*
* Result encoding.
*
* The lowest two bits say what happened; the rest encodes up to 30
* bits of exit code. Note that the traditional Unix encoding, which
* is different, wastes most of the bits and can only transmit 8 bits
* of exit code...
*/
#define _WWHAT(x) ((x)&3) /* lower two bits say what happened */
#define _WVAL(x) ((x)>>2) /* the rest is the value */
#define _MKWVAL(x) ((x)<<2) /* encode a value */
/* Four things can happen... */
#define __WEXITED 0 /* Process exited by calling _exit(). */
#define __WSIGNALED 1 /* Process received a fatal signal. */
#define __WCORED 2 /* Process dumped core on a fatal signal. */
#define __WSTOPPED 3 /* Process stopped (and didn't exit). */
/* Test macros, used by applications. */
#define WIFEXITED(x) (_WWHAT(x)==__WEXITED)
#define WIFSIGNALED(x) (_WWHAT(x)==__WSIGNALED || _WWHAT(x)==__WCORED)
#define WIFSTOPPED(x) (_WWHAT(x)==__WSTOPPED)
#define WEXITSTATUS(x) (_WVAL(x))
#define WTERMSIG(x) (_WVAL(x))
#define WSTOPSIG(x) (_WVAL(x))
#define WCOREDUMP(x) (_WWHAT(x)==__WCORED)
/* Encoding macros, used by the kernel to generate the wait result. */
#define _MKWAIT_EXIT(x) (_MKWVAL(x)|__WEXITED)
#define _MKWAIT_SIG(x) (_MKWVAL(x)|__WSIGNALED)
#define _MKWAIT_CORE(x) (_MKWVAL(x)|__WCORED)
#define _MKWAIT_STOP(x) (_MKWVAL(x)|__WSTOPPED)
#endif /* _KERN_WAIT_H_ */

198
kern/include/lib.h Normal file
View File

@@ -0,0 +1,198 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _LIB_H_
#define _LIB_H_
/*
* Miscellaneous standard C functions for the kernel, and other widely used
* kernel functions.
*
* Note: setjmp and longjmp are in <setjmp.h>.
*/
#include <cdefs.h>
/*
* Assert macros.
*
* KASSERT and DEBUGASSERT are the same, except that they can be
* toggled independently. DEBUGASSERT is used in places where making
* checks is likely to be expensive and relatively unlikely to be
* helpful.
*
* Note that there's also a COMPILE_ASSERT for compile-time checks;
* it's in <cdefs.h>.
*
* Regular assertions (KASSERT) are disabled by the kernel config
* option "noasserts". DEBUGASSERT could be controlled by kernel
* config also, but since it's likely to be wanted only rarely during
* testing there doesn't seem much point; one can just edit this file
* temporarily instead.
*/
#include "opt-noasserts.h"
#if OPT_NOASSERTS
#define KASSERT(expr) ((void)(expr))
#else
#define KASSERT(expr) \
((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
#endif
#if 1 /* no debug asserts */
#define DEBUGASSERT(expr) ((void)(expr))
#else
#define DEBUGASSERT(expr) \
((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
#endif
/*
* Bit flags for DEBUG()
*/
#define DB_LOCORE 0x0001
#define DB_SYSCALL 0x0002
#define DB_INTERRUPT 0x0004
#define DB_DEVICE 0x0008
#define DB_THREADS 0x0010
#define DB_VM 0x0020
#define DB_EXEC 0x0040
#define DB_VFS 0x0080
#define DB_SEMFS 0x0100
#define DB_SFS 0x0200
#define DB_NET 0x0400
#define DB_NETFS 0x0800
#define DB_KMALLOC 0x1000
extern uint32_t dbflags;
/*
* DEBUG() is for conditionally printing debug messages to the console.
*
* The idea is that you put lots of lines of the form
*
* DEBUG(DB_VM, "VM free pages: %u\n", free_pages);
*
* throughout the kernel; then you can toggle whether these messages
* are printed or not at runtime by setting the value of dbflags with
* the debugger.
*
* Unfortunately, as of this writing, there are only a very few such
* messages actually present in the system yet. Feel free to add more.
*
* DEBUG is a varargs macro. These were added to the language in C99.
*/
#define DEBUG(d, ...) ((dbflags & (d)) ? kprintf(__VA_ARGS__) : 0)
/*
* Random number generator, using the random device.
*
* random() returns a number between 0 and randmax() inclusive.
*/
#define RANDOM_MAX (randmax())
uint32_t randmax(void);
uint32_t random(void);
/*
* Kernel heap memory allocation. Like malloc/free.
* If out of memory, kmalloc returns NULL.
*
* kheap_nextgeneration, dump, and dumpall do nothing unless heap
* labeling (for leak detection) in kmalloc.c (q.v.) is enabled.
*/
void *kmalloc(size_t size);
void kfree(void *ptr);
void kheap_printstats(void);
void kheap_nextgeneration(void);
void kheap_dump(void);
void kheap_dumpall(void);
/*
* C string functions.
*
* kstrdup is like strdup, but calls kmalloc instead of malloc.
* If out of memory, it returns NULL.
*/
size_t strlen(const char *str);
int strcmp(const char *str1, const char *str2);
char *strcpy(char *dest, const char *src);
char *strcat(char *dest, const char *src);
char *kstrdup(const char *str);
char *strchr(const char *searched, int searchfor);
char *strrchr(const char *searched, int searchfor);
char *strtok_r(char *buf, const char *seps, char **context);
void *memcpy(void *dest, const void *src, size_t len);
void *memmove(void *dest, const void *src, size_t len);
void *memset(void *block, int ch, size_t len);
void bzero(void *ptr, size_t len);
int atoi(const char *str);
int snprintf(char *buf, size_t maxlen, const char *fmt, ...) __PF(3,4);
const char *strerror(int errcode);
/*
* Low-level console access.
*/
void putch(int ch);
int getch(void);
void beep(void);
/*
* Higher-level console output.
*
* kprintf is like printf, only in the kernel.
* panic prepends the string "panic: " to the message printed, and then
* resets the system.
* badassert calls panic in a way suitable for an assertion failure.
* kgets is like gets, only with a buffer size argument.
*
* kprintf_bootstrap sets up a lock for kprintf and should be called
* during boot once malloc is available and before any additional
* threads are created.
*/
int kprintf(const char *format, ...) __PF(1,2);
__DEAD void panic(const char *format, ...) __PF(1,2);
__DEAD void badassert(const char *expr, const char *file,
int line, const char *func);
void kgets(char *buf, size_t maxbuflen);
void kprintf_bootstrap(void);
/*
* Other miscellaneous stuff
*/
#define DIVROUNDUP(a,b) (((a)+(b)-1)/(b))
#define ROUNDUP(a,b) (DIVROUNDUP(a,b)*b)
#endif /* _LIB_H_ */

52
kern/include/limits.h Normal file
View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _LIMITS_H_
#define _LIMITS_H_
/*
* System limits.
*/
/* Get the limit values, which are exported to userland with private names. */
#include <kern/limits.h>
/* Provide the real names */
#define NAME_MAX __NAME_MAX
#define PATH_MAX __PATH_MAX
#define ARG_MAX __ARG_MAX
#define PID_MIN __PID_MIN
#define PID_MAX __PID_MAX
#define PIPE_BUF __PIPE_BUF
#define NGROUPS_MAX __NGROUPS_MAX
#define LOGIN_NAME_MAX __LOGIN_NAME_MAX
#define OPEN_MAX __OPEN_MAX
#define IOV_MAX __IOV_MAX
#endif /* _LIMITS_H_ */

70
kern/include/mainbus.h Normal file
View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _MAINBUS_H_
#define _MAINBUS_H_
/*
* Abstract system bus interface.
*/
struct cpu; /* from <cpu.h> */
struct trapframe; /* from <machine/trapframe.h> */
/* Initialize the system bus and probe and attach hardware devices. */
void mainbus_bootstrap(void);
/* Start up secondary CPUs, once their cpu structures are set up */
void mainbus_start_cpus(void);
/* Bus-level interrupt handler, called from cpu-level trap/interrupt code */
void mainbus_interrupt(struct trapframe *);
/* Find the size of main memory. */
/* XXX this interface is not adequately MI */
size_t mainbus_ramsize(void);
/* Switch on an inter-processor interrupt. (Low-level.) */
void mainbus_send_ipi(struct cpu *target);
/*
* The various ways to shut down the system. (These are very low-level
* and should generally not be called directly - md_poweroff, for
* instance, unceremoniously turns the power off without doing
* anything else.)
*/
void mainbus_halt(void);
void mainbus_poweroff(void);
void mainbus_reboot(void);
void mainbus_panic(void);
#endif /* _MAINBUS_H_ */

93
kern/include/membar.h Normal file
View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2013
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _MEMBAR_H_
#define _MEMBAR_H_
/*
* Memory barriers. These create ordering barriers in CPU memory
* accesses as actually issued by the CPU to the cache and memory
* system. Because superscalar CPUs can execute many instructions at
* once, they can potentially be retired in a different order from
* what's written in your code. Normally this doesn't matter, but
* sometimes it does (e.g. when writing to device registers) and in
* those cases you need to insert memory barrier instructions to
* create ordering guarantees.
*
* membar_load_load creates an ordering barrier between preceding
* loads (from memory to registers) and subsequent loads, but has
* (potentially) no effect on stores. This is what some people call a
* "load fence".
*
* membar_store_store creates an ordering barrier between preceding
* stores (from registers to memory) and subsequent stores, but has
* (potentially) no effect on loads. This is what some people call a
* "store" or "write fence".
*
* membar_store_any creates an ordering barrier between preceding
* stores and subsequent stores *and* loads. Preceding loads may be
* delayed past the barrier. This is the behavior needed for
* operations comparable to spinlock_acquire().
*
* membar_any_store creates an ordering barrier between preceding
* loads and stores and subsequent stores. Following loads may be
* executed before the barrier. This is the behavior needed for
* operations comparable to spinlock_release().
*
* membar_any_any creates a full ordering barrier, between preceding
* loads and stores and following loads and stores.
*
* In OS/161 we assume that the spinlock operations include any memory
* barrier instructions they require. (On many CPUs the synchronized/
* locked instructions used to implement spinlocks are themselves
* implicit memory barriers.) You do not need to use membar_store_any
* and membar_any_store unless rolling your own lock-like objects,
* using atomic operations, implementing lock-free data structures, or
* talking to hardware devices.
*
* There is a lot of FUD about memory barriers circulating on the
* internet. Please ask your course staff if you have questions or
* concerns.
*/
/* Inlining support - for making sure an out-of-line copy gets built */
#ifndef MEMBAR_INLINE
#define MEMBAR_INLINE INLINE
#endif
MEMBAR_INLINE void membar_load_load(void);
MEMBAR_INLINE void membar_store_store(void);
MEMBAR_INLINE void membar_store_any(void);
MEMBAR_INLINE void membar_any_store(void);
MEMBAR_INLINE void membar_any_any(void);
/* Get the implementation. */
#include <machine/membar.h>
#endif /* _MEMBAR_H_ */

101
kern/include/proc.h Normal file
View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2013
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _PROC_H_
#define _PROC_H_
/*
* Definition of a process.
*
* Note: curproc is defined by <current.h>.
*/
#include <spinlock.h>
struct addrspace;
struct thread;
struct vnode;
/*
* Process structure.
*
* Note that we only count the number of threads in each process.
* (And, unless you implement multithreaded user processes, this
* number will not exceed 1 except in kproc.) If you want to know
* exactly which threads are in the process, e.g. for debugging, add
* an array and a sleeplock to protect it. (You can't use a spinlock
* to protect an array because arrays need to be able to call
* kmalloc.)
*
* You will most likely be adding stuff to this structure, so you may
* find you need a sleeplock in here for other reasons as well.
* However, note that p_addrspace must be protected by a spinlock:
* thread_switch needs to be able to fetch the current address space
* without sleeping.
*/
struct proc {
char *p_name; /* Name of this process */
struct spinlock p_lock; /* Lock for this structure */
unsigned p_numthreads; /* Number of threads in this process */
/* VM */
struct addrspace *p_addrspace; /* virtual address space */
/* VFS */
struct vnode *p_cwd; /* current working directory */
/* add more material here as needed */
};
/* This is the process structure for the kernel and for kernel-only threads. */
extern struct proc *kproc;
/* Call once during system startup to allocate data structures. */
void proc_bootstrap(void);
/* Create a fresh process for use by runprogram(). */
struct proc *proc_create_runprogram(const char *name);
/* Destroy a process. */
void proc_destroy(struct proc *proc);
/* Attach a thread to a process. Must not already have a process. */
int proc_addthread(struct proc *proc, struct thread *t);
/* Detach a thread from its process. */
void proc_remthread(struct thread *t);
/* Fetch the address space of the current process. */
struct addrspace *proc_getas(void);
/* Change the address space of the current process, and return the old one. */
struct addrspace *proc_setas(struct addrspace *);
#endif /* _PROC_H_ */

44
kern/include/setjmp.h Normal file
View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SETJMP_H_
#define _SETJMP_H_
/*
* Kernel-level setjmp/longjmp.
*/
/* Get (machine-dependent) definition of jmp_buf. */
#include <kern/machine/setjmp.h>
int setjmp(jmp_buf jb);
void longjmp(jmp_buf jb, int retval);
#endif /* _SETJMP_H_ */

80
kern/include/sfs.h Normal file
View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SFS_H_
#define _SFS_H_
/*
* Header for SFS, the Simple File System.
*/
/*
* Get abstract structure definitions
*/
#include <fs.h>
#include <vnode.h>
/*
* Get on-disk structures and constants that are made available to
* userland for the benefit of mksfs, dumpsfs, etc.
*/
#include <kern/sfs.h>
/*
* In-memory inode
*/
struct sfs_vnode {
struct vnode sv_absvn; /* abstract vnode structure */
struct sfs_dinode sv_i; /* copy of on-disk inode */
uint32_t sv_ino; /* inode number */
bool sv_dirty; /* true if sv_i modified */
};
/*
* In-memory info for a whole fs volume
*/
struct sfs_fs {
struct fs sfs_absfs; /* abstract filesystem structure */
struct sfs_superblock sfs_sb; /* copy of on-disk superblock */
bool sfs_superdirty; /* true if superblock modified */
struct device *sfs_device; /* device mounted on */
struct vnodearray *sfs_vnodes; /* vnodes loaded into memory */
struct bitmap *sfs_freemap; /* blocks in use are marked 1 */
bool sfs_freemapdirty; /* true if freemap modified */
};
/*
* Function for mounting a sfs (calls vfs_mount)
*/
int sfs_mount(const char *device);
#endif /* _SFS_H_ */

39
kern/include/signal.h Normal file
View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2004, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SIGNAL_H_
#define _SIGNAL_H_
/* In-kernel signal definitions. Get both the MD and MI parts. */
#include <kern/machine/signal.h>
#include <kern/signal.h>
#endif /* _SIGNAL_H_ */

88
kern/include/spinlock.h Normal file
View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SPINLOCK_H_
#define _SPINLOCK_H_
/*
* Spinlocks. While the guts are machine-dependent, the structure and the
* basic functions are supposed to be the same across all machines.
*/
#include <cdefs.h>
/* Inlining support - for making sure an out-of-line copy gets built */
#ifndef SPINLOCK_INLINE
#define SPINLOCK_INLINE INLINE
#endif
/* Get the machine-dependent bits. */
#include <machine/spinlock.h>
/*
* Basic spinlock.
*
* Note that spinlocks are held by CPUs, not by threads.
*
* This structure is made public so spinlocks do not have to be
* malloc'd; however, code that uses spinlocks should not look inside
* the structure directly but always use the spinlock API functions.
*/
struct spinlock {
volatile spinlock_data_t splk_lock; /* Memory word where we spin. */
struct cpu *splk_holder; /* CPU holding this lock. */
};
/*
* Initializer for cases where a spinlock needs to be static or global.
*/
#define SPINLOCK_INITIALIZER { SPINLOCK_DATA_INITIALIZER, NULL }
/*
* Spinlock functions.
*
* init Initialize the contents of a spinlock.
* cleanup Opposite of init. Lock must be unlocked.
*
* acquire Get the lock, spinning as necessary. Also disables interrupts.
* release Release the lock. May re-enable interrupts.
*
* do_i_hold Check if the current CPU holds the lock.
*/
void spinlock_init(struct spinlock *lk);
void spinlock_cleanup(struct spinlock *lk);
void spinlock_acquire(struct spinlock *lk);
void spinlock_release(struct spinlock *lk);
bool spinlock_do_i_hold(struct spinlock *lk);
#endif /* _SPINLOCK_H_ */

109
kern/include/spl.h Normal file
View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SPL_H_
#define _SPL_H_
#include <cdefs.h>
/* Inlining support - for making sure an out-of-line copy gets built */
#ifndef SPL_INLINE
#define SPL_INLINE INLINE
#endif
/*
* Machine-independent interface to interrupt enable/disable.
*
* "spl" stands for "set priority level", and was originally the name of
* a VAX assembler instruction.
*
* The idea is that one can block less important interrupts while
* processing them, but still allow more urgent interrupts to interrupt
* that processing.
*
* Ordinarily there would be a whole bunch of defined interrupt
* priority levels and functions for setting them - spltty(),
* splbio(), etc., etc. But we don't support interrupt priorities in
* OS/161, so there are only three:
*
* spl0() sets IPL to 0, enabling all interrupts.
* splhigh() sets IPL to the highest value, disabling all interrupts.
* splx(s) sets IPL to S, enabling whatever state S represents.
*
* All three return the old interrupt state. Thus, these are commonly used
* as follows:
*
* int s = splhigh();
* [ code ]
* splx(s);
*
* Note that these functions only affect interrupts on the current
* processor.
*/
SPL_INLINE int spl0(void);
SPL_INLINE int splhigh(void);
int splx(int);
/*
* Integer interrupt priority levels.
*/
#define IPL_NONE 0
#define IPL_HIGH 1
/*
* Lower-level functions for explicitly raising and lowering
* particular interrupt levels. These are used by splx() and by the
* spinlock code.
*
* A previous setting of OLDIPL is cancelled and replaced with NEWIPL.
*
* For splraise, NEWIPL > OLDIPL, and for spllower, NEWIPL < OLDIPL.
*/
void splraise(int oldipl, int newipl);
void spllower(int oldipl, int newipl);
////////////////////////////////////////////////////////////
SPL_INLINE
int
spl0(void)
{
return splx(IPL_NONE);
}
SPL_INLINE
int
splhigh(void)
{
return splx(IPL_HIGH);
}
#endif /* _SPL_H_ */

50
kern/include/stat.h Normal file
View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _STAT_H_
#define _STAT_H_
/* Get the stat structure. */
#include <kern/stat.h>
/* Get the object type macros, which are shared in libc with <dirent.h>. */
#include <kern/stattypes.h>
/* Provide non-underscore names. */
#define S_IFMT _S_IFMT
#define S_IFREG _S_IFREG
#define S_IFDIR _S_IFDIR
#define S_IFLNK _S_IFLNK
#define S_IFIFO _S_IFIFO
#define S_IFSOCK _S_IFSOCK
#define S_IFCHR _S_IFCHR
#define S_IFBLK _S_IFBLK
#endif /* _STAT_H */

79
kern/include/stdarg.h Normal file
View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _STDARG_H_
#define _STDARG_H_
/* Get __PF() for declaring printf-like functions. */
#include <cdefs.h>
/*
* As of gcc 3.0, the stdarg declarations can be made machine-
* independent because gcc abstracts the implementations away for
* us. However, they went and changed __builtin_stdarg_start to
* __builtin_va_start sometime between gcc 4.1 and 4.8 (not sure
* when) so we need to check that.
*/
#ifdef __GNUC__
typedef __va_list va_list;
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
#define va_start(ap, fmt) __builtin_stdarg_start(ap, fmt)
#else
#define va_start(ap, fmt) __builtin_va_start(ap, fmt)
#endif
#define va_arg(ap,t) __builtin_va_arg(ap, t)
#define va_copy(ap1, ap2) __builtin_va_copy(ap1, ap2)
#define va_end(ap) __builtin_va_end(ap)
#endif
/*
* The v... versions of printf functions in <lib.h>. This is not
* really the best place for them... but if we put them in <lib.h>
* we'd need to either include this file there, put these defs there,
* or split the definition of va_list into another header file, none
* of which seems entirely desirable.
*/
void vkprintf(const char *fmt, va_list ap) __PF(1,0);
int vsnprintf(char *buf, size_t maxlen, const char *fmt, va_list ap) __PF(3,0);
/*
* The printf driver function (shared with libc).
* Does v...printf, passing the output data piecemeal to the function
* supplied. The "clientdata" argument is passed through to the function.
* The strings passed to the function might not be null-terminated; the
* supplied length should be used explicitly.
*/
int __vprintf(void (*func)(void *clientdata, const char *str, size_t len),
void *clientdata, const char *format, va_list ap) __PF(3,0);
#endif /* _STDARG_H_ */

141
kern/include/synch.h Normal file
View File

@@ -0,0 +1,141 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SYNCH_H_
#define _SYNCH_H_
/*
* Header file for synchronization primitives.
*/
#include <spinlock.h>
/*
* Dijkstra-style semaphore.
*
* The name field is for easier debugging. A copy of the name is made
* internally.
*/
struct semaphore {
char *sem_name;
struct wchan *sem_wchan;
struct spinlock sem_lock;
volatile unsigned sem_count;
};
struct semaphore *sem_create(const char *name, unsigned initial_count);
void sem_destroy(struct semaphore *);
/*
* Operations (both atomic):
* P (proberen): decrement count. If the count is 0, block until
* the count is 1 again before decrementing.
* V (verhogen): increment count.
*/
void P(struct semaphore *);
void V(struct semaphore *);
/*
* Simple lock for mutual exclusion.
*
* When the lock is created, no thread should be holding it. Likewise,
* when the lock is destroyed, no thread should be holding it.
*
* The name field is for easier debugging. A copy of the name is
* (should be) made internally.
*/
struct lock {
char *lk_name;
// add what you need here
// (don't forget to mark things volatile as needed)
};
struct lock *lock_create(const char *name);
void lock_destroy(struct lock *);
/*
* Operations:
* lock_acquire - Get the lock. Only one thread can hold the lock at the
* same time.
* lock_release - Free the lock. Only the thread holding the lock may do
* this.
* lock_do_i_hold - Return true if the current thread holds the lock;
* false otherwise.
*
* These operations must be atomic. You get to write them.
*/
void lock_acquire(struct lock *);
void lock_release(struct lock *);
bool lock_do_i_hold(struct lock *);
/*
* Condition variable.
*
* Note that the "variable" is a bit of a misnomer: a CV is normally used
* to wait until a variable meets a particular condition, but there's no
* actual variable, as such, in the CV.
*
* These CVs are expected to support Mesa semantics, that is, no
* guarantees are made about scheduling.
*
* The name field is for easier debugging. A copy of the name is
* (should be) made internally.
*/
struct cv {
char *cv_name;
// add what you need here
// (don't forget to mark things volatile as needed)
};
struct cv *cv_create(const char *name);
void cv_destroy(struct cv *);
/*
* Operations:
* cv_wait - Release the supplied lock, go to sleep, and, after
* waking up again, re-acquire the lock.
* cv_signal - Wake up one thread that's sleeping on this CV.
* cv_broadcast - Wake up all threads sleeping on this CV.
*
* For all three operations, the current thread must hold the lock passed
* in. Note that under normal circumstances the same lock should be used
* on all operations with any particular CV.
*
* These operations must be atomic. You get to write them.
*/
void cv_wait(struct cv *cv, struct lock *lock);
void cv_signal(struct cv *cv, struct lock *lock);
void cv_broadcast(struct cv *cv, struct lock *lock);
#endif /* _SYNCH_H_ */

62
kern/include/syscall.h Normal file
View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SYSCALL_H_
#define _SYSCALL_H_
#include <cdefs.h> /* for __DEAD */
struct trapframe; /* from <machine/trapframe.h> */
/*
* The system call dispatcher.
*/
void syscall(struct trapframe *tf);
/*
* Support functions.
*/
/* Helper for fork(). You write this. */
void enter_forked_process(struct trapframe *tf);
/* Enter user mode. Does not return. */
__DEAD void enter_new_process(int argc, userptr_t argv, userptr_t env,
vaddr_t stackptr, vaddr_t entrypoint);
/*
* Prototypes for IN-KERNEL entry points for system call implementations.
*/
int sys_reboot(int code);
int sys___time(userptr_t user_seconds, userptr_t user_nanoseconds);
#endif /* _SYSCALL_H_ */

108
kern/include/test.h Normal file
View File

@@ -0,0 +1,108 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _TEST_H_
#define _TEST_H_
/*
* Declarations for test code and other miscellaneous high-level
* functions.
*/
/*
* Test code.
*/
/* data structure tests */
int arraytest(int, char **);
int arraytest2(int, char **);
int bitmaptest(int, char **);
int threadlisttest(int, char **);
/* thread tests */
int threadtest(int, char **);
int threadtest2(int, char **);
int threadtest3(int, char **);
int semtest(int, char **);
int locktest(int, char **);
int cvtest(int, char **);
int cvtest2(int, char **);
/* semaphore unit tests */
int semu1(int, char **);
int semu2(int, char **);
int semu3(int, char **);
int semu4(int, char **);
int semu5(int, char **);
int semu6(int, char **);
int semu7(int, char **);
int semu8(int, char **);
int semu9(int, char **);
int semu10(int, char **);
int semu11(int, char **);
int semu12(int, char **);
int semu13(int, char **);
int semu14(int, char **);
int semu15(int, char **);
int semu16(int, char **);
int semu17(int, char **);
int semu18(int, char **);
int semu19(int, char **);
int semu20(int, char **);
int semu21(int, char **);
int semu22(int, char **);
/* filesystem tests */
int fstest(int, char **);
int readstress(int, char **);
int writestress(int, char **);
int writestress2(int, char **);
int longstress(int, char **);
int createstress(int, char **);
int printfile(int, char **);
/* other tests */
int kmalloctest(int, char **);
int kmallocstress(int, char **);
int kmalloctest3(int, char **);
int kmalloctest4(int, char **);
int nettest(int, char **);
/* Routine for running a user-level program. */
int runprogram(char *progname);
/* Kernel menu system. */
void menu(char *argstr);
/* The main function, called from start.S. */
void kmain(char *bootstring);
#endif /* _TEST_H_ */

172
kern/include/thread.h Normal file
View File

@@ -0,0 +1,172 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _THREAD_H_
#define _THREAD_H_
/*
* Definition of a thread.
*
* Note: curthread is defined by <current.h>.
*/
#include <array.h>
#include <spinlock.h>
#include <threadlist.h>
struct cpu;
/* get machine-dependent defs */
#include <machine/thread.h>
/* Size of kernel stacks; must be power of 2 */
#define STACK_SIZE 4096
/* Mask for extracting the stack base address of a kernel stack pointer */
#define STACK_MASK (~(vaddr_t)(STACK_SIZE-1))
/* Macro to test if two addresses are on the same kernel stack */
#define SAME_STACK(p1, p2) (((p1) & STACK_MASK) == ((p2) & STACK_MASK))
/* States a thread can be in. */
typedef enum {
S_RUN, /* running */
S_READY, /* ready to run */
S_SLEEP, /* sleeping */
S_ZOMBIE, /* zombie; exited but not yet deleted */
} threadstate_t;
/* Thread structure. */
struct thread {
/*
* These go up front so they're easy to get to even if the
* debugger is messed up.
*/
char *t_name; /* Name of this thread */
const char *t_wchan_name; /* Name of wait channel, if sleeping */
threadstate_t t_state; /* State this thread is in */
/*
* Thread subsystem internal fields.
*/
struct thread_machdep t_machdep; /* Any machine-dependent goo */
struct threadlistnode t_listnode; /* Link for run/sleep/zombie lists */
void *t_stack; /* Kernel-level stack */
struct switchframe *t_context; /* Saved register context (on stack) */
struct cpu *t_cpu; /* CPU thread runs on */
struct proc *t_proc; /* Process thread belongs to */
/*
* Interrupt state fields.
*
* t_in_interrupt is true if current execution is in an
* interrupt handler, which means the thread's normal context
* of execution is stopped somewhere in the middle of doing
* something else. This makes assorted operations unsafe.
*
* See notes in spinlock.c regarding t_curspl and t_iplhigh_count.
*
* Exercise for the student: why is this material per-thread
* rather than per-cpu or global?
*/
bool t_in_interrupt; /* Are we in an interrupt? */
int t_curspl; /* Current spl*() state */
int t_iplhigh_count; /* # of times IPL has been raised */
/*
* Public fields
*/
/* add more here as needed */
};
/*
* Array of threads.
*/
#ifndef THREADINLINE
#define THREADINLINE INLINE
#endif
DECLARRAY(thread, THREADINLINE);
DEFARRAY(thread, THREADINLINE);
/* Call once during system startup to allocate data structures. */
void thread_bootstrap(void);
/* Call late in system startup to get secondary CPUs running. */
void thread_start_cpus(void);
/* Call during panic to stop other threads in their tracks */
void thread_panic(void);
/* Call during system shutdown to offline other CPUs. */
void thread_shutdown(void);
/*
* Make a new thread, which will start executing at "func". The thread
* will belong to the process "proc", or to the current thread's
* process if "proc" is null. The "data" arguments (one pointer, one
* number) are passed to the function. The current thread is used as a
* prototype for creating the new one. Returns an error code. The
* thread structure for the new thread is not returned; it is not in
* general safe to refer to it as the new thread may exit and
* disappear at any time without notice.
*/
int thread_fork(const char *name, struct proc *proc,
void (*func)(void *, unsigned long),
void *data1, unsigned long data2);
/*
* Cause the current thread to exit.
* Interrupts need not be disabled.
*/
__DEAD void thread_exit(void);
/*
* Cause the current thread to yield to the next runnable thread, but
* itself stay runnable.
* Interrupts need not be disabled.
*/
void thread_yield(void);
/*
* Reshuffle the run queue. Called from the timer interrupt.
*/
void schedule(void);
/*
* Potentially migrate ready threads to other CPUs. Called from the
* timer interrupt.
*/
void thread_consider_migration(void);
#endif /* _THREAD_H_ */

105
kern/include/threadlist.h Normal file
View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _THREADLIST_H_
#define _THREADLIST_H_
struct thread; /* from <thread.h> */
/*
* AmigaOS-style linked list of threads.
*
* The two threadlistnodes in the threadlist structure are always on
* the list, as bookends; this removes all the special cases in the
* list handling code. However, this means that iterating starts with
* the "second" element in the list (tl_head.tln_next, or
* tl_tail.tln_prev) and it ends at the last element that's actually a
* thread.
*
* Note that this means that assigning or memcpying threadlist
* structures will break them. Don't do that...
*
* ->tln_self always points to the thread that contains the
* threadlistnode. We could avoid this if we wanted to instead use
*
* (struct thread *)((char *)node - offsetof(struct thread, t_listnode))
*
* to get the thread pointer. But that's gross.
*/
struct threadlistnode {
struct threadlistnode *tln_prev;
struct threadlistnode *tln_next;
struct thread *tln_self;
};
struct threadlist {
struct threadlistnode tl_head;
struct threadlistnode tl_tail;
unsigned tl_count;
};
/* Initialize and clean up a thread list node. */
void threadlistnode_init(struct threadlistnode *tln, struct thread *self);
void threadlistnode_cleanup(struct threadlistnode *tln);
/* Initialize and clean up a thread list. Must be empty at cleanup. */
void threadlist_init(struct threadlist *tl);
void threadlist_cleanup(struct threadlist *tl);
/* Check if it's empty */
bool threadlist_isempty(struct threadlist *tl);
/* Add and remove: at ends */
void threadlist_addhead(struct threadlist *tl, struct thread *t);
void threadlist_addtail(struct threadlist *tl, struct thread *t);
struct thread *threadlist_remhead(struct threadlist *tl);
struct thread *threadlist_remtail(struct threadlist *tl);
/* Add and remove: in middle. (TL is needed to maintain ->tl_count.) */
void threadlist_insertafter(struct threadlist *tl,
struct thread *onlist, struct thread *addee);
void threadlist_insertbefore(struct threadlist *tl,
struct thread *addee, struct thread *onlist);
void threadlist_remove(struct threadlist *tl, struct thread *t);
/* Iteration; itervar should previously be declared as (struct thread *) */
#define THREADLIST_FORALL(itervar, tl) \
for ((itervar) = (tl).tl_head.tln_next->tln_self; \
(itervar) != NULL; \
(itervar) = (itervar)->t_listnode.tln_next->tln_self)
#define THREADLIST_FORALL_REV(itervar, tl) \
for ((itervar) = (tl).tl_tail.tln_prev->tln_self; \
(itervar) != NULL; \
(itervar) = (itervar)->t_listnode.tln_prev->tln_self)
#endif /* _THREADLIST_H_ */

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _THREADPRIVATE_H_
#define _THREADPRIVATE_H_
struct thread; /* from <thread.h> */
struct thread_machdep; /* from <machine/thread.h> */
struct switchframe; /* from <machine/switchframe.h> */
/*
* Subsystem-private thread defs.
*
* This file is to be used only by the thread subsystem. However, it
* has to be placed in the public include directory (rather than the
* threads directory) so the machine-dependent thread code can include
* it. This is one of the drawbacks of putting all machine-dependent
* material in a single directory: it exposes what ought to be private
* interfaces.
*/
/*
* Private thread functions.
*/
/* Entry point for new threads. */
void thread_startup(void (*entrypoint)(void *data1, unsigned long data2),
void *data1, unsigned long data2);
/* Initialize or clean up the machine-dependent portion of struct thread */
void thread_machdep_init(struct thread_machdep *tm);
void thread_machdep_cleanup(struct thread_machdep *tm);
/*
* Machine-dependent functions for working on switchframes.
*
* Note that while the functions themselves are machine-dependent, their
* declarations are not.
*/
/* Assembler-level context switch. */
void switchframe_switch(struct switchframe **prev, struct switchframe **next);
/* Thread initialization */
void switchframe_init(struct thread *,
void (*entrypoint)(void *data1, unsigned long data2),
void *data1, unsigned long data2);
#endif /* _THREADPRIVATE_H_ */

155
kern/include/types.h Normal file
View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _TYPES_H_
#define _TYPES_H_
/*
* Master kernel header file.
*
* The model for the include files in the kernel is as follows:
*
* - Every source file includes this file, <types.h>, first.
*
* - Every other header file may assume this file has been
* included, but should explicitly include any other headers it
* uses to compile.
*
* - Some exceptions to the previous rules exist among the headers
* exported to userland; those files should be included in the
* kernel only indirectly via other, non-exported, headers, as
* described in comments therein.
*
* - Every source or header file should include each file it
* directly uses, even if that header is included via some other
* header. This helps to prevent build failures when unrelated
* dependencies are changed around.
*
* - As a matter of convention, the ordering of include files in
* the base system is in order of subsystem dependence. That is,
* lower-level code like <spinlock.h> should come before
* higher-level code like <addrspace.h> or <vfs.h>. This
* convention helps one to keep keep track of (and learn) the
* organization of the system.
*
* The general ordering is as follows:
* 1. <types.h>
* 2. Kernel ABI definitions, e.g. <kern/errno.h>.
* 3. Support code: <lib.h>, arrays, queues, etc.
* 4. Low-level code: locks, trapframes, etc.
* 5. Kernel subsystems: threads, VM, VFS, etc.
* 6. System call layer, e.g. <elf.h>, <syscall.h>.
*
* Subsystem-private headers (the only extant example is
* switchframe.h) and then kernel option headers generated by
* config come last.
*
* There is no one perfect ordering, because the kernel is not
* composed of perfectly nested layers. But for the most part
* this principle produces a workable result.
*/
/* Get types visible to userland, both MI and MD. */
#include <kern/types.h>
/* Get machine-dependent types not visible to userland. */
#include <machine/types.h>
/*
* Define userptr_t as a pointer to a one-byte struct, so it won't mix
* with other pointers.
*/
struct __userptr { char _dummy; };
typedef struct __userptr *userptr_t;
typedef const struct __userptr *const_userptr_t;
/*
* Proper (non-underscore) names for the types that are exposed to
* userland.
*/
/* machine-dependent from <kern/machine/types.h>... */
typedef __i8 int8_t;
typedef __i16 int16_t;
typedef __i32 int32_t;
typedef __i64 int64_t;
typedef __u8 uint8_t;
typedef __u16 uint16_t;
typedef __u32 uint32_t;
typedef __u64 uint64_t;
typedef __size_t size_t;
typedef __ssize_t ssize_t;
typedef __intptr_t intptr_t;
typedef __uintptr_t uintptr_t;
typedef __ptrdiff_t ptrdiff_t;
/* ...and machine-independent from <kern/types.h>. */
typedef __blkcnt_t blkcnt_t;
typedef __blksize_t blksize_t;
typedef __daddr_t daddr_t;
typedef __dev_t dev_t;
typedef __fsid_t fsid_t;
typedef __gid_t gid_t;
typedef __in_addr_t in_addr_t;
typedef __in_port_t in_port_t;
typedef __ino_t ino_t;
typedef __mode_t mode_t;
typedef __nlink_t nlink_t;
typedef __off_t off_t;
typedef __pid_t pid_t;
typedef __rlim_t rlim_t;
typedef __sa_family_t sa_family_t;
typedef __time_t time_t;
typedef __uid_t uid_t;
typedef __nfds_t nfds_t;
typedef __socklen_t socklen_t;
/*
* Number of bits per byte.
*/
#define CHAR_BIT __CHAR_BIT
/*
* Null pointer.
*/
#define NULL ((void *)0)
/*
* Boolean.
*/
typedef _Bool bool;
#define true 1
#define false 0
#endif /* _TYPES_H_ */

142
kern/include/uio.h Normal file
View File

@@ -0,0 +1,142 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _UIO_H_
#define _UIO_H_
/*
* A uio is an abstraction encapsulating a memory block, some metadata
* about it, and also a cursor position associated with working
* through it. The uio structure is used to manage blocks of data
* moved around by the kernel.
*
* Note: struct iovec is in <kern/iovec.h>.
*
* The structure here is essentially the same as BSD uio. The
* position is maintained by incrementing the block pointer,
* decrementing the block size, decrementing the residue count, and
* also incrementing the seek offset in uio_offset. The last is
* intended to provide management for seek pointers.
*
* Callers of file system operations that take uios should honor the
* uio_offset values returned by these operations, as for directories
* they may not necessarily be byte counts and attempting to compute
* seek positions based on byte counts can produce wrong behavior.
*
* File system operations calling uiomove for directory data and not
* intending to use byte counts should update uio_offset to the
* desired value explicitly after calling uiomove, as uiomove always
* increments uio_offset by the number of bytes transferred.
*/
#include <kern/iovec.h>
/* Direction. */
enum uio_rw {
UIO_READ, /* From kernel to uio_seg */
UIO_WRITE, /* From uio_seg to kernel */
};
/* Source/destination. */
enum uio_seg {
UIO_USERISPACE, /* User process code. */
UIO_USERSPACE, /* User process data. */
UIO_SYSSPACE, /* Kernel. */
};
struct uio {
struct iovec *uio_iov; /* Data blocks */
unsigned uio_iovcnt; /* Number of iovecs */
off_t uio_offset; /* Desired offset into object */
size_t uio_resid; /* Remaining amt of data to xfer */
enum uio_seg uio_segflg; /* What kind of pointer we have */
enum uio_rw uio_rw; /* Whether op is a read or write */
struct addrspace *uio_space; /* Address space for user pointer */
};
/*
* Copy data from a kernel buffer to a data region defined by a uio struct,
* updating the uio struct's offset and resid fields. May alter the iovec
* fields as well.
*
* Before calling this, you should
* (1) set up uio_iov to point to the buffer(s) you want to transfer
* to, and set uio_iovcnt to the number of such buffers;
* (2) initialize uio_offset as desired;
* (3) initialize uio_resid to the total amount of data that can be
* transferred through this uio;
* (4) set up uio_seg and uio_rw correctly;
* (5) if uio_seg is UIO_SYSSPACE, set uio_space to NULL; otherwise,
* initialize uio_space to the address space in which the buffer
* should be found.
*
* After calling,
* (1) the contents of uio_iov and uio_iovcnt may be altered and
* should not be interpreted;
* (2) uio_offset will have been incremented by the amount transferred;
* (3) uio_resid will have been decremented by the amount transferred;
* (4) uio_segflg, uio_rw, and uio_space will be unchanged.
*
* uiomove() may be called repeatedly on the same uio to transfer
* additional data until the available buffer space the uio refers to
* is exhausted.
*
* Note that the actual value of uio_offset is not interpreted. It is
* provided (and updated by uiomove) to allow for easier file seek
* pointer management.
*
* When uiomove is called, the address space presently in context must
* be the same as the one recorded in uio_space. This is an important
* sanity check if I/O has been queued.
*/
int uiomove(void *kbuffer, size_t len, struct uio *uio);
/*
* Like uiomove, but sends zeros.
*/
int uiomovezeros(size_t len, struct uio *uio);
/*
* Initialize a uio suitable for I/O from a kernel buffer.
*
* Usage example;
* char buf[128];
* struct iovec iov;
* struct uio myuio;
*
* uio_kinit(&iov, &myuio, buf, sizeof(buf), 0, UIO_READ);
* result = VOP_READ(vn, &myuio);
* ...
*/
void uio_kinit(struct iovec *, struct uio *,
void *kbuf, size_t len, off_t pos, enum uio_rw rw);
#endif /* _UIO_H_ */

45
kern/include/version.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _VERSION_H_
#define _VERSION_H_
/*
* Leave this alone, so we can tell what version of the OS/161 base
* code we gave you.
*/
#define BASE_VERSION "2.0.1"
/*
* Change this as you see fit in the course of hacking the system.
*/
#define GROUP_VERSION "0"
#endif /* _VERSION_H_ */

196
kern/include/vfs.h Normal file
View File

@@ -0,0 +1,196 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _VFS_H_
#define _VFS_H_
#include <array.h>
/*
* Virtual File System layer functions.
*
* The VFS layer translates operations on abstract on-disk files or
* pathnames to operations on specific files on specific filesystems.
*/
struct uio; /* kernel or userspace I/O buffer (uio.h) */
struct device; /* abstract structure for a device (dev.h) */
struct fs; /* abstract structure for a filesystem (fs.h) */
struct vnode; /* abstract structure for an on-disk file (vnode.h) */
/*
* VFS layer low-level operations.
* See vnode.h for direct operations on vnodes.
* See fs.h for direct operations on filesystems/devices.
*
* vfs_setcurdir - change current directory of current thread by vnode
* vfs_clearcurdir - change current directory of current thread to "none"
* vfs_getcurdir - retrieve vnode of current directory of current thread
* vfs_sync - force all dirty buffers to disk
* vfs_getroot - get root vnode for the filesystem named DEVNAME
* vfs_getdevname - get mounted device name for the filesystem passed in
*/
int vfs_setcurdir(struct vnode *dir);
int vfs_clearcurdir(void);
int vfs_getcurdir(struct vnode **retdir);
int vfs_sync(void);
int vfs_getroot(const char *devname, struct vnode **result);
const char *vfs_getdevname(struct fs *fs);
/*
* VFS layer mid-level operations.
*
* vfs_lookup - Like VOP_LOOKUP, but takes a full device:path name,
* or a name relative to the current directory, and
* goes to the correct filesystem.
* vfs_lookparent - Likewise, for VOP_LOOKPARENT.
*
* Both of these may destroy the path passed in.
*/
int vfs_lookup(char *path, struct vnode **result);
int vfs_lookparent(char *path, struct vnode **result,
char *buf, size_t buflen);
/*
* VFS layer high-level operations on pathnames
* Because lookup may destroy pathnames, these all may too.
*
* vfs_open - Open or create a file. FLAGS/MODE per the syscall.
* vfs_readlink - Read contents of a symlink into a uio.
* vfs_symlink - Create a symlink PATH containing contents CONTENTS.
* vfs_mkdir - Create a directory. MODE per the syscall.
* vfs_link - Create a hard link to a file.
* vfs_remove - Delete a file.
* vfs_rmdir - Delete a directory.
* vfs_rename - rename a file.
*
* vfs_chdir - Change current directory of current thread by name.
* vfs_getcwd - Retrieve name of current directory of current thread.
*
* vfs_close - Close a vnode opened with vfs_open. Does not fail.
* (See vfspath.c for a discussion of why.)
*/
int vfs_open(char *path, int openflags, mode_t mode, struct vnode **ret);
void vfs_close(struct vnode *vn);
int vfs_readlink(char *path, struct uio *data);
int vfs_symlink(const char *contents, char *path);
int vfs_mkdir(char *path, mode_t mode);
int vfs_link(char *oldpath, char *newpath);
int vfs_remove(char *path);
int vfs_rmdir(char *path);
int vfs_rename(char *oldpath, char *newpath);
int vfs_chdir(char *path);
int vfs_getcwd(struct uio *buf);
/*
* Misc
*
* vfs_bootstrap - Call during system initialization to allocate
* structures.
*
* vfs_setbootfs - Set the filesystem that paths beginning with a
* slash are sent to. If not set, these paths fail
* with ENOENT. The argument should be the device
* name or volume name for the filesystem (such as
* "lhd0:") but need not have the trailing colon.
*
* vfs_clearbootfs - Clear the bootfs filesystem. This should be
* done during shutdown so that the filesystem in
* question can be unmounted.
*
* vfs_adddev - Add a device to the VFS named device list. If
* MOUNTABLE is zero, the device will be accessible
* as "DEVNAME:". If the mountable flag is set, the
* device will be accessible as "DEVNAMEraw:" and
* mountable under the name "DEVNAME". Thus, the
* console, added with MOUNTABLE not set, would be
* accessed by pathname as "con:", and lhd0, added
* with mountable set, would be accessed by
* pathname as "lhd0raw:" and mounted by passing
* "lhd0" to vfs_mount.
*
* vfs_addfs - Add a hardwired filesystem to the VFS named device
* list. It will be accessible as "devname:". This is
* intended for filesystem-devices like emufs, and
* gizmos like Linux procfs or BSD kernfs, not for
* mounting filesystems on disk devices.
*
* vfs_mount - Attempt to mount a filesystem on a device. The
* device named by DEVNAME will be looked up and
* passed, along with DATA, to the supplied function
* MOUNTFUNC, which should create a struct fs and
* return it in RESULT.
*
* vfs_unmount - Unmount the filesystem presently mounted on the
* specified device.
*
* vfs_unmountall - Unmount all mounted filesystems.
*/
void vfs_bootstrap(void);
int vfs_setbootfs(const char *fsname);
void vfs_clearbootfs(void);
int vfs_adddev(const char *devname, struct device *dev, int mountable);
int vfs_addfs(const char *devname, struct fs *fs);
int vfs_mount(const char *devname, void *data,
int (*mountfunc)(void *data,
struct device *dev,
struct fs **result));
int vfs_unmount(const char *devname);
int vfs_unmountall(void);
/*
* Array of vnodes.
*/
#ifndef VFSINLINE
#define VFSINLINE INLINE
#endif
DECLARRAY(vnode, VFSINLINE);
DEFARRAY(vnode, VFSINLINE);
/*
* Global one-big-lock for all filesystem operations.
* You must remove this for the filesystem assignment.
*/
void vfs_biglock_acquire(void);
void vfs_biglock_release(void);
bool vfs_biglock_do_i_hold(void);
#endif /* _VFS_H_ */

63
kern/include/vm.h Normal file
View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _VM_H_
#define _VM_H_
/*
* VM system-related definitions.
*
* You'll probably want to add stuff here.
*/
#include <machine/vm.h>
/* Fault-type arguments to vm_fault() */
#define VM_FAULT_READ 0 /* A read was attempted */
#define VM_FAULT_WRITE 1 /* A write was attempted */
#define VM_FAULT_READONLY 2 /* A write to a readonly page was attempted*/
/* Initialization function */
void vm_bootstrap(void);
/* Fault handling function called by trap code */
int vm_fault(int faulttype, vaddr_t faultaddress);
/* Allocate/free kernel heap pages (called by kmalloc/kfree) */
vaddr_t alloc_kpages(unsigned npages);
void free_kpages(vaddr_t addr);
/* TLB shootdown handling called from interprocessor_interrupt */
void vm_tlbshootdown_all(void);
void vm_tlbshootdown(const struct tlbshootdown *);
#endif /* _VM_H_ */

316
kern/include/vnode.h Normal file
View File

@@ -0,0 +1,316 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _VNODE_H_
#define _VNODE_H_
#include <spinlock.h>
struct uio;
struct stat;
/*
* A struct vnode is an abstract representation of a file.
*
* It is an interface in the Java sense that allows the kernel's
* filesystem-independent code to interact usefully with multiple sets
* of filesystem code.
*/
/*
* Abstract low-level file.
*
* Note: vn_fs may be null if the vnode refers to a device.
*/
struct vnode {
int vn_refcount; /* Reference count */
struct spinlock vn_countlock; /* Lock for vn_refcount */
struct fs *vn_fs; /* Filesystem vnode belongs to */
void *vn_data; /* Filesystem-specific data */
const struct vnode_ops *vn_ops; /* Functions on this vnode */
};
/*
* Abstract operations on a vnode.
*
* These are used in the form VOP_FOO(vnode, args), which are macros
* that expands to vnode->vn_ops->vop_foo(vnode, args). The operations
* "foo" are:
*
* vop_eachopen - Called on *each* open() of a file. Can be used to
* reject illegal or undesired open modes. Note that
* various operations can be performed without the
* file actually being opened.
* The vnode need not look at O_CREAT, O_EXCL, or
* O_TRUNC, as these are handled in the VFS layer.
*
* VOP_EACHOPEN should not be called directly from
* above the VFS layer - use vfs_open() to open vnodes.
*
* vop_reclaim - Called when vnode is no longer in use.
*
*****************************************
*
* vop_read - Read data from file to uio, at offset specified
* in the uio, updating uio_resid to reflect the
* amount read, and updating uio_offset to match.
* Not allowed on directories or symlinks.
*
* vop_readlink - Read the contents of a symlink into a uio.
* Not allowed on other types of object.
*
* vop_getdirentry - Read a single filename from a directory into a
* uio, choosing what name based on the offset
* field in the uio, and updating that field.
* Unlike with I/O on regular files, the value of
* the offset field is not interpreted outside
* the filesystem and thus need not be a byte
* count. However, the uio_resid field should be
* handled in the normal fashion.
* On non-directory objects, return ENOTDIR.
*
* vop_write - Write data from uio to file at offset specified
* in the uio, updating uio_resid to reflect the
* amount written, and updating uio_offset to match.
* Not allowed on directories or symlinks.
*
* vop_ioctl - Perform ioctl operation OP on file using data
* DATA. The interpretation of the data is specific
* to each ioctl.
*
* vop_stat - Return info about a file. The pointer is a
* pointer to struct stat; see kern/stat.h.
*
* vop_gettype - Return type of file. The values for file types
* are in kern/stattypes.h.
*
* vop_isseekable - Check if this file is seekable. All regular files
* and directories are seekable, but some devices are
* not.
*
* vop_fsync - Force any dirty buffers associated with this file
* to stable storage.
*
* vop_mmap - Map file into memory. If you implement this
* feature, you're responsible for choosing the
* arguments for this operation.
*
* vop_truncate - Forcibly set size of file to the length passed
* in, discarding any excess blocks.
*
* vop_namefile - Compute pathname relative to filesystem root
* of the file and copy to the specified
* uio. Need not work on objects that are not
* directories.
*
*****************************************
*
* vop_creat - Create a regular file named NAME in the passed
* directory DIR. If boolean EXCL is true, fail if
* the file already exists; otherwise, use the
* existing file if there is one. Hand back the
* vnode for the file as per vop_lookup.
*
* vop_symlink - Create symlink named NAME in the passed directory,
* with contents CONTENTS.
*
* vop_mkdir - Make directory NAME in the passed directory PARENTDIR.
*
* vop_link - Create hard link, with name NAME, to file FILE
* in the passed directory DIR.
*
* vop_remove - Delete non-directory object NAME from passed
* directory. If NAME refers to a directory,
* return EISDIR. If passed vnode is not a
* directory, return ENOTDIR.
*
* vop_rmdir - Delete directory object NAME from passed
* directory.
*
* vop_rename - Rename file NAME1 in directory VN1 to be
* file NAME2 in directory VN2.
*
*****************************************
*
* vop_lookup - Parse PATHNAME relative to the passed directory
* DIR, and hand back the vnode for the file it
* refers to. May destroy PATHNAME. Should increment
* refcount on vnode handed back.
*
* vop_lookparent - Parse PATHNAME relative to the passed directory
* DIR, and hand back (1) the vnode for the
* parent directory of the file it refers to, and
* (2) the last component of the filename, copied
* into kernel buffer BUF with max length LEN. May
* destroy PATHNAME. Should increment refcount on
* vnode handed back.
*/
#define VOP_MAGIC 0xa2b3c4d5
struct vnode_ops {
unsigned long vop_magic; /* should always be VOP_MAGIC */
int (*vop_eachopen)(struct vnode *object, int flags_from_open);
int (*vop_reclaim)(struct vnode *vnode);
int (*vop_read)(struct vnode *file, struct uio *uio);
int (*vop_readlink)(struct vnode *link, struct uio *uio);
int (*vop_getdirentry)(struct vnode *dir, struct uio *uio);
int (*vop_write)(struct vnode *file, struct uio *uio);
int (*vop_ioctl)(struct vnode *object, int op, userptr_t data);
int (*vop_stat)(struct vnode *object, struct stat *statbuf);
int (*vop_gettype)(struct vnode *object, mode_t *result);
bool (*vop_isseekable)(struct vnode *object);
int (*vop_fsync)(struct vnode *object);
int (*vop_mmap)(struct vnode *file /* add stuff */);
int (*vop_truncate)(struct vnode *file, off_t len);
int (*vop_namefile)(struct vnode *file, struct uio *uio);
int (*vop_creat)(struct vnode *dir,
const char *name, bool excl, mode_t mode,
struct vnode **result);
int (*vop_symlink)(struct vnode *dir,
const char *contents, const char *name);
int (*vop_mkdir)(struct vnode *parentdir,
const char *name, mode_t mode);
int (*vop_link)(struct vnode *dir,
const char *name, struct vnode *file);
int (*vop_remove)(struct vnode *dir,
const char *name);
int (*vop_rmdir)(struct vnode *dir,
const char *name);
int (*vop_rename)(struct vnode *vn1, const char *name1,
struct vnode *vn2, const char *name2);
int (*vop_lookup)(struct vnode *dir,
char *pathname, struct vnode **result);
int (*vop_lookparent)(struct vnode *dir,
char *pathname, struct vnode **result,
char *buf, size_t len);
};
#define __VOP(vn, sym) (vnode_check(vn, #sym), (vn)->vn_ops->vop_##sym)
#define VOP_EACHOPEN(vn, flags) (__VOP(vn, eachopen)(vn, flags))
#define VOP_RECLAIM(vn) (__VOP(vn, reclaim)(vn))
#define VOP_READ(vn, uio) (__VOP(vn, read)(vn, uio))
#define VOP_READLINK(vn, uio) (__VOP(vn, readlink)(vn, uio))
#define VOP_GETDIRENTRY(vn, uio) (__VOP(vn,getdirentry)(vn, uio))
#define VOP_WRITE(vn, uio) (__VOP(vn, write)(vn, uio))
#define VOP_IOCTL(vn, code, buf) (__VOP(vn, ioctl)(vn,code,buf))
#define VOP_STAT(vn, ptr) (__VOP(vn, stat)(vn, ptr))
#define VOP_GETTYPE(vn, result) (__VOP(vn, gettype)(vn, result))
#define VOP_ISSEEKABLE(vn) (__VOP(vn, isseekable)(vn))
#define VOP_FSYNC(vn) (__VOP(vn, fsync)(vn))
#define VOP_MMAP(vn /*add stuff */) (__VOP(vn, mmap)(vn /*add stuff */))
#define VOP_TRUNCATE(vn, pos) (__VOP(vn, truncate)(vn, pos))
#define VOP_NAMEFILE(vn, uio) (__VOP(vn, namefile)(vn, uio))
#define VOP_CREAT(vn,nm,excl,mode,res) (__VOP(vn, creat)(vn,nm,excl,mode,res))
#define VOP_SYMLINK(vn, name, content) (__VOP(vn, symlink)(vn, name, content))
#define VOP_MKDIR(vn, name, mode) (__VOP(vn, mkdir)(vn, name, mode))
#define VOP_LINK(vn, name, vn2) (__VOP(vn, link)(vn, name, vn2))
#define VOP_REMOVE(vn, name) (__VOP(vn, remove)(vn, name))
#define VOP_RMDIR(vn, name) (__VOP(vn, rmdir)(vn, name))
#define VOP_RENAME(vn1,name1,vn2,name2)(__VOP(vn1,rename)(vn1,name1,vn2,name2))
#define VOP_LOOKUP(vn, name, res) (__VOP(vn, lookup)(vn, name, res))
#define VOP_LOOKPARENT(vn,nm,res,bf,ln) (__VOP(vn,lookparent)(vn,nm,res,bf,ln))
/*
* Consistency check
*/
void vnode_check(struct vnode *, const char *op);
/*
* Reference count manipulation (handled above filesystem level)
*/
void vnode_incref(struct vnode *);
void vnode_decref(struct vnode *);
#define VOP_INCREF(vn) vnode_incref(vn)
#define VOP_DECREF(vn) vnode_decref(vn)
/*
* Vnode initialization (intended for use by filesystem code)
* The reference count is initialized to 1.
*/
int vnode_init(struct vnode *, const struct vnode_ops *ops,
struct fs *fs, void *fsdata);
/*
* Vnode final cleanup (intended for use by filesystem code)
* The reference count is asserted to be 1.
*/
void vnode_cleanup(struct vnode *);
/*
* Common stubs for vnode functions that just fail, in various ways.
*/
int vopfail_uio_notdir(struct vnode *vn, struct uio *uio);
int vopfail_uio_isdir(struct vnode *vn, struct uio *uio);
int vopfail_uio_inval(struct vnode *vn, struct uio *uio);
int vopfail_uio_nosys(struct vnode *vn, struct uio *uio);
int vopfail_mmap_isdir(struct vnode *vn /* add stuff */);
int vopfail_mmap_perm(struct vnode *vn /* add stuff */);
int vopfail_mmap_nosys(struct vnode *vn /* add stuff */);
int vopfail_truncate_isdir(struct vnode *vn, off_t pos);
int vopfail_creat_notdir(struct vnode *vn, const char *name, bool excl,
mode_t mode, struct vnode **result);
int vopfail_symlink_notdir(struct vnode *vn, const char *contents,
const char *name);
int vopfail_symlink_nosys(struct vnode *vn, const char *contents,
const char *name);
int vopfail_mkdir_notdir(struct vnode *vn, const char *name, mode_t mode);
int vopfail_mkdir_nosys(struct vnode *vn, const char *name, mode_t mode);
int vopfail_link_notdir(struct vnode *dir, const char *name,
struct vnode *file);
int vopfail_link_nosys(struct vnode *dir, const char *name,
struct vnode *file);
int vopfail_string_notdir(struct vnode *vn, const char *name);
int vopfail_string_nosys(struct vnode *vn, const char *name);
int vopfail_rename_notdir(struct vnode *fromdir, const char *fromname,
struct vnode *todir, const char *toname);
int vopfail_rename_nosys(struct vnode *fromdir, const char *fromname,
struct vnode *todir, const char *toname);
int vopfail_lookup_notdir(struct vnode *vn, char *path, struct vnode **result);
int vopfail_lookparent_notdir(struct vnode *vn, char *path,
struct vnode **result, char *buf, size_t len);
#endif /* _VNODE_H_ */

80
kern/include/wchan.h Normal file
View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _WCHAN_H_
#define _WCHAN_H_
/*
* Wait channel.
*/
struct spinlock; /* in spinlock.h */
struct wchan; /* Opaque */
/*
* Create a wait channel. Use NAME as a symbolic name for the channel.
* NAME should be a string constant; if not, the caller is responsible
* for freeing it after the wchan is destroyed.
*/
struct wchan *wchan_create(const char *name);
/*
* Destroy a wait channel. Must be empty and unlocked.
*/
void wchan_destroy(struct wchan *wc);
/*
* Return nonzero if there are no threads sleeping on the channel.
* This is meant to be used only for diagnostic purposes.
*/
bool wchan_isempty(struct wchan *wc, struct spinlock *lk);
/*
* Go to sleep on a wait channel. The current thread is suspended
* until awakened by someone else, at which point this function
* returns.
*
* The associated lock must be locked. It will be unlocked while
* sleeping, and relocked upon return.
*/
void wchan_sleep(struct wchan *wc, struct spinlock *lk);
/*
* Wake up one thread, or all threads, sleeping on a wait channel.
* The associated spinlock should be locked.
*
* The current implementation is FIFO but this is not promised by the
* interface.
*/
void wchan_wakeone(struct wchan *wc, struct spinlock *lk);
void wchan_wakeall(struct wchan *wc, struct spinlock *lk);
#endif /* _WCHAN_H_ */