[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] minios: POSIX fixes



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1201011622 0
# Node ID 945820bfedb6e8169cfe98284a06092580d9a19d
# Parent  7b1e7e8a51305df3afe90436d7acde30a1080604
minios: POSIX fixes
Fixes some functions which are POSIX.  Also make them ifndef HAVE_LIBC.

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
---
 extras/mini-os/arch/ia64/time.c   |    4 ++--
 extras/mini-os/fs-front.c         |    4 ++--
 extras/mini-os/include/blkfront.h |    2 +-
 extras/mini-os/include/ia64/os.h  |    2 ++
 extras/mini-os/include/lib.h      |   12 +++++++++++-
 extras/mini-os/include/sched.h    |    2 +-
 extras/mini-os/include/types.h    |   19 +++++++++++++++----
 extras/mini-os/include/xmalloc.h  |   18 +++++++++++++++---
 extras/mini-os/kernel.c           |   15 +--------------
 extras/mini-os/lib/math.c         |   17 +++++++++++++++++
 extras/mini-os/lib/xmalloc.c      |    2 ++
 extras/mini-os/sched.c            |    2 +-
 12 files changed, 70 insertions(+), 29 deletions(-)

diff -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/arch/ia64/time.c
--- a/extras/mini-os/arch/ia64/time.c   Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/arch/ia64/time.c   Tue Jan 22 14:20:22 2008 +0000
@@ -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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/fs-front.c
--- a/extras/mini-os/fs-front.c Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/fs-front.c Tue Jan 22 14:20:22 2008 +0000
@@ -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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/include/blkfront.h
--- a/extras/mini-os/include/blkfront.h Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/include/blkfront.h Tue Jan 22 14:20:22 2008 +0000
@@ -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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/include/ia64/os.h
--- a/extras/mini-os/include/ia64/os.h  Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/include/ia64/os.h  Tue Jan 22 14:20:22 2008 +0000
@@ -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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/include/lib.h
--- a/extras/mini-os/include/lib.h      Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/include/lib.h      Tue Jan 22 14:20:22 2008 +0000
@@ -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 sprintf(char * buf, const char *fmt,
 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  *strstr(const char *s1, const char
 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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/include/sched.h
--- a/extras/mini-os/include/sched.h    Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/include/sched.h    Tue Jan 22 14:20:22 2008 +0000
@@ -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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/include/types.h
--- a/extras/mini-os/include/types.h    Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/include/types.h    Tue Jan 22 14:20:22 2008 +0000
@@ -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, 
 #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; } pt
     ((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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/include/xmalloc.h
--- a/extras/mini-os/include/xmalloc.h  Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/include/xmalloc.h  Tue Jan 22 14:20:22 2008 +0000
@@ -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 *_xmalloc(size_t size, size_
 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_
        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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/kernel.c
--- a/extras/mini-os/kernel.c   Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/kernel.c   Tue Jan 22 14:20:22 2008 +0000
@@ -80,26 +80,13 @@ 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);
     }
 }
 
 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;
diff -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/lib/math.c
--- a/extras/mini-os/lib/math.c Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/lib/math.c Tue Jan 22 14:20:22 2008 +0000
@@ -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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/lib/xmalloc.c
--- a/extras/mini-os/lib/xmalloc.c      Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/lib/xmalloc.c      Tue Jan 22 14:20:22 2008 +0000
@@ -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 -r 7b1e7e8a5130 -r 945820bfedb6 extras/mini-os/sched.c
--- a/extras/mini-os/sched.c    Tue Jan 22 11:35:26 2008 +0000
+++ b/extras/mini-os/sched.c    Tue Jan 22 14:20:22 2008 +0000
@@ -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);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.