/uspace/trunk/libc/include/err.h |
---|
35,7 → 35,10 |
#ifndef _libc__ERR_H_ |
#define _libc__ERR_H_ |
#define errx(status,fmt,...) { printf((fmt),##__VA_ARGS__);_exit(status);} |
#define errx(status, fmt, ...) { \ |
printf((fmt), ##__VA_ARGS__); \ |
_exit(status); \ |
} |
#endif |
42,5 → 45,3 |
/** @} |
*/ |
/uspace/trunk/libc/include/libc.h |
---|
45,16 → 45,12 |
#define __SYSCALL4(id, p1, p2, p3, p4) __syscall(p1,p2,p3,p4,id) |
extern void __main(void); |
extern void __io_init(void); |
extern void __exit(void); |
extern sysarg_t __syscall(const sysarg_t p1, const sysarg_t p2, |
const sysarg_t p3, const sysarg_t p4, |
const syscall_t id); |
extern sysarg_t __syscall(const sysarg_t p1, const sysarg_t p2, const sysarg_t p3, const sysarg_t p4, const syscall_t id); |
#endif |
/** @} |
*/ |
/uspace/trunk/libc/malloc/malloc.c |
---|
2930,10 → 2930,9 |
if (HAVE_MMAP && |
sp->size >= extra && |
!has_segment_link(m, sp)) { /* can't shrink if pinned */ |
size_t newsize = sp->size - extra; |
/* Prefer mremap, fall back to munmap */ |
if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != MFAIL) || |
(CALL_MUNMAP(sp->base + newsize, extra) == 0)) { |
if ((CALL_MREMAP(sp->base, sp->size, sp->size - extra, 0) != MFAIL) || |
(CALL_MUNMAP(sp->base + sp->size - extra, extra) == 0)) { |
released = extra; |
} |
} |
/uspace/trunk/libc/Makefile.toolchain |
---|
27,7 → 27,7 |
# |
DEFS = -DARCH=$(ARCH) |
CFLAGS = -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -O3 -nostdlib -nostdinc -I$(LIBC_PREFIX)/include |
CFLAGS = -fno-builtin -Wall -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -I$(LIBC_PREFIX)/include |
LFLAGS = -M -N $(SOFTINT_PREFIX)/libsoftint.a |
AFLAGS = |
#-Werror |
/uspace/trunk/libc/generic/time.c |
---|
73,9 → 73,7 |
if (!ktime) { |
mapping = as_get_mappable_page(PAGE_SIZE); |
/* Get the mapping of kernel clock */ |
res = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_RECV, |
mapping, PAGE_SIZE, SERVICE_MEM_REALTIME, |
NULL,&rights,NULL); |
res = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_RECV, (sysarg_t) mapping, PAGE_SIZE, SERVICE_MEM_REALTIME, NULL, &rights, NULL); |
if (res) { |
printf("Failed to initialize timeofday memarea\n"); |
_exit(1); |
119,5 → 117,3 |
/** @} |
*/ |
/uspace/trunk/libc/generic/ddi.c |
---|
69,7 → 69,6 |
*/ |
int iospace_enable(task_id_t id, void *ioaddr, unsigned long size) |
{ |
task_id_t task_id; |
ddi_ioarg_t arg; |
arg.task_id = id; |
91,5 → 90,3 |
/** @} |
*/ |
/uspace/trunk/libc/generic/cap.c |
---|
52,7 → 52,7 |
arg.value = (unsigned long long) id; |
__SYSCALL2(SYS_CAP_GRANT, (sysarg_t) &arg, (sysarg_t) caps); |
return __SYSCALL2(SYS_CAP_GRANT, (sysarg_t) &arg, (sysarg_t) caps); |
} |
/** Revoke capabilities from a task. |
68,11 → 68,9 |
arg.value = (unsigned long long) id; |
__SYSCALL2(SYS_CAP_REVOKE, (sysarg_t) &arg, (sysarg_t) caps); |
return __SYSCALL2(SYS_CAP_REVOKE, (sysarg_t) &arg, (sysarg_t) caps); |
} |
/** @} |
*/ |
/uspace/trunk/libc/generic/as.c |
---|
92,17 → 92,22 |
{ |
int rc; |
void *res; |
/* Check for invalid values */ |
if (incr < 0 && -incr > heapsize) |
return NULL; |
/* Check for too large value */ |
if (incr > 0 && incr+heapsize < heapsize) |
return NULL; |
/* Check for too small values */ |
if (incr < 0 && incr+heapsize > heapsize) |
return NULL; |
/* Check for user limit */ |
if ((maxheapsize!=(size_t)(-1)) && (heapsize + incr)>maxheapsize) return NULL; |
if ((maxheapsize != (size_t) (-1)) && (heapsize + incr) > maxheapsize) |
return NULL; |
rc = as_area_resize(&_heap, heapsize + incr,0); |
if (rc != 0) |
121,7 → 126,7 |
{ |
maxheapsize=mhs; |
/* Return pointer to area not managed by sbrk */ |
return (void *)&_heap + maxheapsize; |
return ((void *) &_heap + maxheapsize); |
} |
137,8 → 142,9 |
/* Set heapsize to some meaningful value */ |
if (maxheapsize == -1) |
set_maxheapsize(ALIGN_UP(USER_ADDRESS_SPACE_SIZE_ARCH>>1,PAGE_SIZE)); |
if (!last_allocated) |
last_allocated = ALIGN_UP((void *)&_heap + maxheapsize, PAGE_SIZE); |
last_allocated = (void *) ALIGN_UP((void *) &_heap + maxheapsize, PAGE_SIZE); |
sz = ALIGN_UP(sz, PAGE_SIZE); |
res = last_allocated; |
147,8 → 153,5 |
return res; |
} |
/** @} |
*/ |
/uspace/trunk/libc/generic/string.c |
---|
44,12 → 44,16 |
void * memset(void *s, int c, size_t n) |
{ |
char *os = s; |
while (n--) |
*(os++) = c; |
return s; |
} |
struct along {unsigned long n; } __attribute__ ((packed)); |
struct along { |
unsigned long n; |
} __attribute__ ((packed)); |
static void * unaligned_memcpy(void *dst, const void *src, size_t n) |
{ |
90,7 → 94,7 |
return memcpy(dst, src, n); |
for (j = (n%sizeof(unsigned long))-1; j >= 0; j--) |
((unsigned char *)(((unsigned long *) dst) + i))[j] = ((unsigned char *)(((unsigned long *) src) + i))[j]; |
((unsigned char *) ((unsigned long *) dst))[j] = ((unsigned char *) ((unsigned long *) src))[j]; |
for (i = n/sizeof(unsigned long)-1; i >=0 ; i--) |
((unsigned long *) dst)[i] = ((unsigned long *) src)[i]; |
107,9 → 111,8 |
{ |
size_t counter = 0; |
while (str[counter] != 0) { |
while (str[counter] != 0) |
counter++; |
} |
return counter; |
} |
118,14 → 121,14 |
{ |
int c=0; |
while(a[c]&&b[c]&&(!(a[c]-b[c]))) c++; |
while (a[c] && b[c] && (!(a[c] - b[c]))) |
c++; |
return a[c]-b[c]; |
return (a[c] - b[c]); |
} |
/** Return pointer to the first occurence of character c in string |
* @param str scanned string |
* @param c searched character (taken as one byte) |
297,18 → 300,20 |
char *strcpy(char *dest, const char *src) |
{ |
while (*(dest++) = *(src++)) |
; |
char *orig = dest; |
while ((*(dest++) = *(src++))); |
return orig; |
} |
char *strncpy(char *dest, const char *src, size_t n) |
{ |
while ((*(dest++) = *(src++)) && --n) |
; |
char *orig = dest; |
while ((*(dest++) = *(src++)) && --n); |
return orig; |
} |
/** @} |
*/ |
/uspace/trunk/libc/generic/libc.c |
---|
25,6 → 25,7 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup lc Libc |
* @brief HelenOS C library |
* @{ |
49,11 → 50,13 |
extern char _heap; |
void _exit(int status) { |
void _exit(int status) |
{ |
thread_exit(status); |
} |
void __main(void) { |
void __main(void) |
{ |
psthread_data_t *pt; |
(void) as_area_create(&_heap, 1, AS_AREA_WRITE | AS_AREA_READ); |
62,19 → 65,18 |
__tcb_set(pt->tcb); |
} |
void __io_init(void) { |
void __io_init(void) |
{ |
open("stdin", 0); |
open("stdout", 0); |
open("stderr", 0); |
} |
void __exit(void) { |
void __exit(void) |
{ |
psthread_teardown(__tcb_get()->pst_data); |
_exit(0); |
} |
/** @} |
*/ |
/uspace/trunk/libc/generic/psthread.c |
---|
51,7 → 51,6 |
static LIST_INITIALIZE(serialized_list); |
static LIST_INITIALIZE(manager_list); |
static void psthread_exit(void) __attribute__ ((noinline)); |
static void psthread_main(void); |
static atomic_t psthread_futex = FUTEX_INITIALIZER; |
191,7 → 190,7 |
*/ |
int psthread_join(pstid_t psthrid) |
{ |
volatile psthread_data_t *pt, *mypt; |
volatile psthread_data_t *pt; |
volatile int retval; |
/* Handle psthrid = Kernel address -> it is wait for call */ |
238,8 → 237,7 |
pt->flags = 0; |
context_save(&pt->ctx); |
context_set(&pt->ctx, FADDR(psthread_main), pt->stack, PSTHREAD_INITIAL_STACK_PAGES_NO*getpagesize(), |
pt->tcb); |
context_set(&pt->ctx, FADDR(psthread_main), pt->stack, PSTHREAD_INITIAL_STACK_PAGES_NO*getpagesize(), pt->tcb); |
return (pstid_t )pt; |
} |
309,5 → 307,3 |
/** @} |
*/ |
/uspace/trunk/libc/generic/async.c |
---|
373,11 → 373,13 |
/* Setup thread local connection pointer */ |
PS_connection = (connection_t *)arg; |
PS_connection->cthread(PS_connection->callid, &PS_connection->call); |
/* Remove myself from connection hash table */ |
futex_down(&async_futex); |
key = PS_connection->in_phone_hash; |
hash_table_remove(&conn_hash_table, &key, 1); |
futex_up(&async_futex); |
/* Answer all remaining messages with ehangup */ |
while (!list_empty(&PS_connection->msg_queue)) { |
msg = list_get_instance(PS_connection->msg_queue.next, msg_t, link); |
389,6 → 391,8 |
} |
if (PS_connection->close_callid) |
ipc_answer_fast(PS_connection->close_callid, 0, 0, 0); |
return 0; |
} |
/** Create new thread for a new connection |
405,11 → 409,8 |
* opening the connection |
* @return New thread id |
*/ |
pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
ipc_call_t *call, |
void (*cthread)(ipc_callid_t,ipc_call_t *)) |
pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, ipc_call_t *call, void (*cthread)(ipc_callid_t, ipc_call_t *)) |
{ |
pstid_t ptid; |
connection_t *conn; |
unsigned long key; |
514,7 → 515,8 |
while (1) { |
if (psthread_schedule_next_adv(PS_FROM_MANAGER)) { |
futex_up(&async_futex); /* async_futex is always held |
futex_up(&async_futex); |
/* async_futex is always held |
* when entering manager thread |
*/ |
continue; |
546,6 → 548,8 |
handle_call(callid, &call); |
} |
return 0; |
} |
/** Function to start async_manager as a standalone thread |
557,9 → 561,12 |
*/ |
static int async_manager_thread(void *arg) |
{ |
futex_up(&async_futex); /* async_futex is always locked when entering |
futex_up(&async_futex); |
/* async_futex is always locked when entering |
* manager */ |
async_manager_worker(); |
return 0; |
} |
/** Add one manager to manager list */ |
585,6 → 592,7 |
return ENOMEM; |
} |
return 0; |
} |
/** IPC handler for messages in async framework |
679,7 → 687,6 |
void async_wait_for(aid_t amsgid, ipcarg_t *retval) |
{ |
amsg_t *msg = (amsg_t *) amsgid; |
connection_t *conn; |
futex_down(&async_futex); |
if (msg->done) { |
711,7 → 718,6 |
int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout) |
{ |
amsg_t *msg = (amsg_t *) amsgid; |
connection_t *conn; |
/* TODO: Let it go through the event read at least once */ |
if (timeout < 0) |
804,5 → 810,3 |
/** @} |
*/ |
/uspace/trunk/libc/generic/io/stream.c |
---|
81,7 → 81,6 |
static ssize_t write_stdout(void *param, const void *buf, size_t count) |
{ |
int i; |
ipcarg_t r0,r1; |
for (i = 0; i < count; i++) |
async_msg(streams[1].phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]); |
90,12 → 89,9 |
} |
static stream_t open_stdin(void) |
{ |
stream_t stream; |
int phoneid; |
int res; |
if (console_phone < 0) { |
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { |
104,6 → 100,7 |
} |
stream.r = read_stdin; |
stream.w = NULL; |
stream.param = 0; |
stream.phone = console_phone; |
113,7 → 110,6 |
static stream_t open_stdout(void) |
{ |
stream_t stream; |
int res; |
if (console_phone < 0) { |
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { |
121,9 → 117,11 |
} |
} |
stream.r = NULL; |
stream.w = write_stdout; |
stream.phone = console_phone; |
stream.param = 0; |
return stream; |
} |
139,6 → 137,7 |
while (((streams[c].w) || (streams[c].r)) && (c < FDS)) |
c++; |
if (c == FDS) |
return EMFILE; |
156,10 → 155,13 |
streams[c].w = write_stderr; |
return c; |
} |
if (!strcmp(fname, "null")) { |
streams[c].w = write_null; |
return c; |
} |
return -1; |
} |
191,5 → 193,3 |
/** @} |
*/ |
/uspace/trunk/libc/generic/err.c |
---|
35,14 → 35,13 |
#include <stdio.h> |
#include <stdlib.h> |
/* TODO |
void errx (int __status, __const char *__format, ...) |
{ |
printf("TODO...errx\n"); |
_exit(0); |
} |
*/ |
/** @} |
*/ |
/uspace/trunk/libc/generic/mmap.c |
---|
36,11 → 36,8 |
#include <as.h> |
#include <unistd.h> |
void *mmap(void *start, size_t length, int prot, int flags, int fd, |
off_t offset) |
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) |
{ |
int rc; |
if (!start) |
start = as_get_mappable_page(length); |
60,5 → 57,3 |
/** @} |
*/ |