My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
libc_sos.h
Go to the documentation of this file.
1 /*
2  * OpenVirtualization:
3  * For additional details and support contact developer@sierraware.com.
4  * Additional documentation can be found at www.openvirtualization.org
5  *
6  * Copyright (C) 2010-2014 SierraWare
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23 /*
24  */
25 
26 /* This is the header file for those libc functions that may be needed by other
27  * apps.
28  *
29  * ***************** IMPORTANT ************************
30  * Note that we could have done something simple like
31  * #define memset sw_memset
32  * and could have been done with it. However, gcc automatically inserts memcpy
33  * for structure assignments. Hence, we need something along the lines of
34  * function aliasing that is found in c++. For now, we will make these
35  * functions invoke our implementations.
36  * ********* END IMPORTANT SECTION ****************
37  */
38 
39 
40 #ifndef LIBC_SOS_H
41 #define LIBC_SOS_H
42 
43 /*
44  * @brief memove function, it follows the same parameter format as the one in
45  * libc
46  */
47 void* memmove(void * dest,const void *src, unsigned int count);
48 
49 /*
50  * @brief memset function, it follows the same parameter format as the one in
51  * libc
52  **/
53 void* memset(void * dest, unsigned int c, unsigned int count);
54 
55 /*
56  * @brief memcpy function, it follows the same parameter format as the one in
57  * libc. Further, the memory areas must not overlap.
58  **/
59 void* memcpy(void *dst, const void *src, unsigned int count);
60 
61 /*
62  * @brief malloc function, it follows the same parameter format as the one in
63  * libc.
64  **/
65 void* malloc(unsigned int size);
66 
67 /*
68  * @brief realloc function, it follows the same parameter format as the one in
69  * libc
70  **/
71 void* realloc(void *ptr, unsigned int size);
72 
73 /*
74  * @brief calloc function, it follows the same parameter format as the one in
75  * libc
76  **/
77 void* calloc(unsigned int num_elements, unsigned int element_size);
78 
79 /*
80  * @brief free function, it follows the same parameter format as the one in
81  * libc
82  **/
83 void free(void *ptr);
84 
85 /*
86  * @brief strncmp function, it follows the same parameter format as the one in
87  * libc
88  **/
89 int strncmp(const char *s1, const char *s2, unsigned int n);
90 
91 /*
92  * @brief atoi function, it follows the same parameter format as the one in libc
93  *
94  **/
95 unsigned int atoi(const char *ptr);
96 
97 /*
98  * @brief strlen function, it follows the same parameter format as the one in
99  * libc
100  **/
101 unsigned int strlen(const char *ptr);
102 
103 /*
104  * @brief strcpy function, it follows the same parameter format as the one in
105  * libc
106  **/
107 char* strcpy(char *ptr1, const char *ptr2);
108 
109 /*
110  * @brief strcmp function, it follows the same parameter format as the one in
111  * libc
112  **/
113 int strcmp(const char *ptr1, const char *ptr2);
114 
115 /*
116  * @brief strcat function, it follows the same parameter format as the one in
117  * libc
118  **/
119 char* strcat(char *ptr1, const char *ptr2);
120 
124 typedef struct {
125  unsigned int init_param;
126  volatile unsigned int lock_param;
128 
129 #define PTHREAD_MUTEX_INITIALIZER {1,0}
130 /* We do not support attributes */
131 #define pthread_mutexattr_t void
132 
133 /*
134  * @brief pthread_mutex_init function, it follows the same parameter format as
135  * the one in libc
136  **/
138  const pthread_mutexattr_t *attribute);
139 
140 
141 /*
142  * @brief pthread_mutex_destroy function, it follows the same parameter format
143  * as the one in libc
144  **/
146 
147 
148 /*
149  * @brief pthread_mutex_lock function, it follows the same parameter format as
150  * the one in libc
151  **/
153 
154 /*
155  * @brief pthread_mutex_unlock function, it follows the same parameter format as
156  * the one in libc
157  **/
159 
160 /*
161  * @brief pthread_mutex_trylock function, it follows the same parameter format
162  * as the one in libc
163  **/
165 
166 
170 typedef struct {
171  unsigned int init_param;
172  volatile unsigned int counter_param;
173 } sem_t;
174 
175 /*
176  * @brief sem_init function, it follows the same parameter format as the one in
177  * libc
178  **/
179 int sem_init(sem_t *sem, int shared, unsigned int value);
180 
181 /*
182  * @brief sem_wait function, it follows the same parameter format as the one in
183  * libc
184  **/
185 int sem_wait(sem_t *sem);
186 
187 /*
188  * @brief sem_post function, it follows the same parameter format as the one in
189  * libc
190  **/
191 int sem_post(sem_t *sem);
192 
193 /*
194  * @brief sem_destroy function, it follows the same parameter format as the one
195  * in libc
196  **/
197 int sem_destroy(sem_t *sem);
198 
199 
200 /*
201  * @brief sem_getvalue function, it follows the same parameter format as the one
202  * in libc
203  **/
204 int sem_getvalue(sem_t *sem, int *value);
205 
206 /*
207  * @brief sleep function, it follows the same parameter format as the one
208  * in libc
209  **/
210 void sleep(unsigned int seconds);
211 
212 /*
213  * @brief usleep function, it follows the same parameter format as the one
214  * in libc. Instead of microsecond sleep, we do a millisecond sleep.
215  **/
216 void usleep(unsigned int seconds);
217 
229 int truncate(const char* tr_path, long tr_lth);
230 
242 int rename(const char *old_name,const char *new_name);
243 
244 #endif
int strcmp(const char *ptr1, const char *ptr2)
compares the string pointed to by ptr1 to the string pointed to by ptr2
Definition: libc_sos.c:212
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attribute)
initializes the mutex parameters
Definition: libc_sos.c:238
volatile unsigned int counter_param
Definition: libc_sos.h:172
void * malloc(unsigned int size)
int sem_destroy(sem_t *sem)
Destroys the semaphore indicated by sem.
Definition: libc_sos.c:374
unsigned int strlen(const char *ptr)
computes and returns the length of the string pointed to ptr
Definition: libc_sos.c:186
int sem_init(sem_t *sem, int shared, unsigned int value)
int pthread_mutex_trylock(pthread_mutex_t *mutex)
Same as sw_mutex_lock but it does not block the calling function It returns an error code if the mute...
Definition: libc_sos.c:304
void * calloc(unsigned int num_elements, unsigned int element_size)
unsigned int init_param
Definition: libc_sos.h:171
Definition: libc_sos.h:124
unsigned int init_param
Definition: libc_sos.h:125
void sleep(unsigned int seconds)
void * realloc(void *ptr, unsigned int size)
int sem_wait(sem_t *sem)
Locks the semaphore referenced by sem It will return to the calling thread only after locking the sem...
Definition: libc_sos.c:341
char * strcpy(char *ptr1, const char *ptr2)
copies the string pointed to by ptr2 to ptr1
Definition: libc_sos.c:199
void * memmove(void *dest, const void *src, unsigned int count)
Definition: libc_sos.h:170
#define pthread_mutexattr_t
Definition: libc_sos.h:131
int rename(const char *old_name, const char *new_name)
rename - Changes the name of the file or directory specified by oldname to newname ...
Definition: libc_sos.c:475
void usleep(unsigned int seconds)
s32int count
Definition: virtual_keyboard.c:40
void * memset(void *dest, unsigned int c, unsigned int count)
int truncate(const char *tr_path, long tr_lth)
truncate - function cause the regular file named by path to be truncated to a size of precisely lengt...
Definition: libc_sos.c:448
int pthread_mutex_unlock(pthread_mutex_t *mutex)
This function is called to unlock a mutex.
Definition: libc_sos.c:288
int sem_getvalue(sem_t *sem, int *value)
unsigned int atoi(const char *ptr)
converts the string argument pointed to ptr to integer
Definition: libc_sos.c:174
int pthread_mutex_destroy(pthread_mutex_t *mutex)
This function is called to destroy the mutex once it is used If it is under lock it returns an error ...
Definition: libc_sos.c:256
char * strcat(char *ptr1, const char *ptr2)
appends the string pointed to by ptr2 to the end of string pointed to by dest
Definition: libc_sos.c:225
void free(void *ptr)
Deallocates the memory previously allocated.
Definition: libc_sos.c:146
int sem_post(sem_t *sem)
unlocks the semaphore referenced by sem by performing a unlock operation on that semaphore ...
Definition: libc_sos.c:358
int pthread_mutex_lock(pthread_mutex_t *mutex)
This function is called to lock the specified mutex.
Definition: libc_sos.c:272
void * memcpy(void *dst, const void *src, unsigned int count)
int strncmp(const char *s1, const char *s2, unsigned int n)
volatile unsigned int lock_param
Definition: libc_sos.h:126