aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-01-22 14:20:22 +0000
committerKeir Fraser <keir.fraser@citrix.com>2008-01-22 14:20:22 +0000
commite8c1abd6e75d35e747611bcad82d0d4a6564beca (patch)
tree932aa4b778d3c4871b21f89eaa4db484c34e1d21
parentdfba81d2fcc227ffc2ce546d9884580f682e68b5 (diff)
downloadxen-e8c1abd6e75d35e747611bcad82d0d4a6564beca.tar.gz
xen-e8c1abd6e75d35e747611bcad82d0d4a6564beca.tar.bz2
xen-e8c1abd6e75d35e747611bcad82d0d4a6564beca.zip
minios: POSIX fixes
Fixes some functions which are POSIX. Also make them ifndef HAVE_LIBC. Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
-rw-r--r--extras/mini-os/arch/ia64/time.c4
-rw-r--r--extras/mini-os/fs-front.c4
-rw-r--r--extras/mini-os/include/blkfront.h2
-rw-r--r--extras/mini-os/include/ia64/os.h2
-rw-r--r--extras/mini-os/include/lib.h12
-rw-r--r--extras/mini-os/include/sched.h2
-rw-r--r--extras/mini-os/include/types.h19
-rw-r--r--extras/mini-os/include/xmalloc.h18
-rw-r--r--extras/mini-os/kernel.c15
-rw-r--r--extras/mini-os/lib/math.c17
-rw-r--r--extras/mini-os/lib/xmalloc.c2
-rw-r--r--extras/mini-os/sched.c2
12 files changed, 70 insertions, 29 deletions
diff --git a/extras/mini-os/arch/ia64/time.c b/extras/mini-os/arch/ia64/time.c
index cda36e69d4..9fb3157fb6 100644
--- a/extras/mini-os/arch/ia64/time.c
+++ b/extras/mini-os/arch/ia64/time.c
@@ -76,7 +76,7 @@ static uint64_t itm_val;
* will already get problems at other places on 2038-01-19 03:14:08)
*/
static unsigned long
-mktime(const unsigned int year0, const unsigned int mon0,
+_mktime(const unsigned int year0, const unsigned int mon0,
const unsigned int day, const unsigned int hour,
const unsigned int min, const unsigned int sec)
{
@@ -260,7 +260,7 @@ init_time(void)
if (efi_get_time(&tm)) {
printk(" EFI-Time: %d.%d.%d %d:%d:%d\n", tm.Day,
tm.Month, tm.Year, tm.Hour, tm.Minute, tm.Second);
- os_time.tv_sec = mktime(SWAP(tm.Year), SWAP(tm.Month),
+ os_time.tv_sec = _mktime(SWAP(tm.Year), SWAP(tm.Month),
SWAP(tm.Day), SWAP(tm.Hour),
SWAP(tm.Minute), SWAP(tm.Second));
os_time.tv_nsec = tm.Nanosecond;
diff --git a/extras/mini-os/fs-front.c b/extras/mini-os/fs-front.c
index 7f0bd2b017..dd8623d71a 100644
--- a/extras/mini-os/fs-front.c
+++ b/extras/mini-os/fs-front.c
@@ -817,7 +817,7 @@ void test_fs_import(void *data)
long ret64;
/* Sleep for 1s and then try to open a file */
- sleep(1000);
+ msleep(1000);
ret = fs_create(import, "mini-os-created-directory", 1, 0777);
printk("Directory create: %d\n", ret);
@@ -1013,7 +1013,7 @@ done:
printk("Backend found at %s\n", import->backend);
break;
}
- sleep(WAIT_PERIOD);
+ msleep(WAIT_PERIOD);
}
if(!import->backend)
diff --git a/extras/mini-os/include/blkfront.h b/extras/mini-os/include/blkfront.h
index 9460a00942..92e658e899 100644
--- a/extras/mini-os/include/blkfront.h
+++ b/extras/mini-os/include/blkfront.h
@@ -7,7 +7,7 @@ struct blkfront_aiocb
struct blkfront_dev *aio_dev;
uint8_t *aio_buf;
size_t aio_nbytes;
- uint64_t aio_offset;
+ off_t aio_offset;
void *data;
grant_ref_t gref[BLKIF_MAX_SEGMENTS_PER_REQUEST];
diff --git a/extras/mini-os/include/ia64/os.h b/extras/mini-os/include/ia64/os.h
index 51e365e8a6..e6b7884d7a 100644
--- a/extras/mini-os/include/ia64/os.h
+++ b/extras/mini-os/include/ia64/os.h
@@ -38,7 +38,9 @@
typedef uint64_t paddr_t; /* Physical address. */
+#ifndef HAVE_LIBC
typedef uint64_t caddr_t; /* rr7/kernel memory address. */
+#endif
#include "page.h"
#include "mm.h"
diff --git a/extras/mini-os/include/lib.h b/extras/mini-os/include/lib.h
index 97a2305daa..d946e0a534 100644
--- a/extras/mini-os/include/lib.h
+++ b/extras/mini-os/include/lib.h
@@ -59,6 +59,9 @@
#include <stddef.h>
#include <console.h>
+#ifdef HAVE_LIBC
+#include <stdio.h>
+#else
/* printing */
#define _p(_x) ((void *)(unsigned long)(_x))
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
@@ -69,13 +72,16 @@ int vsprintf(char *buf, const char *fmt, va_list args);
int sprintf(char * buf, const char *fmt, ...);
int vsscanf(const char * buf, const char * fmt, va_list args);
int sscanf(const char * buf, const char * fmt, ...);
+#endif
long simple_strtol(const char *cp,char **endp,unsigned int base);
unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);
long long simple_strtoll(const char *cp,char **endp,unsigned int base);
unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
-
+#ifdef HAVE_LIBC
+#include <string.h>
+#else
/* string and memory manipulation */
int memcmp(const void *cs, const void *ct, size_t count);
void *memcpy(void *dest, const void *src, size_t count);
@@ -91,7 +97,11 @@ char *strrchr(const char *s, int c);
char *strstr(const char *s1, const char *s2);
char * strcat(char * dest, const char * src);
char *strdup(const char *s);
+#endif
+
+#define RAND_MIX 2654435769U
+int rand(void);
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/extras/mini-os/include/sched.h b/extras/mini-os/include/sched.h
index 734e441a15..a3d2022b8a 100644
--- a/extras/mini-os/include/sched.h
+++ b/extras/mini-os/include/sched.h
@@ -47,6 +47,6 @@ void schedule(void);
void wake(struct thread *thread);
void block(struct thread *thread);
-void sleep(u32 millisecs);
+void msleep(u32 millisecs);
#endif /* __SCHED_H__ */
diff --git a/extras/mini-os/include/types.h b/extras/mini-os/include/types.h
index a53db24a93..c11765167d 100644
--- a/extras/mini-os/include/types.h
+++ b/extras/mini-os/include/types.h
@@ -42,7 +42,6 @@ typedef unsigned long u_long;
#ifdef __i386__
typedef long long quad_t;
typedef unsigned long long u_quad_t;
-typedef unsigned int uintptr_t;
#if !defined(CONFIG_X86_PAE)
typedef struct { unsigned long pte_low; } pte_t;
@@ -53,7 +52,6 @@ typedef struct { unsigned long pte_low, pte_high; } pte_t;
#elif defined(__x86_64__) || defined(__ia64__)
typedef long quad_t;
typedef unsigned long u_quad_t;
-typedef unsigned long uintptr_t;
typedef struct { unsigned long pte; } pte_t;
#endif /* __i386__ || __x86_64__ */
@@ -65,18 +63,31 @@ typedef struct { unsigned long pte; } pte_t;
((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
#endif
+#ifdef HAVE_LIBC
+#include <limits.h>
+#include <stdint.h>
+#else
+#ifdef __i386__
+typedef unsigned int uintptr_t;
+typedef int intptr_t;
+#elif defined(__x86_64__) || defined(__ia64__)
+typedef unsigned long uintptr_t;
+typedef long intptr_t;
+#endif /* __i386__ || __x86_64__ */
typedef u8 uint8_t;
typedef s8 int8_t;
typedef u16 uint16_t;
typedef s16 int16_t;
typedef u32 uint32_t;
typedef s32 int32_t;
-typedef u64 uint64_t;
-typedef s64 int64_t;
+typedef u64 uint64_t, uintmax_t;
+typedef s64 int64_t, intmax_t;
+typedef u64 off_t;
#define INT_MAX ((int)(~0U>>1))
#define UINT_MAX (~0U)
typedef long ssize_t;
+#endif
#endif /* _TYPES_H_ */
diff --git a/extras/mini-os/include/xmalloc.h b/extras/mini-os/include/xmalloc.h
index 26ae9dd012..e168a84f88 100644
--- a/extras/mini-os/include/xmalloc.h
+++ b/extras/mini-os/include/xmalloc.h
@@ -1,11 +1,15 @@
#ifndef __XMALLOC_H__
#define __XMALLOC_H__
+#ifdef HAVE_LIBC
+
+#include <stdlib.h>
+#include <malloc.h>
/* Allocate space for typed object. */
-#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
+#define _xmalloc(size, align) memalign(align, size)
+#define xfree(ptr) free(ptr)
-/* Allocate space for array of typed objects. */
-#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
+#else
#define DEFAULT_ALIGN (sizeof(unsigned long))
#define malloc(size) _xmalloc(size, DEFAULT_ALIGN)
@@ -19,6 +23,8 @@ extern void xfree(const void *);
extern void *_xmalloc(size_t size, size_t align);
extern void *_realloc(void *ptr, size_t size);
+#endif
+
static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
{
/* Check for overflow. */
@@ -27,4 +33,10 @@ static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
return _xmalloc(size * num, align);
}
+/* Allocate space for typed object. */
+#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
+
+/* Allocate space for array of typed objects. */
+#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
+
#endif /* __XMALLOC_H__ */
diff --git a/extras/mini-os/kernel.c b/extras/mini-os/kernel.c
index 6e56315549..a94e743f63 100644
--- a/extras/mini-os/kernel.c
+++ b/extras/mini-os/kernel.c
@@ -80,7 +80,7 @@ static void periodic_thread(void *p)
{
gettimeofday(&tv, NULL);
printk("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec);
- sleep(1000);
+ msleep(1000);
}
}
@@ -89,19 +89,6 @@ static void netfront_thread(void *p)
init_netfront(NULL, NULL, NULL);
}
-#define RAND_MIX 2654435769U
-
-/* Should be random enough for this use */
-static int rand(void)
-{
- static unsigned int previous;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- previous += tv.tv_sec + tv.tv_usec;
- previous *= RAND_MIX;
- return previous;
-}
-
static struct blkfront_dev *blk_dev;
static uint64_t blk_sectors;
static unsigned blk_sector_size;
diff --git a/extras/mini-os/lib/math.c b/extras/mini-os/lib/math.c
index 5f5ed55ec2..807bcc8e0d 100644
--- a/extras/mini-os/lib/math.c
+++ b/extras/mini-os/lib/math.c
@@ -56,6 +56,8 @@
*/
#include <types.h>
+#include <lib.h>
+#include <time.h>
/* On ia64 these functions lead to crashes. These are replaced by
* assembler functions. */
@@ -85,7 +87,9 @@ union uu {
* These are used for shifting, and also below for halfword extraction
* and assembly.
*/
+#ifndef HAVE_LIBC
#define CHAR_BIT 8 /* number of bits in a char */
+#endif
#define QUAD_BITS (sizeof(s64) * CHAR_BIT)
#define LONG_BITS (sizeof(long) * CHAR_BIT)
#define HALF_BITS (sizeof(long) * CHAR_BIT / 2)
@@ -385,3 +389,16 @@ __umoddi3(u_quad_t a, u_quad_t b)
}
#endif /* !defined(__ia64__) */
+
+#ifndef HAVE_LIBC
+/* Should be random enough for our uses */
+int rand(void)
+{
+ static unsigned int previous;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ previous += tv.tv_sec + tv.tv_usec;
+ previous *= RAND_MIX;
+ return previous;
+}
+#endif
diff --git a/extras/mini-os/lib/xmalloc.c b/extras/mini-os/lib/xmalloc.c
index be3d228c04..9e59c9f834 100644
--- a/extras/mini-os/lib/xmalloc.c
+++ b/extras/mini-os/lib/xmalloc.c
@@ -43,6 +43,7 @@
#include <list.h>
#include <xmalloc.h>
+#ifndef HAVE_LIBC
static LIST_HEAD(freelist);
/* static spinlock_t freelist_lock = SPIN_LOCK_UNLOCKED; */
@@ -295,3 +296,4 @@ void *_realloc(void *ptr, size_t size)
return new;
}
+#endif
diff --git a/extras/mini-os/sched.c b/extras/mini-os/sched.c
index 5820d64689..18b3f01538 100644
--- a/extras/mini-os/sched.c
+++ b/extras/mini-os/sched.c
@@ -211,7 +211,7 @@ void block(struct thread *thread)
clear_runnable(thread);
}
-void sleep(u32 millisecs)
+void msleep(u32 millisecs)
{
struct thread *thread = get_current();
thread->wakeup_time = NOW() + MILLISECS(millisecs);