summaryrefslogtreecommitdiff
path: root/nuttx/include
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-03-20 16:51:12 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-03-20 16:51:12 +0000
commit360b2b7ab8fd7cf337f02e260346a0f0ecbb8064 (patch)
tree7e83b806156983fa5af8a32715d849762b8c7346 /nuttx/include
parentd913f00d3b4bcbebc12dfa7ea017bacd17464b88 (diff)
downloadpx4-nuttx-360b2b7ab8fd7cf337f02e260346a0f0ecbb8064.tar.gz
px4-nuttx-360b2b7ab8fd7cf337f02e260346a0f0ecbb8064.tar.bz2
px4-nuttx-360b2b7ab8fd7cf337f02e260346a0f0ecbb8064.zip
Restructure header files for POSIX compliance; eliminate compile warnings
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@107 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include')
-rw-r--r--nuttx/include/ctype.h65
-rw-r--r--nuttx/include/fcntl.h181
-rw-r--r--nuttx/include/limits.h138
-rw-r--r--nuttx/include/mqueue.h63
-rw-r--r--nuttx/include/nuttx/sched.h287
-rw-r--r--nuttx/include/pthread.h195
-rw-r--r--nuttx/include/sched.h254
-rw-r--r--nuttx/include/semaphore.h9
-rw-r--r--nuttx/include/signal.h88
-rw-r--r--nuttx/include/stdio.h39
-rw-r--r--nuttx/include/sys/types.h28
-rw-r--r--nuttx/include/time.h84
-rw-r--r--nuttx/include/unistd.h54
13 files changed, 942 insertions, 543 deletions
diff --git a/nuttx/include/ctype.h b/nuttx/include/ctype.h
index fb30746de..6cc2cb895 100644
--- a/nuttx/include/ctype.h
+++ b/nuttx/include/ctype.h
@@ -76,7 +76,7 @@
*
************************************************************/
-#define isascii(c) ((c) >= 0 && (c) <= 0x7f);
+#define isascii(c) ((c) >= 0 && (c) <= 0x7f);
/************************************************************
* Function: isprint
@@ -86,7 +86,17 @@
*
************************************************************/
-#define isprint(c) ((c) >= 0x20 && (c) < 0x7f)
+#define isprint(c) ((c) >= 0x20 && (c) < 0x7f)
+
+/************************************************************
+ * Function: isgraph
+ *
+ * Description:
+ * Checks for a printable character (excluding space)
+ *
+ ************************************************************/
+
+#define isgraph(c) ((c) > 0x20 && (c) < 0x7f)
/************************************************************
* Function: iscntrl
@@ -99,6 +109,36 @@
#define iscontrol(c) (!isprint(c))
/************************************************************
+ * Function: islower
+ *
+ * Description:
+ * Checks for an lowercase letter.
+ *
+ ************************************************************/
+
+#define islower(c) ((c) >= 'a' && (c) <= 'z')
+
+/************************************************************
+ * Function: isupper
+ *
+ * Description:
+ * Checks for an uppercase letter.
+ *
+ ************************************************************/
+
+#define isupper(c) ((c) >= 'a' && (c) <= 'z')
+
+/************************************************************
+ * Function: isalpha
+ *
+ * Description:
+ * Checks for an alphabetic character
+ *
+ ************************************************************/
+
+#define isalpha(c) (islower(c) || isupper(c))
+
+/************************************************************
* Function: isdigit
*
* Description:
@@ -109,6 +149,27 @@
#define isdigit(c) ((c) >= '0' && (c) <= '9')
/************************************************************
+ * Function: isalnum
+ *
+ * Description:
+ * Checks for an alphanumeric character
+ *
+ ************************************************************/
+
+#define isalnum(c) (isalpha(c) || isdigit(c))
+
+/************************************************************
+ * Function: ispunct
+ *
+ * Description:
+ * Checks for a printable character which is not a space
+ * or an alphanumeric character
+ *
+ ************************************************************/
+
+#define ispunct(c) (isgraph(c) && !isalnum(c))
+
+/************************************************************
* Function: isxdigit
*
* Description:
diff --git a/nuttx/include/fcntl.h b/nuttx/include/fcntl.h
new file mode 100644
index 000000000..1949be42a
--- /dev/null
+++ b/nuttx/include/fcntl.h
@@ -0,0 +1,181 @@
+/********************************************************************************
+ * fcntl.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 Gregory Nutt 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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 __FCNTL_H
+#define __FCNTL_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+/********************************************************************************
+ * Definitions
+ ********************************************************************************/
+
+/* open flag settings for open() (and related APIs) */
+
+#define O_RDONLY 0x01 /* Open for read access */
+#define O_WRONLY 0x02 /* Open for write access */
+#define O_RDWR 0x03 /* Open for both read & write access */
+#define O_CREAT 0x04 /* Create file/sem/mq object */
+#define O_EXCL 0x08 /* Name must not exist when opened */
+#define O_APPEND 0x10 /* Keep contents, append to end */
+#define O_TRUNC 0x20 /* Delete contents */
+#define O_NONBLOCK 0x40 /* Don't wait for data */
+#define O_SYNC 0x80 /* Synchronize output on write */
+#define O_DSYNC OSYNC
+
+#define O_RSYNC 0x00 /* Sychronize input on read */
+#define O_ACCMODE 0x00 /* Required by POSIX */
+#define O_NOCTTY 0x00 /* Reqired by POSIX */
+
+#define O_RDOK O_RDONLY /* Not POSIX */
+#define O_WROK O_WRONLY /* Not POSIX */
+
+/* fcntl() commands */
+
+#define F_DUPFD 0 /* Duplicate a file descriptor */
+#define F_GETFD 1 /* Read the file descriptor flags */
+#define F_GETFL 2 /* Read the file status flags */
+#define F_GETLEASE 3 /* Indicas what type of lease is held on fd (linux) */
+#define F_GETLK 4 /* Check if we could place a lock */
+#define F_GETOWN 5 /* Get the pid receiving SIGIO and SIGURG signals for fd */
+#define F_GETSIG 6 /* Get the signal sent */
+#define F_NOTIFY 7 /* Provide notification when directory referred to by fd changes (linux)*/
+#define F_SETFD 8 /* Set the file descriptor flags to value */
+#define F_SETFL 9 /* Set the file status flags to the value */
+#define F_SETLEASE 10 /* Set or remove file lease (linux) */
+#define F_SETLK 11 /* Acquire or release a lock on range of bytes */
+#define F_SETLKW 12 /* Like F_SETLK, but wait for lock to become available */
+#define F_SETOWN 13 /* Set pid that will receive SIGIO and SIGURG signals for fd */
+#define F_SETSIG 14 /* Set the signal to be sent */
+
+/* close-on-exec flag for F_GETRL and F_SETFL */
+
+#define FD_CLOEXEC 1
+
+/* Arguments to F_SETLEASE */
+
+#define F_RDLCK 0 /* Take out a read lease */
+#define F_WRLCK 2 /* Take out a write lease */
+#define F_UNLCK 3 /* Remove a lease */
+
+/* These are the notifications that can be received from F_NOTIFY (linux) */
+
+#define DN_ACCESS 0 /* A file was accessed */
+#define DN_MODIFY 1 /* A file was modified */
+#define DN_CREATE 2 /* A file was created */
+#define DN_DELETE 3 /* A file was unlinked */
+#define DN_RENAME 4 /* A file was renamed */
+#define DN_ATTRIB 5 /* Attributes of a file were changed */
+
+#define S_IFMT 0170000
+#define S_IFSOCK 0140000
+#define S_IFLNK 0120000
+#define S_IFREG 0100000
+#define S_IFBLK 0060000
+#define S_IFCHR 0020000
+#define S_IFDIR 0040000
+#define S_IFIFO 0010000
+#define S_ISUID 0004000
+#define S_ISGID 0002000
+#define S_ISVTX 0001000
+#define S_IRWXU 0000700
+#define S_IRUSR 0000400
+#define S_IWUSR 0000200
+#define S_IXUSR 0000100
+#define S_IRWXG 0000070
+#define S_IRGRP 0000040
+#define S_IWGRP 0000020
+#define S_IXGRP 0000010
+#define S_IRWXO 0000007
+#define S_IROTH 0000004
+#define S_IWOTH 0000002
+#define S_IXOTH 0000001
+
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+
+/********************************************************************************
+ * Public Type Definitions
+ ********************************************************************************/
+
+/* struct flock is the third argument for F_GETLK, F_SETLK and F_SETLKW */
+
+struct flock
+{
+ short l_type; /* Type of lock: F_RDLCK, F_WRLCK, F_UNLCK */
+ short l_whence; /* How to interpret l_start: SEEK_SET, SEEK_CUR, SEEK_END */
+ off_t l_start; /* Starting offset for lock */
+ off_t l_len; /* Number of bytes to lock */
+ pid_t l_pid; /* PID of process blocking our lock (F_GETLK only) */
+};
+
+/********************************************************************************
+ * Public Variables
+ ********************************************************************************/
+
+/********************************************************************************
+ * Public Function Prototypes
+ ********************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* POSIX-like File System Interfaces */
+
+EXTERN int creat(const char *path, mode_t mode);
+EXTERN int open(const char *path, int oflag, ...);
+EXTERN int fcntl(int fd, int cmd, ...);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __FCNTL_H */
diff --git a/nuttx/include/limits.h b/nuttx/include/limits.h
index da3cebaf9..285eea684 100644
--- a/nuttx/include/limits.h
+++ b/nuttx/include/limits.h
@@ -1,4 +1,4 @@
-/************************************************************
+/********************************************************************************
* limits.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
@@ -31,14 +31,14 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ********************************************************************************/
#ifndef __LIMITS_H
#define __LIMITS_H
-/************************************************************
+/********************************************************************************
* Included Files
- ************************************************************/
+ ********************************************************************************/
#include <nuttx/config.h>
@@ -46,13 +46,133 @@
#include <arch/limits.h>
-/************************************************************
+/********************************************************************************
* Definitions
- ************************************************************/
+ ********************************************************************************/
-/* Configurable limits */
+/* Configurable limits required by POSIX
+ *
+ * Required for all implementations:
+ *
+ * _POSIX_ARG_MAX Total length of string arguments
+ * _POSIX_CHILD_MAX Number of child tasks active
+ * _POSIX_LINK_MAX The number of links a file can have
+ * _POSIX_MAX_CANON Number bytes in TTY canonical input queue
+ * _POSIX_MAX_INPUT Number bytes in TTY canonical input queue
+ * _POSIX_NAME_MAX Number of bytes in a file or pathname component
+ * _POSIX_NGROUPS_MAX Number supplementary group IDs
+ * _POSIX_OPEN_MAX Number of files a task can have open at once
+ * _POSIX_PATH_MAX Number of bytes in a full pathname
+ * _POSIX_PIPE_BUF Number of bytes for atomic write into pipe
+ * _POSIX_SSIZE_MAX Largest filesystem write; also max value of ssize_t
+ * _POSIX_STREAM_MAX Number of std I/O streams open at once
+ * _POSIX_TZNAME_MAX Max number of bytes of a timezone name
+ *
+ * Required for sigqueue
+ *
+ * _POSIX_RTSIG_MAX Difference between SIGRTMIN and SIGRTMAX
+ * _POSIX_SIGQUEUE_MAX Max number signals a task can queue
+ *
+ * Required for POSIX timers
+ *
+ * _POSIX_DELAYTIMER_MAX Max number timer overruns
+ * _POSIX_TIMER_MAX Max number of timers per task
+ * _POSIX_CLOCKRES_MIN Clock resolution in nanoseconds
+ *
+ * Required for asynchronous I/O
+ *
+ * _POSIX_AIO_LISTIO_MAX Max number of AIOs in single listio call
+ * _POSIX_AIO_MAX Max number of simultaneous AIO operations
+ *
+ * Required for POSIX message passing
+ *
+ * _POSIX_MQ_OPEN_MAX Max number message queues task may open (mq_open)
+ * _POSIX_MQ_PRIO_MAX Max message priority (mq_send)
+ *
+ * Required for POSIX semaphores
+ *
+ * _POSIX_SEM_NSEMS_MAX Max number of open semaphores per task
+ * _POSIX_SEM_VALUE_MAX Max value a semaphore may have
+ */
+
+#define _POSIX_ARG_MAX 4096
+#define _POSIX_CHILD_MAX 6
+#define _POSIX_LINK_MAX 8
+#define _POSIX_MAX_CANON 255
+#define _POSIX_MAX_INPUT 255
+#define _POSIX_NAME_MAX CONFIG_NAME_MAX
+#define _POSIX_NGROUPS_MAX 0
+#define _POSIX_OPEN_MAX CONFIG_NFILE_DESCRIPTORS
+#define _POSIX_PATH_MAX 255
+#define _POSIX_PIPE_BUF 512
+#define _POSIX_SSIZE_MAX INT_MAX
+#define _POSIX_STREAM_MAX CONFIG_NFILE_STREAMS
+#define _POSIX_TZNAME_MAX 3
+
+/* Requred for sigqueue */
+
+#define _POSIX_RTSIG_MAX 31
+#define _POSIX_SIGQUEUE_MAX 32
+
+/* Required for POSIX timers */
+
+#define _POSIX_DELAYTIMER_MAX 32
+#define _POSIX_TIMER_MAX 32
+#define _POSIX_CLOCKRES_MIN 10000000
+
+/* Required for asynchronous I/O */
+
+#define _POSIX_AIO_LISTIO_MAX 2
+#define _POSIX_AIO_MAX 1
+
+/* Required for POSIX message passing */
+
+#define _POSIX_MQ_OPEN_MAX 8
+#define _POSIX_MQ_PRIO_MAX UCHAR_MAX
+
+/* Required for POSIX semaphores */
+
+#define _POSIX_SEM_NSEMS_MAX INT_MAX
+#define _POSIX_SEM_VALUE_MAX 0x7fff
+
+/* Actual limits. These values may be increased from the POSIX minimum
+ * values above or made indeterminate
+ */
+
+#define ARG_MAX _POSIX_ARG_MAX
+#define CHILD_MAX _POSIX_CHILD_MAX
+#define LINK_MAX _POSIX_LINK_MAX
+#define MAX_CANON _POSIX_MAX_CANON
+#define MAX_INPUT _POSIX_MAX_INPUT
+#define NAME_MAX _POSIX_NAME_MAX
+#define NGROUPS_MAX _POSIX_NGROUPS_MAX
+#define OPEN_MAX _POSIX_OPEN_MAX
+#define PATH_MAX _POSIX_PATH_MAX
+#define PIPE_BUF _POSIX_PIPE_BUF
+#define SSIZE_MAX _POSIX_SSIZE_MAX
+#define STREAM_MAX _POSIX_STREAM_MAX
+#define TZNAME_MAX _POSIX_TZNAME_MAX
+
+#define RTSIG_MAX _POSIX_RTSIG_MAX
+#define SIGQUEUE_MAX _POSIX_SIGQUEUE_MAX
+
+#define DELAYTIMER_MAX _POSIX_DELAYTIMER_MAX
+#define TIMER_MAX _POSIX_TIMER_MAX
+#define CLOCKRES_MIN _POSIX_CLOCKRES_MIN
+
+/* Required for asynchronous I/O */
+
+#define AIO_LISTIO_MAX _POSIX_AIO_LISTIO_MAX
+#define AIO_MAX _POSIX_AIO_MAX
+
+/* Required for POSIX message passing */
+
+#define MQ_OPEN_MAX _POSIX_MQ_OPEN_MAX
+#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX
+
+/* Required for POSIX semaphores */
-#define NAME_MAX CONFIG_NAME_MAX
-#define MAXNAMELEN CONFIG_NAME_MAX
+#define SEM_NSEMS_MAX _POSIX_SEM_NSEMS_MAX
+#define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
#endif /* __LIMITS_H */
diff --git a/nuttx/include/mqueue.h b/nuttx/include/mqueue.h
index 7e0966d25..22e853a16 100644
--- a/nuttx/include/mqueue.h
+++ b/nuttx/include/mqueue.h
@@ -1,4 +1,4 @@
-/************************************************************
+/********************************************************************************
* mqueue.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
@@ -31,62 +31,54 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ********************************************************************************/
#ifndef __MQUEUE_H
#define __MQUEUE_H
-/************************************************************
+/********************************************************************************
* Included Files
- ************************************************************/
+ ********************************************************************************/
#include <sys/types.h>
#include <signal.h>
#include "queue.h"
-/************************************************************
+/********************************************************************************
* Compilations Switches
- ************************************************************/
+ ********************************************************************************/
-/************************************************************
+/********************************************************************************
* Definitions
- ************************************************************/
+ ********************************************************************************/
-/************************************************************
+#define MQ_NONBLOCK O_NONBLOCK
+
+/********************************************************************************
* Global Type Declarations
- ************************************************************/
+ ********************************************************************************/
/* Message queue attributes */
struct mq_attr
{
- size_t mq_maxmsg; /* Max number of messages in queue */
- size_t mq_msgsize; /* Max message size */
- unsigned mq_flags; /* Queue flags */
- size_t mq_curmsgs; /* Number of messages currently in queue */
-};
-
-/* The following is used to attach a signal to a message queue
- * to notify a task when a message is available on a queue
- */
-
-struct sigevent {
- int sigev_signo;
- union sigval sigev_value;
- int sigev_notify;
+ size_t mq_maxmsg; /* Max number of messages in queue */
+ size_t mq_msgsize; /* Max message size */
+ unsigned mq_flags; /* Queue flags */
+ size_t mq_curmsgs; /* Number of messages currently in queue */
};
/* Message queue descriptor */
typedef FAR struct mq_des *mqd_t;
-/************************************************************
+/********************************************************************************
* Global Variables
- ************************************************************/
+ ********************************************************************************/
-/************************************************************
+/********************************************************************************
* Global Function Prototypes
- ************************************************************/
+ ********************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
@@ -98,17 +90,12 @@ extern "C" {
EXTERN mqd_t mq_open(const char *mq_name, int oflags, ... );
EXTERN int mq_close(mqd_t mqdes );
EXTERN int mq_unlink(const char *mq_name );
-EXTERN int mq_send(mqd_t mqdes, const void *msg,
- size_t msglen, int prio );
-EXTERN int mq_receive(mqd_t mqdes, void *msg,
- size_t msglen, int *prio );
-EXTERN int mq_notify(mqd_t mqdes,
- const struct sigevent *notification );
-EXTERN int mq_setattr(mqd_t mqdes,
- const struct mq_attr *mq_stat,
+EXTERN int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio );
+EXTERN int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio );
+EXTERN int mq_notify(mqd_t mqdes, const struct sigevent *notification );
+EXTERN int mq_setattr(mqd_t mqdes, const struct mq_attr *mq_stat,
struct mq_attr *oldstat);
-EXTERN int mq_getattr(mqd_t mqdes,
- struct mq_attr *mq_stat);
+EXTERN int mq_getattr(mqd_t mqdes, struct mq_attr *mq_stat);
#undef EXTERN
#ifdef __cplusplus
diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h
new file mode 100644
index 000000000..494f5dcd9
--- /dev/null
+++ b/nuttx/include/nuttx/sched.h
@@ -0,0 +1,287 @@
+/********************************************************************************
+ * sched.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 Gregory Nutt 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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 __NUTTX_SCHED_H
+#define __NUTTX_SCHED_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <queue.h>
+#include <signal.h>
+#include <semaphore.h>
+#include <pthread.h>
+#include <mqueue.h>
+#include <time.h>
+#include <nuttx/irq.h>
+
+/********************************************************************************
+ * Definitions
+ ********************************************************************************/
+
+/* Task Management Definitins ***************************************************/
+
+/* This is the maximum number of times that a lock can be set */
+
+#define MAX_LOCK_COUNT 127
+
+/* Values for the _TCB flags flag bits */
+
+#define TCB_FLAG_PTHREAD 0x0001 /* Thread is a pthread */
+#define TCB_FLAG_NONCANCELABLE 0x0002 /* Pthread is non-cancelable */
+#define TCB_FLAG_CANCEL_PENDING 0x0004 /* Pthread cancel is pending */
+#define TCB_FLAG_ROUND_ROBIN 0x0008 /* Round robin sched enabled */
+
+/********************************************************************************
+ * Global Type Definitions
+ ********************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/* General Task Management Types ************************************************/
+
+/* This is the type of the task_state field of the TCB.
+ * NOTE: the order and content of this enumeration is
+ * critical since there are some OS tables indexed by these
+ * values.
+ */
+
+typedef enum tstate_e
+{
+ TSTATE_TASK_INVALID = 0, /* INVALID - TCB has not yet been initialized */
+
+ TSTATE_TASK_PENDING = 1, /* READY_TO_RUN - Pending preemption unlock */
+ TSTATE_TASK_READYTORUN = 2, /* READY-TO-RUN - But not running */
+ TSTATE_TASK_RUNNING = 3, /* READY_TO_RUN - And running */
+
+ TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */
+ TSTATE_WAIT_SEM = 5, /* BLOCKED - Waiting for a semaphore */
+#ifndef CONFIG_DISABLE_SIGNALS
+ TSTATE_WAIT_SIG = 6, /* BLOCKED - Waiting for a signal */
+#endif
+#ifndef CONFIG_DISABLE_MQUEUE
+ TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */
+ TSTATE_WAIT_MQNOTFULL /* BLOCKED - Waiting for a MQ to become not full. */
+#endif
+};
+typedef enum tstate_e tstate_t;
+
+/* The following definitions are determined by tstate_t */
+
+#define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN
+#define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING
+#define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE
+#ifndef CONFIG_DISABLE_MQUEUE
+# define LAST_BLOCKED_STATE TSTATE_WAIT_MQNOTFULL
+# ifndef CONFIG_DISABLE_SIGNALS
+# define NUM_TASK_STATES 9
+# else
+# define NUM_TASK_STATES 8
+# endif
+#else
+# ifndef CONFIG_DISABLE_SIGNALS
+# define LAST_BLOCKED_STATE TSTATE_WAIT_SIG
+# define NUM_TASK_STATES 7
+# else
+# define LAST_BLOCKED_STATE TSTATE_WAIT_SEM
+# define NUM_TASK_STATES 6
+# endif
+#endif
+
+/* The following is the form of a thread start-up function */
+
+typedef void (*start_t)(void);
+
+/* This is the entry point into the main thread of the task
+ * or into a created pthread within the task.
+ */
+
+union entry_u
+{
+ pthread_startroutine_t pthread;
+ main_t main;
+};
+typedef union entry_u entry_t;
+
+/* This is the type of the function that is executed with
+ * exit() is called (if registered via atexit()).
+ */
+
+typedef void (*exitfunc_t)(void);
+
+/* POSIX Message queue */
+
+typedef struct msgq_s msgq_t;
+
+/* This is the task control block (TCB) */
+
+struct _TCB
+{
+ /* Fields used to support list management *************************************/
+
+ FAR struct _TCB *flink; /* link in DQ of TCBs */
+ FAR struct _TCB *blink;
+
+ /* Task Management Fields *****************************************************/
+
+ pid_t pid; /* This is the ID of the thread */
+ start_t start; /* Thread start function */
+ entry_t entry; /* Entry Point into the thread */
+ exitfunc_t exitfunc; /* Called if exit is called. */
+ ubyte sched_priority; /* Current priority of the thread */
+ tstate_t task_state; /* Current state of the thread */
+ uint16 flags; /* Misc. general status flags */
+ sint16 lockcount; /* 0=preemptable (not-locked) */
+ FAR void *joininfo; /* Detach-able info to support join */
+#if CONFIG_RR_INTERVAL > 0
+ int timeslice; /* RR timeslice interval remaining */
+#endif
+
+ /* Values needed to restart a task ********************************************/
+
+ ubyte init_priority; /* Initial priority of the task */
+ char *argv[CONFIG_MAX_TASK_ARGS+1]; /* Name+start-up parameters */
+
+ /* Stack-Related Fields *******************************************************/
+
+#ifndef CONFIG_CUSTOM_STACK
+ size_t adj_stack_size; /* Stack size after adjustment */
+ /* for hardware, processor, etc. */
+ /* (for debug purposes only) */
+ FAR void *stack_alloc_ptr; /* Pointer to allocated stack */
+ /* Need to deallocate stack */
+ FAR void *adj_stack_ptr; /* Adjusted stack_alloc_ptr for HW */
+ /* The initial stack pointer value */
+#endif
+
+ /* POSIX thread Specific Data *************************************************/
+
+#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_NPTHREAD_KEYS > 0
+ FAR void *pthread_data[CONFIG_NPTHREAD_KEYS];
+#endif
+
+ /* POSIX Semaphore Control Fields *********************************************/
+
+ sem_t *waitsem; /* Semaphore ID waiting on */
+
+ /* POSIX Signal Control Fields ************************************************/
+
+#ifndef CONFIG_DISABLE_SIGNALS
+ sigset_t sigprocmask; /* Signals that are blocked */
+ sigset_t sigwaitmask; /* Waiting for pending signals */
+ sq_queue_t sigactionq; /* List of actions for signals */
+ sq_queue_t sigpendingq; /* List of Pending Signals */
+ sq_queue_t sigpendactionq; /* List of pending signal actions */
+ sq_queue_t sigpostedq; /* List of posted signals */
+ siginfo_t sigunbinfo; /* Signal info when task unblocked */
+#endif
+
+ /* POSIX Named Message Queue Fields *******************************************/
+
+#ifndef CONFIG_DISABLE_MQUEUE
+ sq_queue_t msgdesq; /* List of opened message queues */
+ FAR msgq_t *msgwaitq; /* Waiting for this message queue */
+#endif
+
+ /* Library related fields *****************************************************/
+
+ int errno; /* Current per-thread errno */
+
+ /* File system support ********************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+ FAR struct filelist *filelist; /* Maps file descriptor to file */
+#endif
+
+#if CONFIG_NFILE_STREAMS > 0
+ FAR struct streamlist *streams; /* Holds C buffered I/O info */
+#endif
+
+ /* State save areas ***********************************************************/
+ /* The form and content of these fields are processor-specific. */
+
+ struct xcptcontext xcp; /* Interrupt register save area */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+ char name[CONFIG_TASK_NAME_SIZE]; /* Task name */
+#endif
+
+};
+typedef struct _TCB _TCB;
+
+/* This is the callback type used by sched_foreach() */
+
+typedef void (sched_foreach_t)(FAR _TCB *tcb, FAR void *arg);
+
+#endif /* __ASSEMBLY__ */
+
+/********************************************************************************
+ * Global Function Prototypes
+ ********************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* File system helpers */
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+EXTERN FAR struct filelist *sched_getfiles(void);
+#if CONFIG_NFILE_STREAMS > 0
+EXTERN FAR struct streamlist *sched_getstreams(void);
+#endif /* CONFIG_NFILE_STREAMS */
+#endif /* CONFIG_NFILE_DESCRIPTORS */
+
+/* sched_foreach will enumerate over each task and provide the
+ * TCB of each task to a user callback functions. Interrupts
+ * will be disabled throughout this enumeration!
+ */
+
+EXTERN void sched_foreach(sched_foreach_t handler, FAR void *arg);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+#endif /* __ASSEMBLY__ */
+
+#endif /* __NUTTX_SCHED_H */
diff --git a/nuttx/include/pthread.h b/nuttx/include/pthread.h
index 5ff44f718..16973a5a5 100644
--- a/nuttx/include/pthread.h
+++ b/nuttx/include/pthread.h
@@ -1,4 +1,4 @@
-/************************************************************
+/********************************************************************************
* pthread.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
@@ -31,14 +31,14 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ********************************************************************************/
#ifndef __PTHREAD_H
#define __PTHREAD_H
-/************************************************************
+/********************************************************************************
* Included Files
- ************************************************************/
+ ********************************************************************************/
#include <nuttx/config.h> /* Default settings */
#include <nuttx/compiler.h> /* Compiler settings */
@@ -47,9 +47,9 @@
#include <time.h> /* Needed for struct timespec */
#include <nuttx/compiler.h> /* For noreturn_function */
-/************************************************************
+/********************************************************************************
* Compilation Switches
- ************************************************************/
+ ********************************************************************************/
/* Standard POSIX switches */
@@ -60,9 +60,9 @@
#define _POSIX_THREAD_ATTR_STACKSIZE
#endif
-/************************************************************
+/********************************************************************************
* Definitions
- ************************************************************/
+ ********************************************************************************/
#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED 1
@@ -88,9 +88,9 @@
# define PTHREAD_CANCELED ((FAR void*)ERROR)
-/************************************************************
+/********************************************************************************
* Global Type Declarations
- ************************************************************/
+ ********************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
@@ -144,125 +144,96 @@ struct pthread_mutex_s
typedef struct pthread_mutex_s pthread_mutex_t;
#define PTHREAD_MUTEX_INITIALIZER {0, {1, 0xffff}}
-/************************************************************
+/* Forware references */
+
+struct sched_param; /* Defined in sched.h */
+
+/********************************************************************************
* Global Variables
- ************************************************************/
+ ********************************************************************************/
-/************************************************************
+/********************************************************************************
* Global Function Prototypes
- ************************************************************/
-/*----------------------------------------------------------*
- * Initializes a thread attributes object (attr) with default
- * values for all of the individual attributes used by a
- * given implementation.
- *----------------------------------------------------------*/
+ ********************************************************************************/
+/* Initializes a thread attributes object (attr) with default values for all of
+ * the individual attributes used by a given implementation.
+ */
EXTERN int pthread_attr_init(pthread_attr_t *attr);
-/*----------------------------------------------------------*
- * An attributes object can be deleted when it is no longer
- * needed.
- *----------------------------------------------------------*/
+/* An attributes object can be deleted when it is no longer needed. */
EXTERN int pthread_attr_destroy(pthread_attr_t *attr);
-/*----------------------------------------------------------*
- * Set or obtain the default scheduling algorithm
- *----------------------------------------------------------*/
+/* Set or obtain the default scheduling algorithm */
-EXTERN int pthread_attr_setschedpolicy(pthread_attr_t *attr,
- int policy);
-EXTERN int pthread_attr_getschedpolicy(pthread_attr_t *attr,
- int *policy);
+EXTERN int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
+EXTERN int pthread_attr_getschedpolicy(pthread_attr_t *attr, int *policy);
EXTERN int pthread_attr_setschedparam(pthread_attr_t *attr,
- const struct sched_param *param);
+ const struct sched_param *param);
EXTERN int pthread_attr_getschedparam(pthread_attr_t *attr,
- struct sched_param *param);
-EXTERN int pthread_attr_setinheritsched(pthread_attr_t *attr,
- int inheritsched);
+ struct sched_param *param);
+EXTERN int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
EXTERN int pthread_attr_getinheritsched(const pthread_attr_t *attr,
- int *inheritsched);
+ int *inheritsched);
-/*----------------------------------------------------------*
- * Set or obtain the default stack size
- *----------------------------------------------------------*/
+/* Set or obtain the default stack size */
-EXTERN int pthread_attr_setstacksize(pthread_attr_t *attr,
- long stacksize);
-EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr,
- long *stackaddr);
+EXTERN int pthread_attr_setstacksize(pthread_attr_t *attr, long stacksize);
+EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr, long *stackaddr);
-/*----------------------------------------------------------*
- * To create a thread object and runnable thread, a routine
- * must be specified as the new thread's start routine. An
- * argument may be passed to this routine, as an untyped
- * address; an untyped address may also be returned as the
- * routine's value. An attributes object may be used to
- * specify details about the kind of thread being created.
- *----------------------------------------------------------*/
+/* To create a thread object and runnable thread, a routine must be specified
+ * as the new thread's start routine. An argument may be passed to this
+ * routine, as an untyped address; an untyped address may also be returned as
+ * the routine's value. An attributes object may be used to specify details
+ * about the kind of thread being created.
+ */
-EXTERN int pthread_create(pthread_t *thread,
- pthread_attr_t *attr,
- pthread_startroutine_t startRoutine,
- pthread_addr_t arg);
+EXTERN int pthread_create(pthread_t *thread, pthread_attr_t *attr,
+ pthread_startroutine_t startroutine,
+ pthread_addr_t arg);
-/*----------------------------------------------------------*
- * A thread object may be "detached" to specify that the
- * return value and completion status will not be requested.
- *----------------------------------------------------------*/
+/* A thread object may be "detached" to specify that the return value and
+ * completion status will not be requested.
+ */
EXTERN int pthread_detach(pthread_t thread);
-/*----------------------------------------------------------*
- * A thread may terminate it's own execution or the
- * execution of another thread.
- *----------------------------------------------------------*/
+/* A thread may terminate it's own execution or the execution of another
+ * thread.
+ */
EXTERN void pthread_exit(pthread_addr_t value) noreturn_function;
EXTERN int pthread_cancel(pthread_t thread);
EXTERN int pthread_setcancelstate(int state, int *oldstate);
EXTERN void pthread_testcancel(void);
-/*----------------------------------------------------------*
- * A thread can await termination of another thread and retrieve
- * the return value of the thread.
- *----------------------------------------------------------*/
+/* A thread can await termination of another thread and retrieve the return
+ * value of the thread.
+ */
-EXTERN int pthread_join(pthread_t thread,
- pthread_addr_t *value);
+EXTERN int pthread_join(pthread_t thread, pthread_addr_t *value);
-/*----------------------------------------------------------*
- * A thread may tell the scheduler that its processor can be
- * made available.
- *----------------------------------------------------------*/
+/* A thread may tell the scheduler that its processor can be made available. */
EXTERN void pthread_yield(void);
-/*----------------------------------------------------------*
- * A thread may obtain a copy of its own thread handle.
- *----------------------------------------------------------*/
+/* A thread may obtain a copy of its own thread handle. */
#define pthread_self() ((pthread_t)getpid())
-/*----------------------------------------------------------*
- * Compare to thread IDs.
- *----------------------------------------------------------*/
+/* Compare two thread IDs. */
#define pthread_equal(t1,t2) (t1 == t2)
-/*----------------------------------------------------------*
- * Thread scheduling parameters
- *----------------------------------------------------------*/
+/* Thread scheduling parameters */
-EXTERN int pthread_getschedparam(pthread_t thread,
- int *policy,
- struct sched_param *param);
+EXTERN int pthread_getschedparam(pthread_t thread, int *policy,
+ struct sched_param *param);
EXTERN int pthread_setschedparam(pthread_t thread, int policy,
- const struct sched_param *param);
+ const struct sched_param *param);
-/*----------------------------------------------------------*
- * Thread-specific Data Interfaces
- *----------------------------------------------------------*/
+/* Thread-specific Data Interfaces */
EXTERN int pthread_key_create(pthread_key_t *key,
FAR void (*destructor)(FAR void*));
@@ -270,65 +241,43 @@ EXTERN int pthread_setspecific(pthread_key_t key, FAR void *value);
EXTERN FAR void *pthread_getspecific(pthread_key_t key);
EXTERN int pthread_key_delete(pthread_key_t key);
-/*----------------------------------------------------------*
- * Create, operate on, and destroy mutex attributes.
- *----------------------------------------------------------*/
+/* Create, operate on, and destroy mutex attributes. */
EXTERN int pthread_mutexattr_init(pthread_mutexattr_t *attr);
EXTERN int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
-EXTERN int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr,
- int *pshared);
-EXTERN int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
- int pshared);
+EXTERN int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared);
+EXTERN int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
-/*----------------------------------------------------------*
- * The following routines create, delete, lock and unlock
- * mutexes.
- *----------------------------------------------------------*/
+/* The following routines create, delete, lock and unlock mutexes. */
-EXTERN int pthread_mutex_init(pthread_mutex_t *mutex,
- pthread_mutexattr_t *attr);
+EXTERN int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
EXTERN int pthread_mutex_destroy(pthread_mutex_t *mutex);
EXTERN int pthread_mutex_lock(pthread_mutex_t *mutex);
EXTERN int pthread_mutex_trylock(pthread_mutex_t *mutex);
EXTERN int pthread_mutex_unlock(pthread_mutex_t *mutex);
-/*----------------------------------------------------------*
- * Operations on condition variables
- *----------------------------------------------------------*/
+/* Operations on condition variables */
EXTERN int pthread_condattr_init(pthread_condattr_t *attr);
EXTERN int pthread_condattr_destroy(pthread_condattr_t *attr);
-/*----------------------------------------------------------*
- * A thread can create and delete condition variables.
- *----------------------------------------------------------*/
+/* A thread can create and delete condition variables. */
-EXTERN int pthread_cond_init(pthread_cond_t *cond,
- pthread_condattr_t *attr);
+EXTERN int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
EXTERN int pthread_cond_destroy(pthread_cond_t *cond);
-/*----------------------------------------------------------*
- * A thread can signal to and broadcast on a condition variable.
- *----------------------------------------------------------*/
+/* A thread can signal to and broadcast on a condition variable. */
EXTERN int pthread_cond_broadcast(pthread_cond_t *cond);
EXTERN int pthread_cond_signal(pthread_cond_t *cond);
-/*----------------------------------------------------------*
- * A thread can wait for a condition variable to be signalled
- * or broadcast.
- *----------------------------------------------------------*/
+/* A thread can wait for a condition variable to be signalled or broadcast. */
-EXTERN int pthread_cond_wait(pthread_cond_t *cond,
- pthread_mutex_t *mutex);
+EXTERN int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
-/*----------------------------------------------------------*
- * A thread can perform a timed wait on a condition variable.
- *----------------------------------------------------------*/
+/* A thread can perform a timed wait on a condition variable. */
-EXTERN int pthread_cond_timedwait(pthread_cond_t *cond,
- pthread_mutex_t *mutex,
+EXTERN int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime);
#undef EXTERN
diff --git a/nuttx/include/sched.h b/nuttx/include/sched.h
index bab6f517f..0efce85db 100644
--- a/nuttx/include/sched.h
+++ b/nuttx/include/sched.h
@@ -1,4 +1,4 @@
-/************************************************************
+/********************************************************************************
* sched.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
@@ -31,231 +31,48 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ********************************************************************************/
#ifndef __SCHED_H
#define __SCHED_H
-/************************************************************
+/********************************************************************************
* Included Files
- ************************************************************/
+ ********************************************************************************/
#include <nuttx/config.h>
-#include <queue.h>
-#include <signal.h>
-#include <semaphore.h>
-#include <pthread.h>
-#include <mqueue.h>
-#include <time.h>
-#include <nuttx/irq.h>
+#include <nuttx/sched.h>
-/************************************************************
+/********************************************************************************
* Definitions
- ************************************************************/
+ ********************************************************************************/
-/* Task Management Definitins *******************************/
+/* Task Management Definitins ***************************************************/
-/* This is the maximum number of times that a lock can be set */
+/* POSIX-like scheduling policies */
-#define MAX_LOCK_COUNT 127
+#define SCHED_FIFO 1 /* FIFO per priority scheduling policy */
+#define SCHED_RR 2 /* Round robin scheduling policy */
+#define SCHED_OTHER 4 /* Not used */
-/* Values for the _TCB flags flag bits */
-
-#define TCB_FLAG_PTHREAD 0x0001 /* Thread is a pthread */
-#define TCB_FLAG_NONCANCELABLE 0x0002 /* Pthread is non-cancelable */
-#define TCB_FLAG_CANCEL_PENDING 0x0004 /* Pthread cancel is pending */
-#define TCB_FLAG_ROUND_ROBIN 0x0008 /* Round robin sched enabled */
-
-/* Pthread definitions **************************************/
+/* Pthread definitions **********************************************************/
#define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS
-/************************************************************
+/********************************************************************************
* Global Type Definitions
- ************************************************************/
-
-#ifndef __ASSEMBLY__
-
-/* General Task Management Types ****************************/
-
-/* This is the type of the task_state field of the TCB.
- * NOTE: the order and content of this enumeration is
- * critical since there are some OS tables indexed by these
- * values.
- */
-
-typedef enum tstate_e
-{
- TSTATE_TASK_INVALID = 0, /* INVALID - TCB has not yet been initialized */
-
- TSTATE_TASK_PENDING = 1, /* READY_TO_RUN - Pending preemption unlock */
- TSTATE_TASK_READYTORUN = 2, /* READY-TO-RUN - But not running */
- TSTATE_TASK_RUNNING = 3, /* READY_TO_RUN - And running */
-
- TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */
- TSTATE_WAIT_SEM = 5, /* BLOCKED - Waiting for a semaphore */
-#ifndef CONFIG_DISABLE_SIGNALS
- TSTATE_WAIT_SIG = 6, /* BLOCKED - Waiting for a signal */
-#endif
-#ifndef CONFIG_DISABLE_MQUEUE
- TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */
- TSTATE_WAIT_MQNOTFULL /* BLOCKED - Waiting for a MQ to become not full. */
-#endif
-};
-typedef enum tstate_e tstate_t;
-
-/* The following definitions are determined by tstate_t */
-
-#define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN
-#define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING
-#define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE
-#ifndef CONFIG_DISABLE_MQUEUE
-# define LAST_BLOCKED_STATE TSTATE_WAIT_MQNOTFULL
-# ifndef CONFIG_DISABLE_SIGNALS
-# define NUM_TASK_STATES 9
-# else
-# define NUM_TASK_STATES 8
-# endif
-#else
-# ifndef CONFIG_DISABLE_SIGNALS
-# define LAST_BLOCKED_STATE TSTATE_WAIT_SIG
-# define NUM_TASK_STATES 7
-# else
-# define LAST_BLOCKED_STATE TSTATE_WAIT_SEM
-# define NUM_TASK_STATES 6
-# endif
-#endif
+ ********************************************************************************/
-/* The following is the form of a thread start-up function */
+/* This is the POSIX-like scheduling parameter structure */
-typedef void (*start_t)(void);
-
-/* This is the entry point into the main thread of the task
- * or into a created pthread within the task.
- */
-
-union entry_u
-{
- pthread_startroutine_t pthread;
- main_t main;
-};
-typedef union entry_u entry_t;
-
-/* This is the type of the function that is executed with
- * exit() is called (if registered via atexit()).
- */
-
-typedef void (*exitfunc_t)(void);
-
-/* POSIX Message queue */
-
-typedef struct msgq_s msgq_t;
-
-/* This is the task control block (TCB) */
-
-struct _TCB
+struct sched_param
{
- /* Fields used to support list management ***************************/
-
- FAR struct _TCB *flink; /* link in DQ of TCBs */
- FAR struct _TCB *blink;
-
- /* Task Management Fields *******************************************/
-
- pid_t pid; /* This is the ID of the thread */
- start_t start; /* Thread start function */
- entry_t entry; /* Entry Point into the thread */
- exitfunc_t exitfunc; /* Called if exit is called. */
- ubyte sched_priority; /* Current priority of the thread */
- tstate_t task_state; /* Current state of the thread */
- uint16 flags; /* Misc. general status flags */
- sint16 lockcount; /* 0=preemptable (not-locked) */
- FAR void *joininfo; /* Detach-able info to support join */
-#if CONFIG_RR_INTERVAL > 0
- int timeslice; /* RR timeslice interval remaining */
-#endif
-
- /* Values needed to restart a task **********************************/
-
- ubyte init_priority; /* Initial priority of the task */
- char *argv[CONFIG_MAX_TASK_ARGS+1]; /* Name+start-up parameters */
-
- /* Stack-Related Fields *********************************************/
-
-#ifndef CONFIG_CUSTOM_STACK
- size_t adj_stack_size; /* Stack size after adjustment */
- /* for hardware, processor, etc. */
- /* (for debug purposes only) */
- FAR void *stack_alloc_ptr; /* Pointer to allocated stack */
- /* Need to deallocate stack */
- FAR void *adj_stack_ptr; /* Adjusted stack_alloc_ptr for HW */
- /* The initial stack pointer value */
-#endif
-
- /* POSIX thread Specific Data ***************************************/
-
-#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_NPTHREAD_KEYS > 0
- FAR void *pthread_data[CONFIG_NPTHREAD_KEYS];
-#endif
-
- /* POSIX Semaphore Control Fields ***********************************/
-
- sem_t *waitsem; /* Semaphore ID waiting on */
-
- /* POSIX Signal Control Fields **************************************/
-
-#ifndef CONFIG_DISABLE_SIGNALS
- sigset_t sigprocmask; /* Signals that are blocked */
- sigset_t sigwaitmask; /* Waiting for pending signals */
- sq_queue_t sigactionq; /* List of actions for signals */
- sq_queue_t sigpendingq; /* List of Pending Signals */
- sq_queue_t sigpendactionq; /* List of pending signal actions */
- sq_queue_t sigpostedq; /* List of posted signals */
- siginfo_t sigunbinfo; /* Signal info when task unblocked */
-#endif
-
- /* POSIX Named Message Queue Fields *********************************/
-
-#ifndef CONFIG_DISABLE_MQUEUE
- sq_queue_t msgdesq; /* List of opened message queues */
- FAR msgq_t *msgwaitq; /* Waiting for this message queue */
-#endif
-
- /* Library related fields *******************************************/
-
- int errno; /* Current per-thread errno */
-
- /* File system support **********************************************/
-
-#if CONFIG_NFILE_DESCRIPTORS > 0
- FAR struct filelist *filelist; /* Maps file descriptor to file */
-#endif
-
-#if CONFIG_NFILE_STREAMS > 0
- FAR struct streamlist *streams; /* Holds C buffered I/O info */
-#endif
-
- /* State save areas *************************************************/
- /* The form and content of these fields are processor-specific. */
-
- struct xcptcontext xcp; /* Interrupt register save area */
-
-#if CONFIG_TASK_NAME_SIZE > 0
- char name[CONFIG_TASK_NAME_SIZE]; /* Task name */
-#endif
-
+ int sched_priority;
};
-typedef struct _TCB _TCB;
-/* This is the callback type used by sched_foreach() */
-
-typedef void (sched_foreach_t)(FAR _TCB *tcb, FAR void *arg);
-
-#endif /* __ASSEMBLY__ */
-
-/************************************************************
+/********************************************************************************
* Global Function Prototypes
- ************************************************************/
+ ********************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
@@ -289,18 +106,15 @@ EXTERN STATUS task_restart(pid_t pid);
/* Task Scheduling Interfaces (based on POSIX APIs) */
-EXTERN int sched_setparam(pid_t pid,
- const struct sched_param *param);
-EXTERN int sched_getparam(pid_t pid,
- struct sched_param *param);
+EXTERN int sched_setparam(pid_t pid, const struct sched_param *param);
+EXTERN int sched_getparam(pid_t pid, struct sched_param *param);
EXTERN int sched_setscheduler(pid_t pid, int policy,
const struct sched_param *param);
EXTERN int sched_getscheduler(pid_t pid);
EXTERN int sched_yield(void);
EXTERN int sched_get_priority_max(int policy);
EXTERN int sched_get_priority_min(int policy);
-EXTERN int sched_rr_get_interval(pid_t pid,
- struct timespec *interval);
+EXTERN int sched_rr_get_interval(pid_t pid, struct timespec *interval);
/* Task Switching Interfaces (non-standard) */
@@ -314,9 +128,9 @@ EXTERN sint32 sched_lockcount(void);
#ifdef CONFIG_SCHED_INSTRUMENTATION
-EXTERN void sched_note_start(FAR _TCB *tcb );
-EXTERN void sched_note_stop(FAR _TCB *tcb );
-EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb);
+EXTERN void sched_note_start(FAR _TCB *tcb );
+EXTERN void sched_note_stop(FAR _TCB *tcb );
+EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb);
#else
# define sched_note_start(t)
@@ -324,22 +138,6 @@ EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb);
# define sched_note_switch(t1, t2)
#endif /* CONFIG_SCHED_INSTRUMENTATION */
-/* File system helpers */
-
-#if CONFIG_NFILE_DESCRIPTORS > 0
-EXTERN FAR struct filelist *sched_getfiles(void);
-#if CONFIG_NFILE_STREAMS > 0
-EXTERN FAR struct streamlist *sched_getstreams(void);
-#endif /* CONFIG_NFILE_STREAMS */
-#endif /* CONFIG_NFILE_DESCRIPTORS */
-
-/* sched_foreach will enumerate over each task and provide the
- * TCB of each task to a user callback functions. Interrupts
- * will be disabled throughout this enumeration!
- */
-
-EXTERN void sched_foreach(sched_foreach_t handler, FAR void *arg);
-
#undef EXTERN
#if defined(__cplusplus)
}
diff --git a/nuttx/include/semaphore.h b/nuttx/include/semaphore.h
index f23435a1a..565acaf31 100644
--- a/nuttx/include/semaphore.h
+++ b/nuttx/include/semaphore.h
@@ -41,6 +41,7 @@
************************************************************/
#include <sys/types.h>
+#include <limits.h>
#ifdef __cplusplus
#define EXTERN extern "C"
@@ -53,14 +54,6 @@ extern "C" {
* Definitions
************************************************************/
-/* The maximum value that a semaphore may have. */
-
-#define SEM_MAX_VALUE 0x7fff /* Max value POSIX counting semaphore */
-
-/* The maximum number of semaphores that a task may have */
-
-#define SEM_NSEMS_MAX 0x7fffffff
-
/************************************************************
* Public Type Declarations
************************************************************/
diff --git a/nuttx/include/signal.h b/nuttx/include/signal.h
index df8fe214d..8e25f8c00 100644
--- a/nuttx/include/signal.h
+++ b/nuttx/include/signal.h
@@ -1,4 +1,4 @@
-/************************************************************
+/********************************************************************************
* signal.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
@@ -31,27 +31,27 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ********************************************************************************/
#ifndef __SIGNAL_H
#define __SIGNAL_H
-/************************************************************
+/********************************************************************************
* Included Files
- ************************************************************/
+ ********************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <time.h> /* Needed for struct timespec */
#include <sys/types.h> /* Needed for, e.g., sigset_t */
-/************************************************************
+/********************************************************************************
* Compilations Switches
- ************************************************************/
+ ********************************************************************************/
-/************************************************************
+/********************************************************************************
* Definitions
- ************************************************************/
+ ********************************************************************************/
/* Signal set management definitions and macros. */
@@ -62,13 +62,18 @@
#define GOOD_SIGNO(s) (((s)>=MIN_SIGNO)&&((s)<=MAX_SIGNO))
#define SIGNO2SET(s) ((sigset_t)1 << (s))
+/* All signals are "real time" signals */
+
+#define SIGRTMIN 0 /* First real time signal */
+#define SIGRTMAX 31 /* Last real time signal */
+
/* sigprocmask() "how" definitions. Only one of the following
* can be specified:
*/
-#define SIG_BLOCK 1
-#define SIG_UNBLOCK 2
-#define SIG_SETMASK 3
+#define SIG_BLOCK 1 /* Block the given signals */
+#define SIG_UNBLOCK 2 /* Unblock the given signals */
+#define SIG_SETMASK 3 /* Set the signal mask to the current set */
/* struct sigaction flag values */
@@ -80,19 +85,25 @@
/* Dummy value for the sigev_notify field of struct sigevent */
-#define SIGEV_SIGNAL 0
+#define SIGEV_SIGNAL 0
/* These are the possible values of the signfo si_code field */
-#define SI_QUEUE 0 /* Signal sent from sigqueue */
-#define SI_MESGQ 1 /* Signal generated by arrival of a message on an
- * empty message queue */
-#define SI_NOWAIT 2 /* Signal already pending -- don't know how sent */
-#define SI_TIMEOUT 3 /* No-signal, unblocked by timeout */
+#define SI_USER 0 /* Signal sent from kill, raise, or abort */
+#define SI_QUEUE 1 /* Signal sent from sigqueue */
+#define SI_TIMER 2 /* Signal is result of timer expiration */
+#define SI_ASYNCIO 3 /* Signal is the result of asynch IO completion */
+#define SI_MESGQ 4 /* Signal generated by arrival of a message on an */
+ /* empty message queue */
+
+/* sigevent definitions */
-/************************************************************
+#define SIGEV_NONE 0 /* No notification desired */
+#define SIGEV_SIGNAL 1 /* Notify via signal */
+
+/********************************************************************************
* Global Type Declarations
- ************************************************************/
+ ********************************************************************************/
/* This defines a set of 32 signals (numbered 0 through 31). */
@@ -106,6 +117,18 @@ union sigval
void *sival_ptr;
};
+/* This structure contains elements that define a queue signal.
+ * The following is used to attach a signal to a message queue
+ * to notify a task when a message is available on a queue
+ */
+
+struct sigevent
+{
+ int sigev_signo; /* Notification: SIGNAL or NONE */
+ union sigval sigev_value; /* Generate this signal */
+ int sigev_notify; /* Queue this value */
+};
+
/* The following types is used to pass parameters to/from
* signal handlers
*/
@@ -132,13 +155,13 @@ struct sigaction
#define sa_handler sa_u._sa_handler
#define sa_sigaction sa_u._sa_sigaction
-/************************************************************
+/********************************************************************************
* Global Variables
- ************************************************************/
+ ********************************************************************************/
-/************************************************************
+/********************************************************************************
* Global Function Prototypes
- ************************************************************/
+ ********************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
@@ -147,26 +170,21 @@ extern "C" {
#define EXTERN extern
#endif
+EXTERN int kill(pid_t, int);
EXTERN int sigemptyset(sigset_t *set);
EXTERN int sigfillset(sigset_t *set);
EXTERN int sigaddset(sigset_t *set, int signo);
EXTERN int sigdelset(sigset_t *set, int signo);
EXTERN int sigismember(const sigset_t *set, int signo);
-EXTERN int sigaction(int sig,
- const struct sigaction *act,
- struct sigaction *oact);
-EXTERN int sigprocmask(int how, const sigset_t *set,
- sigset_t *oset);
+EXTERN int sigaction(int sig, const struct sigaction *act, struct sigaction *oact);
+EXTERN int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
EXTERN int sigpending(sigset_t *set);
EXTERN int sigsuspend(const sigset_t *sigmask);
-EXTERN int sigwaitinfo(const sigset_t *set,
- struct siginfo *value);
-EXTERN int sigtimedwait(const sigset_t *set,
- struct siginfo *value,
- const struct timespec *timeout);
+EXTERN int sigwaitinfo(const sigset_t *set, struct siginfo *value);
+EXTERN int sigtimedwait(const sigset_t *set, struct siginfo *value,
+ const struct timespec *timeout);
#ifdef CONFIG_CAN_PASS_STRUCTS
-EXTERN int sigqueue(int pid, int signo,
- const union sigval value);
+EXTERN int sigqueue(int pid, int signo, const union sigval value);
#else
EXTERN int sigqueue(int pid, int signo, void *sival_ptr);
#endif
diff --git a/nuttx/include/stdio.h b/nuttx/include/stdio.h
index 666bb22fa..eba23a9ce 100644
--- a/nuttx/include/stdio.h
+++ b/nuttx/include/stdio.h
@@ -59,37 +59,6 @@
#define EOF (-1)
-/* File I/O constants ***************************************/
-
-#define PATH_MAX 101
-#define S_IFMT 0170000
-#define S_IFIFO 0010000
-#define S_IFCHR 0020000
-#define S_IFDIR 0040000
-#define S_IFBLK 0060000
-#define S_IFREG 0100000
-#define S_IFLNK 0120000
-#define S_IFSOCK 0140000
-#define SEEK_SET 0
-#define SEEK_CUR 1
-#define SEEK_END 2
-
-/* Wind-River IOCTL constants */
-
-#define FIOFLUSH 2
-#define FIONBIO 16
-#define FIOSELECT 28
-#define FIOUNSELECT 29
-#define FIOTRUNC 42
-#define FIOHANDLETONAME 45
-#define FIOLABELGET 33
-#define SET_HIDDEN 0x1004
-#define PHYS_BLK_IO 255
-
-#define SECTOR_ALIGN_BYTES 512
-#define FILE_BUF_SIZE (4 * SECTOR_ALIGN_BYTES)
-#define FILE_BUF_ALIGN_BYTES 16
-
/* The first three _iob entries are reserved for standard I/O */
#define stdin (&sched_getstreams()->sl_streams[0])
@@ -106,7 +75,6 @@
#define getchar() fgetc(stdin)
#define ftell(s) fseek((s),0,SEEK_CUR)
#define rewind(s) ((void)fseek((s),0,SEEK_SET))
-#define fsync(f)
/************************************************************
* Public Type Definitions
@@ -197,21 +165,14 @@ EXTERN int vsprintf(char *buf, const char *s, va_list ap);
/* POSIX-like File System Interfaces */
EXTERN int chdir(const char *path);
-EXTERN int close(int fd);
-EXTERN int creat(const char *path, mode_t mode);
EXTERN FILE *fdopen(int fd, const char *type);
EXTERN int fstat(int fd, FAR struct stat *buf);
EXTERN char *getcwd(FAR char *buf, size_t size);
EXTERN int ioctl(int fd, int req, unsigned long arg);
-EXTERN off_t lseek(int fd, off_t offset, int whence);
EXTERN int mkdir(const char *path, mode_t mode);
-EXTERN int open(const char *path, int oflag, ...);
-EXTERN int read(int fd, void *buf, unsigned int nbytes);
EXTERN int rmdir(const char *path);
EXTERN int stat(const char *path, FAR struct stat *buf);
EXTERN int statfs(const char *path, FAR struct statfs *buf);
-EXTERN int unlink(const char *path);
-EXTERN int write(int fd, const void *buf, unsigned int nbytes);
#undef EXTERN
#if defined(__cplusplus)
diff --git a/nuttx/include/sys/types.h b/nuttx/include/sys/types.h
index 45971e4fd..916681c39 100644
--- a/nuttx/include/sys/types.h
+++ b/nuttx/include/sys/types.h
@@ -69,12 +69,6 @@
#undef OK
#define OK 0
-/* POSIX-like scheduling policies (only SCHED_FIFO is supported) */
-
-#define SCHED_FIFO 1 /* FIFO per priority scheduling policy */
-#define SCHED_RR 2 /* Round robin scheduling policy */
-#define SCHED_OTHER 4 /* Not used */
-
/* HPUX-like MIN/MAX value */
#define PRIOR_RR_MIN 0
@@ -92,22 +86,6 @@
#define SCHED_PRIORITY_MIN 1
#define SCHED_PRIORITY_IDLE 0
-/* oflag bit settings for sem_open and mq_open */
-
-#define O_RDONLY 0x01 /* Open for read access */
-#define O_WRONLY 0x02 /* Open for write access */
-#define O_RDWR 0x03 /* Open for both read & write access */
-#define O_CREAT 0x04 /* Create semaphore/message queue */
-#define O_EXCL 0x08 /* Name must not exist when opened */
-#define O_APPEND 0x10
-#define O_TRUNC 0x20
-#define O_NONBLOCK 0x40 /* Don't wait for data */
-#define O_NDELAY O_NONBLOCK
-#define O_LOCK 0x80
-
-#define O_RDOK O_RDONLY /* Not POSIX */
-#define O_WROK O_WRONLY /* Not POSIX */
-
/************************************************************
* Type Declarations
************************************************************/
@@ -144,12 +122,6 @@ typedef int STATUS;
typedef int (*main_t)(int argc, char *argv[]);
-/* This is the POSIX-like scheduling parameter structure */
-
-struct sched_param
-{
- int sched_priority;
-};
#endif
/************************************************************
diff --git a/nuttx/include/time.h b/nuttx/include/time.h
index 0d0399e83..4ae943565 100644
--- a/nuttx/include/time.h
+++ b/nuttx/include/time.h
@@ -1,4 +1,4 @@
-/************************************************************
+/********************************************************************************
* time.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
@@ -31,49 +31,44 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ********************************************************************************/
#ifndef _TIME_H_
#define _TIME_H_
-/************************************************************
+/********************************************************************************
* Included Files
- ************************************************************/
+ ********************************************************************************/
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
-#endif
+#include <nuttx/config.h>
+#include <sys/types.h>
-/************************************************************
+/********************************************************************************
* Compilations Switches
- ************************************************************/
+ ********************************************************************************/
-/************************************************************
+/********************************************************************************
* Definitions
- ************************************************************/
+ ********************************************************************************/
-/* This must be set to the last known date */
+/* Clock tick of the system */
-#define CURRENT_YEAR 2000
-#define CURRENT_MONTH 5
-#define CURRENT_DAY 22
+#define CLK_TCK 100
/* This is the only clock_id supported by the "Clock and Timer
* Functions."
*/
#define CLOCK_REALTIME 0
+#define CLOCK_ABSTIME
-/************************************************************
+/********************************************************************************
* Global Type Declarations
- ************************************************************/
+ ********************************************************************************/
-typedef long time_t;
-typedef long clockid_t;
+typedef uint32 time_t;
+typedef ubyte clockid_t;
+typedef ubyte timer_t;
struct timespec
{
@@ -102,22 +97,51 @@ struct tm
#endif
};
-/************************************************************
+/* Struct itimerspec is used to define settings for an interval timer */
+
+struct itimerspec
+{
+ struct timespec it_value; /* First time */
+ struct timespec it_interval; /* and thereafter */
+};
+
+/* forward reference (defined in signal.h) */
+
+struct sigevent;
+
+/********************************************************************************
* Global Variables
- ************************************************************/
+ ********************************************************************************/
+
+/* extern char *tznames[]; not supported */
-/************************************************************
+/********************************************************************************
* Global Function Prototypes
- ************************************************************/
+ ********************************************************************************/
-EXTERN int clock_settime(clockid_t clock_id, const struct timespec *tp);
-EXTERN int clock_gettime(clockid_t clock_id, struct timespec *tp);
-EXTERN int clock_getres(clockid_t clock_id, struct timespec *res);
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN int clock_settime(clockid_t clockid, const struct timespec *tp);
+EXTERN int clock_gettime(clockid_t clockid, struct timespec *tp);
+EXTERN int clock_getres(clockid_t clockid, struct timespec *res);
EXTERN time_t mktime(struct tm *tp);
EXTERN struct tm *gmtime_r(const time_t *clock, struct tm *result);
#define localtime_r(c,r) gmtime_r(c,r)
+EXTERN int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);
+EXTERN int timer_delete(timer_t timerid);
+EXTERN int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
+ struct itimerspec *ovalue);
+EXTERN int timer_gettime(timer_t timerid, struct itimerspec *value);
+EXTERN int timer_getoverrun(timer_t timerid);
+
#undef EXTERN
#if defined(__cplusplus)
}
diff --git a/nuttx/include/unistd.h b/nuttx/include/unistd.h
index faf50e3a3..164b5368e 100644
--- a/nuttx/include/unistd.h
+++ b/nuttx/include/unistd.h
@@ -53,6 +53,49 @@
#define ATEXIT_MAX 1
+/* Values for seeking */
+
+#define SEEK_SET 0 /* From the start of the file */
+#define SEEK_CUR 1 /* From the current file offset */
+#define SEEK_END 2 /* From the end of the file */
+
+/* Bit values for the second argument to access */
+
+#define F_OK 0 /* Test existence */
+#define R_OK 1 /* Test read permission */
+#define W_OK 2 /* Test write permission */
+#define X_OK 4 /* Test execute permission */
+
+/* POSIX feature set macros */
+
+#define POSIX_VERSION
+#undef _POSIX_SAVED_IDS
+#undef _POSIX_JOB_CONTROL
+#define _POSIX_REALTIME_SIGNALS 1
+#define _POSIX_MESSAGE_PASSING 1
+#undef _POSIX_MAPPED_FILES
+#undef _POSIX_SHARED_MEMORY_OBJECTS
+#define _POSIX_PRIORITY_SCHEDULING 1
+#define _POSIX_TIMERS
+#undef _POSIX_MEMLOCK
+#undef _POSIX_MEMLOCK_RANGE
+#undef _POSIX_FSYNC
+#define _POSIX_SYNCHRONIZED_IO
+#undef _POSIX_ASYNCHRONOUS_IO
+#undef _POSIX_PRIORITIZED_IO
+
+/* Execution time constants (not supported) */
+
+#undef _POSIX_CHOWN_RESTRICTED
+#undef _POSIX_NO_TRUNC
+#undef _POSIX_VDISABLE
+
+#define _POSIX_SYNC_IO
+#undef _POSIX_ASYNC_IO
+#undef _POSIX_PRIO_IO
+
+#define fsync(f)
+
/************************************************************
* Global Function Prototypes
************************************************************/
@@ -70,12 +113,17 @@ extern "C" {
EXTERN pid_t getpid(void);
EXTERN void _exit(int status) noreturn_function;
EXTERN unsigned int sleep(unsigned int seconds);
-EXTERN void usleep(unsigned long usec);
+EXTERN void usleep(unsigned long usec);
/* File descriptor operations */
-EXTERN int dup(int fildes);
-EXTERN int dup2(int fildes1, int fildes2);
+EXTERN int close(int fd);
+EXTERN int dup(int fildes);
+EXTERN int dup2(int fildes1, int fildes2);
+EXTERN off_t lseek(int fd, off_t offset, int whence);
+EXTERN int read(int fd, void *buf, unsigned int nbytes);
+EXTERN int unlink(const char *path);
+EXTERN int write(int fd, const void *buf, unsigned int nbytes);
#undef EXTERN
#if defined(__cplusplus)