/contrib/sdk/sources/newlib/libc/crt/gthr-kos32.c |
---|
21,7 → 21,8 |
<http://www.gnu.org/licenses/>. */ |
#include <errno.h> |
#include <kos32sys.h> |
#include <stdint.h> |
#include <sys/ksys.h> |
#include "gthr-kos32.h" |
#define FUTEX_INIT 0 |
35,6 → 36,42 |
#define exchange_release(ptr, new) \ |
__atomic_exchange_4((ptr), (new), __ATOMIC_RELEASE) |
#define TLS_KEY_PID 0 |
#define TLS_KEY_TID 4 |
#define TLS_KEY_LOW_STACK 8 |
#define TLS_KEY_HIGH_STACK 12 |
#define TLS_KEY_LIBC 16 |
unsigned int tls_alloc(void); |
int tls_free(unsigned int key); |
static inline int tls_set(unsigned int key, void *val) |
{ |
int ret = -1; |
if(key < 4096) |
{ |
__asm__ __volatile__( |
"movl %0, %%fs:(%1)" |
::"r"(val),"r"(key)); |
ret = 0; |
} |
return ret; |
}; |
static inline void *tls_get(unsigned int key) |
{ |
void *val = (void*)-1; |
if(key < 4096) |
{ |
__asm__ __volatile__( |
"movl %%fs:(%1), %0" |
:"=r"(val) |
:"r"(key)); |
}; |
return val; |
} |
int __gthr_kos32_once (__gthread_once_t *once, void (*func) (void)) |
{ |
if (once == NULL || func == NULL) |
50,7 → 87,7 |
else |
{ |
while (! once->done) |
yield(); |
_ksys_thread_yield(); |
} |
} |
return 0; |
92,25 → 129,14 |
void __gthr_kos32_mutex_init_function (__gthread_mutex_t *mutex) |
{ |
int handle; |
mutex->lock = 0; |
__asm__ volatile( |
"int $0x40\t" |
:"=a"(handle) |
:"a"(77),"b"(FUTEX_INIT),"c"(mutex)); |
mutex->handle = handle; |
mutex->handle = _ksys_futex_create(mutex); |
} |
void __gthr_kos32_mutex_destroy (__gthread_mutex_t *mutex) |
{ |
int retval; |
__asm__ volatile( |
"int $0x40\t" |
:"=a"(retval) |
:"a"(77),"b"(FUTEX_DESTROY),"c"(mutex->handle)); |
_ksys_futex_destroy(mutex->handle); |
} |
int __gthr_kos32_mutex_lock (__gthread_mutex_t *mutex) |
122,11 → 148,7 |
while (exchange_acquire (&mutex->lock, 2) != 0) |
{ |
__asm__ volatile( |
"int $0x40\t\n" |
:"=a"(tmp) |
:"a"(77),"b"(FUTEX_WAIT), |
"c"(mutex->handle),"d"(2),"S"(0)); |
_ksys_futex_wait(mutex->handle, 2 , 0); |
} |
return 0; |
} |
146,11 → 168,7 |
if (prev != 1) |
{ |
__asm__ volatile( |
"int $0x40\t" |
:"=a"(prev) |
:"a"(77),"b"(FUTEX_WAKE), |
"c"(mutex->handle),"d"(1)); |
_ksys_futex_wake(mutex->handle, 1); |
}; |
return 0; |
} |
158,14 → 176,9 |
void __gthr_kos32_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex) |
{ |
int handle; |
mutex->lock = 0; |
__asm__ volatile( |
"int $0x40\t" |
:"=a"(handle) |
:"a"(77),"b"(FUTEX_INIT),"c"(mutex)); |
mutex->handle = handle; |
mutex->handle = _ksys_futex_create(mutex); |
mutex->depth = 0; |
mutex->owner = 0; |
190,11 → 203,7 |
} |
else while (exchange_acquire (&mutex->lock, 2) != 0) |
{ |
__asm__ volatile( |
"int $0x40\t\n" |
:"=a"(tmp) |
:"a"(77),"b"(FUTEX_WAIT), |
"c"(mutex->handle),"d"(2),"S"(0)); |
_ksys_futex_wait(mutex->handle, 2, 0); |
mutex->depth = 1; |
mutex->owner = me; |
}; |
232,11 → 241,7 |
if (prev != 1) |
{ |
__asm__ volatile( |
"int $0x40\t" |
:"=a"(prev) |
:"a"(77),"b"(FUTEX_WAKE), |
"c"(mutex->handle),"d"(1)); |
_ksys_futex_wake(mutex->handle, 1); |
}; |
mutex->owner = 0; |
}; |
247,12 → 252,7 |
int __gthr_kos32_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex) |
{ |
int retval; |
__asm__ volatile( |
"int $0x40\t" |
:"=a"(retval) |
:"a"(77),"b"(FUTEX_DESTROY),"c"(mutex->handle)); |
_ksys_futex_destroy(mutex->handle); |
return 0; |
} |
/contrib/sdk/sources/newlib/libc/include/sys/ksys.h |
---|
22,6 → 22,10 |
#include <stddef.h> |
#include <stdint.h> |
#ifdef __cplusplus |
extern "C" { |
#endif |
#define KOSAPI static inline |
#define asm_inline __asm__ __volatile__ |
1617,7 → 1621,7 |
/*============= Function 77, subfunction 0 - create futex object =============*/ |
KOSAPI uint32_t _ksys_futex_create(int* futex_ctrl) |
KOSAPI uint32_t _ksys_futex_create(void* futex_ctrl) |
{ |
uint32_t futex_desc; |
asm_inline( |
1722,4 → 1726,8 |
return res.status; |
} |
#ifdef __cplusplus |
} |
#endif |
#endif // _KSYS_H_ |
/contrib/sdk/sources/newlib/libc/pe/crtloader.c |
---|
6,7 → 6,7 |
#include <setjmp.h> |
#include <envz.h> |
#include <kos32sys.h> |
#include <sys/ksys.h> |
#include "list.h" |
#include "pe.h" |
97,7 → 97,7 |
dos = (PIMAGE_DOS_HEADER)raw; |
nt = MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew); |
img_base = user_alloc(nt->OptionalHeader.SizeOfImage); |
img_base = _ksys_alloc(nt->OptionalHeader.SizeOfImage); |
if(unlikely(img_base == NULL)) |
return 0; |
196,9 → 196,9 |
void *raw_img; |
size_t raw_size; |
void *img_base = NULL; |
ufile_t uf; |
ksys_ufile_t uf; |
uf = load_file("/kolibrios/lib/libc.dll"); |
uf = _ksys_load_file("/kolibrios/lib/libc.dll"); |
raw_img = uf.data; |
raw_size = uf.size; |
214,7 → 214,7 |
img_base = create_image(raw_img); |
}; |
user_free(raw_img); |
_ksys_free(raw_img); |
return img_base; |
/contrib/sdk/sources/newlib/libc/pe/loader.c |
---|
7,7 → 7,7 |
#include <setjmp.h> |
#include <envz.h> |
#include <kos32sys.h> |
#include <sys/ksys.h> |
#include "list.h" |
#include "pe.h" |
22,6 → 22,7 |
void init_loader(void *libc_image); |
void* create_image(void *raw); |
int link_image(void *img_base, PIMAGE_IMPORT_DESCRIPTOR imp); |
void* load_library(const char *name); |
extern char* __appenv; |
extern int __appenv_size; |
266,7 → 267,7 |
dos = (PIMAGE_DOS_HEADER)raw; |
nt = MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew); |
img_base = user_alloc(nt->OptionalHeader.SizeOfImage); |
img_base = _ksys_alloc(nt->OptionalHeader.SizeOfImage); |
if(unlikely(img_base == NULL)) |
return 0; |
651,12 → 652,12 |
PIMAGE_NT_HEADERS32 nt; |
PIMAGE_EXPORT_DIRECTORY exp; |
ufile_t uf; |
ksys_ufile_t uf; |
void *raw_img; |
size_t raw_size; |
void *img_base = NULL; |
uf = load_file(path); |
uf = _ksys_load_file(path); |
raw_img = uf.data; |
raw_size = uf.size; |
666,12 → 667,12 |
if( validate_pe(raw_img, raw_size, 0) == 0) |
{ |
printf("invalide module %s\n", path); |
user_free(raw_img); |
_ksys_free(raw_img); |
return NULL; |
}; |
img_base = create_image(raw_img); |
user_free(raw_img); |
_ksys_free(raw_img); |
if( unlikely(img_base == NULL) ) |
printf("cannot create image %s\n",path); |
797,7 → 798,7 |
free(module->img_path); |
free(module); |
err1: |
user_free(img_base); |
_ksys_free(img_base); |
return NULL; |
}; |
/contrib/sdk/sources/newlib/libc/reent/getreent.c |
---|
3,7 → 3,7 |
#include <_ansi.h> |
#include <string.h> |
#include <sys/reent.h> |
#include <kos32sys.h> |
#include <sys/ksys.h> |
extern _VOID _EXFUN(__sinit,(struct _reent *)); |
11,7 → 11,7 |
{ |
struct _reent *ent; |
ent = user_alloc(sizeof(struct _reent)); |
ent = _ksys_alloc(sizeof(struct _reent)); |
_REENT_INIT_PTR_ZEROED(ent); |
/contrib/sdk/sources/newlib/libc/stdlib/mallocr.c |
---|
36,9 → 36,9 |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <sys/ksys.h> |
struct malloc_chunk { |
size_t prev_foot; /* Size of previous chunk (if free). */ |
size_t head; /* Size and inuse bits. */ |
60,34 → 60,9 |
/* The maximum possible size_t value has all bits set */ |
#define MAX_SIZE_T (~(size_t)0) |
void *user_alloc(size_t size) |
{ |
void *val; |
#define user_alloc(s) _ksys_alloc(s) |
#define user_free _ksys_free |
// __asm__("int3"); |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(68),"b"(12),"c"(size)); |
return val; |
} |
static inline |
int user_free(void *mem) |
{ |
int val; |
// __asm__("int3"); |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(68),"b"(13),"c"(mem)); |
return val; |
} |
/* ------------------- size_t and alignment properties -------------------- */ |
/* The byte and bit size of a size_t */ |
/contrib/sdk/sources/newlib/libc/sys/clock_gettime.c |
---|
20,7 → 20,7 |
#include <stdint.h> |
#include <time.h> |
#include <sys/time.h> |
#include <kos32sys.h> |
#include <sys/ksys.h> |
/* Get current value of CLOCK and store it in TP. */ |
int clock_gettime (clockid_t clock_id, struct timespec *tp) |
27,7 → 27,7 |
{ |
uint64_t tsc; |
tsc = get_ns_count(); |
tsc = _ksys_get_ns_count(); |
tp->tv_sec = tsc / 1000000000; |
tp->tv_nsec = tsc % 1000000000; |