Merge branch 'driver-refactoring' into new-driver-refactoring
[yaffs2.git] / direct / test-framework / yaffs_osglue.c
1 /*
2  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14
15 #include "yaffscfg.h"
16 #include "yaffs_guts.h"
17 #include "yaffsfs.h"
18 #include "yaffs_trace.h"
19 #include <assert.h>
20
21 #include <errno.h>
22
23
24 static int yaffsfs_lastError;
25
26 void yaffsfs_SetError(int err)
27 {
28         //Do whatever to set error
29         yaffsfs_lastError = err;
30 }
31
32 int yaffsfs_GetLastError(void)
33 {
34         return yaffsfs_lastError;
35 }
36
37 int yaffsfs_CheckMemRegion(const void *addr, size_t size, int writeable)
38 {
39         if(!addr)
40                 return -1;
41         return 0;
42 }
43
44
45 #ifdef CONFIG_YAFFS_USE_PTHREADS
46 #include <pthread.h>
47 static pthread_mutex_t mutex1;
48
49
50 void yaffsfs_Lock(void)
51 {
52         pthread_mutex_lock( &mutex1 );
53 }
54
55 void yaffsfs_Unlock(void)
56 {
57         pthread_mutex_unlock( &mutex1 );
58 }
59
60 void yaffsfs_LockInit(void)
61 {
62         pthread_mutex_init( &mutex1, NULL);
63 }
64
65 #else
66
67 void yaffsfs_Lock(void)
68 {
69 }
70
71 void yaffsfs_Unlock(void)
72 {
73 }
74
75 void yaffsfs_LockInit(void)
76 {
77 }
78 #endif
79
80 u32 yaffsfs_CurrentTime(void)
81 {
82         return time(NULL);
83 }
84
85
86 static int yaffs_kill_alloc = 0;
87 static size_t total_malloced = 0;
88 static size_t malloc_limit = 0 & 6000000;
89
90 void *yaffsfs_malloc(size_t size)
91 {
92         void * this;
93         if(yaffs_kill_alloc)
94                 return NULL;
95         if(malloc_limit && malloc_limit <(total_malloced + size) )
96                 return NULL;
97
98         this = malloc(size);
99         if(this)
100                 total_malloced += size;
101         return this;
102 }
103
104 void yaffsfs_free(void *ptr)
105 {
106         free(ptr);
107 }
108
109 void yaffsfs_OSInitialisation(void)
110 {
111         yaffsfs_LockInit();
112 }
113
114
115 void yaffs_bug_fn(const char *file_name, int line_no)
116 {
117         printf("yaffs bug detected %s:%d\n",
118                 file_name, line_no);
119         assert(0);
120 }