1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
|
/* Copyright (c) 2008-2010, Advanced Micro Devices. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Advanced Micro Devices nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __KOSAPI_H
#define __KOSAPI_H
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#include "os_types.h"
//////////////////////////////////////////////////////////////////////////////
// entrypoint abstraction
//////////////////////////////////////////////////////////////////////////////
#if defined(_WIN32) && !defined (_WIN32_WCE) && !defined(__SYMBIAN32__)
#define KOS_DLLEXPORT __declspec(dllexport)
#define KOS_DLLIMPORT __declspec(dllimport)
#elif defined(_WIN32) && defined (_WIN32_WCE)
#define KOS_DLLEXPORT __declspec(dllexport)
#define KOS_DLLIMPORT
#else
#define KOS_DLLEXPORT extern
#define KOS_DLLIMPORT
#endif // _WIN32
//////////////////////////////////////////////////////////////////////////////
// KOS lib entrypoints
//////////////////////////////////////////////////////////////////////////////
#ifdef __KOSLIB_EXPORTS
#define KOS_API KOS_DLLEXPORT
#else
#define KOS_API KOS_DLLIMPORT
#endif // __KOSLIB_EXPORTS
//////////////////////////////////////////////////////////////////////////////
// assert API
//////////////////////////////////////////////////////////////////////////////
KOS_API void kos_assert_hook(const char* file, int line, int expression);
#if defined(DEBUG) || defined(DBG) || defined (_DBG) || defined (_DEBUG)
#if defined(_WIN32) && !defined(__SYMBIAN32__) || defined(_WIN32_WCE)
#include <assert.h>
#define KOS_ASSERT(expression) assert(expression)
#elif defined(_BREW)
#include <assert.h>
#define KOS_ASSERT(expression) kos_assert_hook(__FILE__, __LINE__, expression)
#elif defined(__SYMBIAN32__)
//#include <assert.h>
//#define KOS_ASSERT(expression) assert(expression)
#define KOS_ASSERT(expression) /**/
#elif defined(__ARM__)
#define KOS_ASSERT(expression)
#elif defined(_LINUX)
#define KOS_ASSERT(expression) //kos_assert_hook(__FILE__, __LINE__, (int)(expression))
#endif
#else
#define KOS_ASSERT(expression)
#endif // DEBUG || DBG || _DBG
#if defined(_WIN32) && defined(_DEBUG) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
#pragma warning ( push, 3 )
#include <crtdbg.h>
#pragma warning (pop)
#define KOS_MALLOC_DBG(size) _malloc_dbg(size, _NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define KOS_MALLOC_DBG(size) kos_malloc(int size)
#endif // _WIN32 _DEBUG
#define kos_assert(expression) KOS_ASSERT(expression)
#define kos_malloc_dbg(size) KOS_MALLOC_DBG(size)
#ifdef UNDER_CE
#define KOS_PAGE_SIZE 0x1000
#endif
typedef enum mutexIndex mutexIndex_t;
//////////////////////////////////////////////////////////////////////////////
// Interprocess shared memory initialization
//////////////////////////////////////////////////////////////////////////////
// TODO: still valid?
KOS_API int kos_sharedmem_create(unsigned int map_addr, unsigned int size);
KOS_API int kos_sharedmem_destroy(void);
//////////////////////////////////////////////////////////////////////////////
// heap API (per process)
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Allocate memory for a kernel side process.
*
*
* \param int size Amount of bytes to be allocated.
* \return Pointer to the reserved memory, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_malloc(int size);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Allocate memory for a kernel side process. Clears the reserved memory.
*
*
* \param int num Number of elements to allocate.
* \param int size Element size in bytes.
* \return Pointer to the reserved memory, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_calloc(int num, int size);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Re-allocate an existing memory for a kernel side process.
* Contents of the old block will be copied to the new block
* taking the sizes of both blocks into account.
*
*
* \param void* memblock Pointer to the old memory block.
* \param int size Size of the new block in bytes.
* \return Pointer to the new memory block, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_realloc(void* memblock, int size);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Free a reserved memory block from the kernel side process.
*
*
* \param void* memblock Pointer to the memory block.
*//*-------------------------------------------------------------------*/
KOS_API void kos_free(void* memblock);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Enable automatic memory leak checking performed at program exit.
*
*
*//*-------------------------------------------------------------------*/
KOS_API void kos_enable_memoryleakcheck(void);
//////////////////////////////////////////////////////////////////////////////
// shared heap API (cross process)
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Allocate memory that can be shared between user and kernel
* side processes.
*
*
* \param int size Amount of bytes to be allocated.
* \return Pointer to the new memory block, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_shared_malloc(int size);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Allocate memory that can be shared between user and kernel
* side processes. Clears the reserved memory.
*
*
* \param int num Number of elements to allocate.
* \param int size Element size in bytes.
* \return Pointer to the reserved memory, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_shared_calloc(int num, int size);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Re-allocate an existing user/kernel shared memory block.
* Contents of the old block will be copied to the new block
* taking the sizes of both blocks into account.
*
*
* \param void* ptr Pointer to the old memory block.
* \param int size Size of the new block in bytes.
* \return Pointer to the new memory block, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_shared_realloc(void* ptr, int size);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Free a reserved shared memory block.
*
*
* \param void* ptr Pointer to the memory block.
*//*-------------------------------------------------------------------*/
KOS_API void kos_shared_free(void* ptr);
//////////////////////////////////////////////////////////////////////////////
// memory API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Copies the values of num bytes from the location pointed by src
* directly to the memory block pointed by dst.
*
*
* \param void* dst Pointer to the destination memory block.
* \param void* src Pointer to the source memory block.
* \param void* count Amount of bytes to copy.
* \return Returns the dst pointer, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_memcpy(void* dst, const void* src, int count);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Fills the destination memory block with the given value.
*
*
* \param void* dst Pointer to the destination memory block.
* \param int value Value to be written to each destination address.
* \param void* count Number of bytes to be set to the value.
* \return Returns the dst pointer, NULL if any error.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_memset(void* dst, int value, int count);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Compares two memory blocks.
*
*
* \param void* dst Pointer to the destination memory block.
* \param void* src Pointer to the source memory block.
* \param void* count Number of bytes to compare.
* \return Zero if identical, >0 if first nonmatching byte is greater in dst.
*//*-------------------------------------------------------------------*/
KOS_API int kos_memcmp(void* dst, void* src, int count);
//////////////////////////////////////////////////////////////////////////////
// physical memory API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Allocates a physically contiguous memory block.
*
*
* \param void** virt_addr Pointer where to store the virtual address of the reserved block.
* \param void** phys_addr Pointer where to store the physical address of the reserved block.
* \param int pages Number of pages to reserve (default page size = 4096 bytes).
* \return Zero if ok, othervise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_alloc_physical(void** virt_addr, void** phys_addr, int pages);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Free a physically contiguous allocated memory block.
*
*
* \param void* virt_addr Virtual address of the memory block.
* \param int pages Number of pages.
* \return Zero if ok, othervise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_free_physical(void* virt_addr, int pages);
KOS_API void kos_memoryfence(void);
//////////////////////////////////////////////////////////////////////////////
// string API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Perform a string copy.
*
*
* \param void* strdestination Pointer to destination memory.
* \param void* strsource Pointer to the source string.
* \return Zero if ok, othervise an error code.
*//*-------------------------------------------------------------------*/
KOS_API char* kos_strcpy(char* strdestination, const char* strsource);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Perform a string copy with given length.
*
*
* \param void* destination Pointer to destination memory.
* \param void* source Pointer to the source string.
* \param int length Amount of bytes to copy.
* \return Returns the destination pointer.
*//*-------------------------------------------------------------------*/
KOS_API char* kos_strncpy(char* destination, const char* source, int length);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Append source string to destination string.
*
*
* \param void* strdestination Pointer to destination string.
* \param void* strsource Pointer to the source string.
* \return Returns the destination pointer.
*//*-------------------------------------------------------------------*/
KOS_API char* kos_strcat(char* strdestination, const char* strsource);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Compare two strings.
*
*
* \param void* string1 Pointer to first string.
* \param void* string2 Pointer to second string.
* \param void* length Number of bytes to compare.
* \return Zero if identical, >0 if first string is lexically greater <0 if not.
*//*-------------------------------------------------------------------*/
KOS_API int kos_strcmp(const char* string1, const char* string2);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Compares two strings of given length.
*
*
* \param void* string1 Pointer to first string.
* \param void* string2 Pointer to second string.
* \param void* length Number of bytes to compare.
* \return Zero if identical, >0 if first string is lexically greater <0 if not.
*//*-------------------------------------------------------------------*/
KOS_API int kos_strncmp(const char* string1, const char* string2, int length);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Calculates the length of a string..
*
*
* \param void* string Pointer to the string.
* \return Lenght of the string in bytes.
*//*-------------------------------------------------------------------*/
KOS_API int kos_strlen(const char* string);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Convert an numeric ascii string to integer value.
*
*
* \param void* string Pointer to the string.
* \return Integer value extracted from the string.
*//*-------------------------------------------------------------------*/
KOS_API int kos_atoi(const char* string);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Convert string to unsigned long integer.
*
*
* \param void* nptr Pointer to the string.
* \param char** endptr If not null, will be set to point to the next character after the number.
* \param int base Base defining the type of the numeric string.
* \return Unsigned integer value extracted from the string.
*//*-------------------------------------------------------------------*/
KOS_API unsigned int kos_strtoul(const char* nptr, char** endptr, int base);
//////////////////////////////////////////////////////////////////////////////
// sync API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Create a mutex instance.
*
*
* \param void* name Name string for the new mutex.
* \return Returns a handle to the mutex.
*//*-------------------------------------------------------------------*/
KOS_API oshandle_t kos_mutex_create(const char* name);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get a handle to an already existing mutex.
*
*
* \param void* name Name string for the new mutex.
* \return Returns a handle to the mutex.
*//*-------------------------------------------------------------------*/
KOS_API oshandle_t kos_mutex_open(const char* name);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Free the given mutex.
*
*
* \param oshandle_t mutexhandle Handle to the mutex.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_mutex_free(oshandle_t mutexhandle);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Lock the given mutex.
*
*
* \param oshandle_t mutexhandle Handle to the mutex.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_mutex_lock(oshandle_t mutexhandle);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Try to lock the given mutex, if already locked returns immediately.
*
*
* \param oshandle_t mutexhandle Handle to the mutex.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_mutex_locktry(oshandle_t mutexhandle);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Try to lock the given mutex by waiting for its release. Returns without locking if the
* mutex is already locked and cannot be acquired within the given period.
*
*
* \param oshandle_t mutexhandle Handle to the mutex.
* \param int millisecondstowait Time to wait for the mutex to be available.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_mutex_lockwait(oshandle_t mutexhandle, int millisecondstowait);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Unlock the given mutex.
*
*
* \param oshandle_t mutexhandle Handle to the mutex.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_mutex_unlock(oshandle_t mutexhandle);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Increments (increases by one) the value of the specified 32-bit variable as an atomic operation.
*
*
* \param int* ptr Pointer to the value to be incremented.
* \return Returns the new incremented value.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interlock_incr(int* ptr);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Decrements (decreases by one) the value of the specified 32-bit variable as an atomic operation.
*
*
* \param int* ptr Pointer to the value to be decremented.
* \return Returns the new decremented value.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interlock_decr(int* ptr);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Atomic replacement of a value.
*
*
* \param int* ptr Pointer to the value to be replaced.
* \param int value The new value.
* \return Returns the old value.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interlock_xchg(int* ptr, int value);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Perform an atomic compare-and-exchange operation on the specified values. Compares the two specified 32-bit values and exchanges
* with another 32-bit value based on the outcome of the comparison.
*
*
* \param int* ptr Pointer to the value to be replaced.
* \param int value The new value.
* \param int compvalue Value to be compared with.
* \return Returns the initial value of the first given parameter.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interlock_compxchg(int* ptr, int value, int compvalue);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Atomic addition of two 32-bit values.
*
*
* \param int* ptr Pointer to the target value.
* \param int value Value to be added to the target.
* \return Returns the initial value of the target.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interlock_xchgadd(int* ptr, int value);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Create an event semaphore.
*
*
* \param int a_manualReset Selection for performing reset manually (or by the system).
* \return Returns an handle to the created semaphore.
*//*-------------------------------------------------------------------*/
KOS_API oshandle_t kos_event_create(int a_manualReset);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Destroy an event semaphore.
*
*
* \param oshandle_t a_event Handle to the semaphore.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_event_destroy(oshandle_t a_event);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Signal an event semaphore.
*
*
* \param oshandle_t a_event Handle to the semaphore.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_event_signal(oshandle_t a_event);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Reset an event semaphore.
*
*
* \param oshandle_t a_event Handle to the semaphore.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_event_reset(oshandle_t a_event);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Wait for an event semaphore to be freed and acquire it.
*
*
* \param oshandle_t a_event Handle to the semaphore.
* \param int a_milliSeconds Time to wait.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_event_wait(oshandle_t a_event, int a_milliSeconds);
//////////////////////////////////////////////////////////////////////////////
// interrupt handler API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Enable an interrupt with specified id.
*
*
* \param int interrupt Identification number for the interrupt.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interrupt_enable(int interrupt);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Disable an interrupt with specified id.
*
*
* \param int interrupt Identification number for the interrupt.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interrupt_disable(int interrupt);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Set the callback function for an interrupt.
*
*
* \param int interrupt Identification number for the interrupt.
* \param void* handler Pointer to the callback function.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interrupt_setcallback(int interrupt, void* handler);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Remove a callback function from an interrupt.
*
*
* \param int interrupt Identification number for the interrupt.
* \param void* handler Pointer to the callback function.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_interrupt_clearcallback(int interrupt, void* handler);
//////////////////////////////////////////////////////////////////////////////
// thread and process API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Allocate an entry from the thread local storage table.
*
*
* \return Index of the reserved entry.
*//*-------------------------------------------------------------------*/
KOS_API unsigned int kos_tls_alloc(void);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Free an entry from the thread local storage table.
*
*
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_tls_free(unsigned int tlsindex);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Read the value of an entry in the thread local storage table.
*
*
* \param unsigned int tlsindex Index of the entry.
* \return Returns the value of the entry.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_tls_read(unsigned int tlsindex);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Write a value to an entry in the thread local storage table.
*
*
* \param unsigned int tlsindex Index of the entry.
* \param void* tlsvalue Value to be written.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_tls_write(unsigned int tlsindex, void* tlsvalue);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Put the thread to sleep for the given time period.
*
*
* \param unsigned int milliseconds Time in milliseconds.
*//*-------------------------------------------------------------------*/
KOS_API void kos_sleep(unsigned int milliseconds);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get the id of the current process.
*
*
* \return Returns the process id.
*//*-------------------------------------------------------------------*/
KOS_API unsigned int kos_process_getid(void);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get the id of the current caller process.
*
*
* \return Returns the caller process id.
*//*-------------------------------------------------------------------*/
KOS_API unsigned int kos_callerprocess_getid(void);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get the id of the current thread.
*
*
* \return Returns the thread id.
*//*-------------------------------------------------------------------*/
KOS_API unsigned int kos_thread_getid(void);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Create a new thread.
*
*
* \param oshandle_t a_function Handle to the function to be executed in the thread.
* \param unsigned int* a_threadId Pointer to a value where to store the ID of the new thread.
* \return Returns an handle to the created thread.
*//*-------------------------------------------------------------------*/
KOS_API oshandle_t kos_thread_create(oshandle_t a_function, unsigned int* a_threadId);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Destroy the given thread.
*
*
* \param oshandle_t a_task Handle to the thread to be destroyed.
*//*-------------------------------------------------------------------*/
KOS_API void kos_thread_destroy( oshandle_t a_task );
//////////////////////////////////////////////////////////////////////////////
// timing API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get the current time as a timestamp.
*
*
* \return Returns the timestamp.
*//*-------------------------------------------------------------------*/
KOS_API unsigned int kos_timestamp(void);
//////////////////////////////////////////////////////////////////////////////
// libary API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Map the given library (not required an all OS'es).
*
*
* \param char* libraryname The name string of the lib.
* \return Returns a handle for the lib.
*//*-------------------------------------------------------------------*/
KOS_API oshandle_t kos_lib_map(char* libraryname);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Unmap the given library.
*
* \param oshandle_t libhandle Handle to the lib.
* \return Returns an error code incase of an error.
*//*-------------------------------------------------------------------*/
KOS_API int kos_lib_unmap(oshandle_t libhandle);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get the address of a lib.
*
* \param oshandle_t libhandle Handle to the lib.
* \return Returns a pointer to the lib.
*//*-------------------------------------------------------------------*/
KOS_API void* kos_lib_getaddr(oshandle_t libhandle, char* procname);
//////////////////////////////////////////////////////////////////////////////
// query API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get device system info.
*
* \param os_sysinfo_t* sysinfo Pointer to the destination sysinfo structure.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_get_sysinfo(os_sysinfo_t* sysinfo);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Get system status info.
*
* \param os_stats_t* stats Pointer to the destination stats structure.
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_get_stats(os_stats_t* stats);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Sync block start
*
* \param void
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_syncblock_start(void);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Sync block end
*
* \param void
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_syncblock_end(void);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Sync block start with argument
*
* \param void
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_syncblock_start_ex( mutexIndex_t a_index );
/*-------------------------------------------------------------------*//*!
* \external
* \brief Sync block start with argument
*
* \param void
* \return Returns NULL if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_syncblock_end_ex( mutexIndex_t a_index );
//////////////////////////////////////////////////////////////////////////////
// file API
//////////////////////////////////////////////////////////////////////////////
/*-------------------------------------------------------------------*//*!
* \external
* \brief Opens a file
*
* \param const char* filename Name of the file to open.
* \param const char* mode Mode used for file opening. See fopen.
* \return Returns file handle or NULL if error.
*//*-------------------------------------------------------------------*/
KOS_API oshandle_t kos_fopen(const char* filename, const char* mode);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Writes to a file
*
* \param oshandle_t file Handle of the file to write to.
* \param const char* format Format string. See fprintf.
* \return Returns the number of bytes written
*//*-------------------------------------------------------------------*/
KOS_API int kos_fprintf(oshandle_t file, const char* format, ...);
/*-------------------------------------------------------------------*//*!
* \external
* \brief Closes a file
*
* \param oshandle_t file Handle of the file to close.
* \return Returns zero if no error, otherwise an error code.
*//*-------------------------------------------------------------------*/
KOS_API int kos_fclose(oshandle_t file);
#ifdef __SYMBIAN32__
KOS_API void kos_create_dfc(void);
KOS_API void kos_signal_dfc(void);
KOS_API void kos_enter_critical_section();
KOS_API void kos_leave_critical_section();
#endif // __SYMBIAN32__
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __KOSAPI_H
|