]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/mini-os.git/commitdiff
minios: POSIX fixes
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 22 Jan 2008 14:20:22 +0000 (14:20 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 22 Jan 2008 14:20:22 +0000 (14:20 +0000)
Fixes some functions which are POSIX.  Also make them ifndef HAVE_LIBC.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
12 files changed:
arch/ia64/time.c
fs-front.c
include/blkfront.h
include/ia64/os.h
include/lib.h
include/sched.h
include/types.h
include/xmalloc.h
kernel.c
lib/math.c
lib/xmalloc.c
sched.c

index cda36e69d47a6da77d42138d8a514fff238d1e44..9fb3157fb6feb53ad66c38249239d159a6dd1142 100644 (file)
@@ -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;
index 7f0bd2b01726b6158d6ea3bc380387cd1471579d..dd8623d71abd4f6113c8db33f4f772a4a3cec3a4 100644 (file)
@@ -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)
index 9460a00942ca6400269e6c97c8dc43c11c0f3025..92e658e899f1bc0a1e5f38c9ee3ae8b79764cb22 100644 (file)
@@ -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];
index 51e365e8a64c4fe0c5bc90ba748710505d159086..e6b7884d7ab65169c8c717a04d9d1397f837bfd5 100644 (file)
@@ -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"
index 97a2305daa515ee6a5005d98e94f1233db2d1197..d946e0a53495a7937511d870ac11957e1359f1b2 100644 (file)
@@ -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]))
 
index 734e441a154f6332e2ad34be7c71627f411a7c03..a3d2022b8a887dd771e1b6541bc7adaa94400767 100644 (file)
@@ -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__ */
index a53db24a93cdea556ddc314f3472096be67ea329..c11765167d0b5652dc0f18715a3c2964d3d6691f 100644 (file)
@@ -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_ */
index 26ae9dd0120704a8d7e0f23f9819b23de04df03d..e168a84f88bbffb9edd3464e8da730a062732944 100644 (file)
@@ -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__ */
index 6e56315549a57e45aba502495f7c339fe60cdda8..a94e743f63c38cb5ccd655dcdfedcd8242f79593 100644 (file)
--- a/kernel.c
+++ b/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;
index 5f5ed55ec257cf81d9c065a1e7303b3f8caa6e29..807bcc8e0decdf89e589a84bb1553b271e423278 100644 (file)
@@ -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
index be3d228c040712c9de4b97a0ae72d94a66c1b375..9e59c9f8349242aaaf35d41cb9bb7367d46a5207 100644 (file)
@@ -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/sched.c b/sched.c
index 5820d646893a63036a79b03a560d04cb9c219286..18b3f015383768b7c624cc38a6055741bf04b36f 100644 (file)
--- a/sched.c
+++ b/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);