debuggers.hg
changeset 16821:945820bfedb6
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>
Fixes some functions which are POSIX. Also make them ifndef HAVE_LIBC.
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Jan 22 14:20:22 2008 +0000 (2008-01-22) |
parents | 7b1e7e8a5130 |
children | 898ce9341e6b |
files | extras/mini-os/arch/ia64/time.c extras/mini-os/fs-front.c extras/mini-os/include/blkfront.h extras/mini-os/include/ia64/os.h extras/mini-os/include/lib.h extras/mini-os/include/sched.h extras/mini-os/include/types.h extras/mini-os/include/xmalloc.h extras/mini-os/kernel.c extras/mini-os/lib/math.c extras/mini-os/lib/xmalloc.c extras/mini-os/sched.c |
line diff
1.1 --- a/extras/mini-os/arch/ia64/time.c Tue Jan 22 11:35:26 2008 +0000 1.2 +++ b/extras/mini-os/arch/ia64/time.c Tue Jan 22 14:20:22 2008 +0000 1.3 @@ -76,7 +76,7 @@ static uint64_t itm_val; 1.4 * will already get problems at other places on 2038-01-19 03:14:08) 1.5 */ 1.6 static unsigned long 1.7 -mktime(const unsigned int year0, const unsigned int mon0, 1.8 +_mktime(const unsigned int year0, const unsigned int mon0, 1.9 const unsigned int day, const unsigned int hour, 1.10 const unsigned int min, const unsigned int sec) 1.11 { 1.12 @@ -260,7 +260,7 @@ init_time(void) 1.13 if (efi_get_time(&tm)) { 1.14 printk(" EFI-Time: %d.%d.%d %d:%d:%d\n", tm.Day, 1.15 tm.Month, tm.Year, tm.Hour, tm.Minute, tm.Second); 1.16 - os_time.tv_sec = mktime(SWAP(tm.Year), SWAP(tm.Month), 1.17 + os_time.tv_sec = _mktime(SWAP(tm.Year), SWAP(tm.Month), 1.18 SWAP(tm.Day), SWAP(tm.Hour), 1.19 SWAP(tm.Minute), SWAP(tm.Second)); 1.20 os_time.tv_nsec = tm.Nanosecond;
2.1 --- a/extras/mini-os/fs-front.c Tue Jan 22 11:35:26 2008 +0000 2.2 +++ b/extras/mini-os/fs-front.c Tue Jan 22 14:20:22 2008 +0000 2.3 @@ -817,7 +817,7 @@ void test_fs_import(void *data) 2.4 long ret64; 2.5 2.6 /* Sleep for 1s and then try to open a file */ 2.7 - sleep(1000); 2.8 + msleep(1000); 2.9 ret = fs_create(import, "mini-os-created-directory", 1, 0777); 2.10 printk("Directory create: %d\n", ret); 2.11 2.12 @@ -1013,7 +1013,7 @@ done: 2.13 printk("Backend found at %s\n", import->backend); 2.14 break; 2.15 } 2.16 - sleep(WAIT_PERIOD); 2.17 + msleep(WAIT_PERIOD); 2.18 } 2.19 2.20 if(!import->backend)
3.1 --- a/extras/mini-os/include/blkfront.h Tue Jan 22 11:35:26 2008 +0000 3.2 +++ b/extras/mini-os/include/blkfront.h Tue Jan 22 14:20:22 2008 +0000 3.3 @@ -7,7 +7,7 @@ struct blkfront_aiocb 3.4 struct blkfront_dev *aio_dev; 3.5 uint8_t *aio_buf; 3.6 size_t aio_nbytes; 3.7 - uint64_t aio_offset; 3.8 + off_t aio_offset; 3.9 void *data; 3.10 3.11 grant_ref_t gref[BLKIF_MAX_SEGMENTS_PER_REQUEST];
4.1 --- a/extras/mini-os/include/ia64/os.h Tue Jan 22 11:35:26 2008 +0000 4.2 +++ b/extras/mini-os/include/ia64/os.h Tue Jan 22 14:20:22 2008 +0000 4.3 @@ -38,7 +38,9 @@ 4.4 4.5 4.6 typedef uint64_t paddr_t; /* Physical address. */ 4.7 +#ifndef HAVE_LIBC 4.8 typedef uint64_t caddr_t; /* rr7/kernel memory address. */ 4.9 +#endif 4.10 4.11 #include "page.h" 4.12 #include "mm.h"
5.1 --- a/extras/mini-os/include/lib.h Tue Jan 22 11:35:26 2008 +0000 5.2 +++ b/extras/mini-os/include/lib.h Tue Jan 22 14:20:22 2008 +0000 5.3 @@ -59,6 +59,9 @@ 5.4 #include <stddef.h> 5.5 #include <console.h> 5.6 5.7 +#ifdef HAVE_LIBC 5.8 +#include <stdio.h> 5.9 +#else 5.10 /* printing */ 5.11 #define _p(_x) ((void *)(unsigned long)(_x)) 5.12 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); 5.13 @@ -69,13 +72,16 @@ int vsprintf(char *buf, const char *fmt, 5.14 int sprintf(char * buf, const char *fmt, ...); 5.15 int vsscanf(const char * buf, const char * fmt, va_list args); 5.16 int sscanf(const char * buf, const char * fmt, ...); 5.17 +#endif 5.18 5.19 long simple_strtol(const char *cp,char **endp,unsigned int base); 5.20 unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base); 5.21 long long simple_strtoll(const char *cp,char **endp,unsigned int base); 5.22 unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base); 5.23 5.24 - 5.25 +#ifdef HAVE_LIBC 5.26 +#include <string.h> 5.27 +#else 5.28 /* string and memory manipulation */ 5.29 int memcmp(const void *cs, const void *ct, size_t count); 5.30 void *memcpy(void *dest, const void *src, size_t count); 5.31 @@ -91,7 +97,11 @@ char *strrchr(const char *s, int c); 5.32 char *strstr(const char *s1, const char *s2); 5.33 char * strcat(char * dest, const char * src); 5.34 char *strdup(const char *s); 5.35 +#endif 5.36 5.37 +#define RAND_MIX 2654435769U 5.38 + 5.39 +int rand(void); 5.40 5.41 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 5.42
6.1 --- a/extras/mini-os/include/sched.h Tue Jan 22 11:35:26 2008 +0000 6.2 +++ b/extras/mini-os/include/sched.h Tue Jan 22 14:20:22 2008 +0000 6.3 @@ -47,6 +47,6 @@ void schedule(void); 6.4 6.5 void wake(struct thread *thread); 6.6 void block(struct thread *thread); 6.7 -void sleep(u32 millisecs); 6.8 +void msleep(u32 millisecs); 6.9 6.10 #endif /* __SCHED_H__ */
7.1 --- a/extras/mini-os/include/types.h Tue Jan 22 11:35:26 2008 +0000 7.2 +++ b/extras/mini-os/include/types.h Tue Jan 22 14:20:22 2008 +0000 7.3 @@ -42,7 +42,6 @@ typedef unsigned long u_long; 7.4 #ifdef __i386__ 7.5 typedef long long quad_t; 7.6 typedef unsigned long long u_quad_t; 7.7 -typedef unsigned int uintptr_t; 7.8 7.9 #if !defined(CONFIG_X86_PAE) 7.10 typedef struct { unsigned long pte_low; } pte_t; 7.11 @@ -53,7 +52,6 @@ typedef struct { unsigned long pte_low, 7.12 #elif defined(__x86_64__) || defined(__ia64__) 7.13 typedef long quad_t; 7.14 typedef unsigned long u_quad_t; 7.15 -typedef unsigned long uintptr_t; 7.16 7.17 typedef struct { unsigned long pte; } pte_t; 7.18 #endif /* __i386__ || __x86_64__ */ 7.19 @@ -65,18 +63,31 @@ typedef struct { unsigned long pte; } pt 7.20 ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) 7.21 #endif 7.22 7.23 +#ifdef HAVE_LIBC 7.24 +#include <limits.h> 7.25 +#include <stdint.h> 7.26 +#else 7.27 +#ifdef __i386__ 7.28 +typedef unsigned int uintptr_t; 7.29 +typedef int intptr_t; 7.30 +#elif defined(__x86_64__) || defined(__ia64__) 7.31 +typedef unsigned long uintptr_t; 7.32 +typedef long intptr_t; 7.33 +#endif /* __i386__ || __x86_64__ */ 7.34 typedef u8 uint8_t; 7.35 typedef s8 int8_t; 7.36 typedef u16 uint16_t; 7.37 typedef s16 int16_t; 7.38 typedef u32 uint32_t; 7.39 typedef s32 int32_t; 7.40 -typedef u64 uint64_t; 7.41 -typedef s64 int64_t; 7.42 +typedef u64 uint64_t, uintmax_t; 7.43 +typedef s64 int64_t, intmax_t; 7.44 +typedef u64 off_t; 7.45 7.46 7.47 #define INT_MAX ((int)(~0U>>1)) 7.48 #define UINT_MAX (~0U) 7.49 7.50 typedef long ssize_t; 7.51 +#endif 7.52 #endif /* _TYPES_H_ */
8.1 --- a/extras/mini-os/include/xmalloc.h Tue Jan 22 11:35:26 2008 +0000 8.2 +++ b/extras/mini-os/include/xmalloc.h Tue Jan 22 14:20:22 2008 +0000 8.3 @@ -1,11 +1,15 @@ 8.4 #ifndef __XMALLOC_H__ 8.5 #define __XMALLOC_H__ 8.6 8.7 -/* Allocate space for typed object. */ 8.8 -#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type))) 8.9 +#ifdef HAVE_LIBC 8.10 8.11 -/* Allocate space for array of typed objects. */ 8.12 -#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) 8.13 +#include <stdlib.h> 8.14 +#include <malloc.h> 8.15 +/* Allocate space for typed object. */ 8.16 +#define _xmalloc(size, align) memalign(align, size) 8.17 +#define xfree(ptr) free(ptr) 8.18 + 8.19 +#else 8.20 8.21 #define DEFAULT_ALIGN (sizeof(unsigned long)) 8.22 #define malloc(size) _xmalloc(size, DEFAULT_ALIGN) 8.23 @@ -19,6 +23,8 @@ extern void xfree(const void *); 8.24 extern void *_xmalloc(size_t size, size_t align); 8.25 extern void *_realloc(void *ptr, size_t size); 8.26 8.27 +#endif 8.28 + 8.29 static inline void *_xmalloc_array(size_t size, size_t align, size_t num) 8.30 { 8.31 /* Check for overflow. */ 8.32 @@ -27,4 +33,10 @@ static inline void *_xmalloc_array(size_ 8.33 return _xmalloc(size * num, align); 8.34 } 8.35 8.36 +/* Allocate space for typed object. */ 8.37 +#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type))) 8.38 + 8.39 +/* Allocate space for array of typed objects. */ 8.40 +#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) 8.41 + 8.42 #endif /* __XMALLOC_H__ */
9.1 --- a/extras/mini-os/kernel.c Tue Jan 22 11:35:26 2008 +0000 9.2 +++ b/extras/mini-os/kernel.c Tue Jan 22 14:20:22 2008 +0000 9.3 @@ -80,7 +80,7 @@ static void periodic_thread(void *p) 9.4 { 9.5 gettimeofday(&tv, NULL); 9.6 printk("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec); 9.7 - sleep(1000); 9.8 + msleep(1000); 9.9 } 9.10 } 9.11 9.12 @@ -89,19 +89,6 @@ static void netfront_thread(void *p) 9.13 init_netfront(NULL, NULL, NULL); 9.14 } 9.15 9.16 -#define RAND_MIX 2654435769U 9.17 - 9.18 -/* Should be random enough for this use */ 9.19 -static int rand(void) 9.20 -{ 9.21 - static unsigned int previous; 9.22 - struct timeval tv; 9.23 - gettimeofday(&tv, NULL); 9.24 - previous += tv.tv_sec + tv.tv_usec; 9.25 - previous *= RAND_MIX; 9.26 - return previous; 9.27 -} 9.28 - 9.29 static struct blkfront_dev *blk_dev; 9.30 static uint64_t blk_sectors; 9.31 static unsigned blk_sector_size;
10.1 --- a/extras/mini-os/lib/math.c Tue Jan 22 11:35:26 2008 +0000 10.2 +++ b/extras/mini-os/lib/math.c Tue Jan 22 14:20:22 2008 +0000 10.3 @@ -56,6 +56,8 @@ 10.4 */ 10.5 10.6 #include <types.h> 10.7 +#include <lib.h> 10.8 +#include <time.h> 10.9 10.10 /* On ia64 these functions lead to crashes. These are replaced by 10.11 * assembler functions. */ 10.12 @@ -85,7 +87,9 @@ union uu { 10.13 * These are used for shifting, and also below for halfword extraction 10.14 * and assembly. 10.15 */ 10.16 +#ifndef HAVE_LIBC 10.17 #define CHAR_BIT 8 /* number of bits in a char */ 10.18 +#endif 10.19 #define QUAD_BITS (sizeof(s64) * CHAR_BIT) 10.20 #define LONG_BITS (sizeof(long) * CHAR_BIT) 10.21 #define HALF_BITS (sizeof(long) * CHAR_BIT / 2) 10.22 @@ -385,3 +389,16 @@ u_quad_t 10.23 } 10.24 10.25 #endif /* !defined(__ia64__) */ 10.26 + 10.27 +#ifndef HAVE_LIBC 10.28 +/* Should be random enough for our uses */ 10.29 +int rand(void) 10.30 +{ 10.31 + static unsigned int previous; 10.32 + struct timeval tv; 10.33 + gettimeofday(&tv, NULL); 10.34 + previous += tv.tv_sec + tv.tv_usec; 10.35 + previous *= RAND_MIX; 10.36 + return previous; 10.37 +} 10.38 +#endif
11.1 --- a/extras/mini-os/lib/xmalloc.c Tue Jan 22 11:35:26 2008 +0000 11.2 +++ b/extras/mini-os/lib/xmalloc.c Tue Jan 22 14:20:22 2008 +0000 11.3 @@ -43,6 +43,7 @@ 11.4 #include <list.h> 11.5 #include <xmalloc.h> 11.6 11.7 +#ifndef HAVE_LIBC 11.8 static LIST_HEAD(freelist); 11.9 /* static spinlock_t freelist_lock = SPIN_LOCK_UNLOCKED; */ 11.10 11.11 @@ -295,3 +296,4 @@ void *_realloc(void *ptr, size_t size) 11.12 11.13 return new; 11.14 } 11.15 +#endif
12.1 --- a/extras/mini-os/sched.c Tue Jan 22 11:35:26 2008 +0000 12.2 +++ b/extras/mini-os/sched.c Tue Jan 22 14:20:22 2008 +0000 12.3 @@ -211,7 +211,7 @@ void block(struct thread *thread) 12.4 clear_runnable(thread); 12.5 } 12.6 12.7 -void sleep(u32 millisecs) 12.8 +void msleep(u32 millisecs) 12.9 { 12.10 struct thread *thread = get_current(); 12.11 thread->wakeup_time = NOW() + MILLISECS(millisecs);