/trunk/uspace/lib/libc/generic/errno.c |
---|
File deleted |
/trunk/uspace/lib/libc/generic/io/io.c |
---|
89,7 → 89,7 |
static LIST_INITIALIZE(files); |
void __stdio_init(int filc, fdi_node_t *filv[]) |
void stdio_init(int filc, fdi_node_t *filv[]) |
{ |
if (filc > 0) { |
stdin = fopen_node(filv[0], "r"); |
113,7 → 113,7 |
} |
} |
void __stdio_done(void) |
void stdio_done(void) |
{ |
link_t *link = files.next; |
/trunk/uspace/lib/libc/generic/async.c |
---|
738,7 → 738,7 |
* |
* @return Zero on success or an error code. |
*/ |
int __async_init(void) |
int _async_init(void) |
{ |
if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1, |
&conn_hash_table_ops)) { |
/trunk/uspace/lib/libc/generic/libc.c |
---|
52,8 → 52,11 |
#include <as.h> |
#include <loader/pcb.h> |
extern char _heap; |
extern int main(int argc, char *argv[]); |
int _errno; |
void _exit(int status) |
{ |
thread_exit(status); |
61,8 → 64,9 |
void __main(void *pcb_ptr) |
{ |
__heap_init(); |
__async_init(); |
(void) as_area_create(&_heap, 1, AS_AREA_WRITE | AS_AREA_READ); |
_async_init(); |
fibril_t *fibril = fibril_setup(); |
__tcb_set(fibril->tcb); |
75,15 → 79,15 |
if (__pcb == NULL) { |
argc = 0; |
argv = NULL; |
__stdio_init(0, NULL); |
stdio_init(0, NULL); |
} else { |
argc = __pcb->argc; |
argv = __pcb->argv; |
__stdio_init(__pcb->filc, __pcb->filv); |
stdio_init(__pcb->filc, __pcb->filv); |
} |
main(argc, argv); |
__stdio_done(); |
stdio_done(); |
} |
void __exit(void) |
/trunk/uspace/lib/libc/generic/as.c |
---|
38,10 → 38,11 |
#include <align.h> |
#include <sys/types.h> |
#include <bitops.h> |
#include <malloc.h> |
/** Last position allocated by as_get_mappable_page */ |
static uintptr_t last_allocated = 0; |
/** |
* Either 4*256M on 32-bit architecures or 16*256M on 64-bit architectures. |
*/ |
#define MAX_HEAP_SIZE (sizeof(uintptr_t)<<28) |
/** Create address space area. |
* |
50,7 → 51,6 |
* @param flags Flags describing type of the area. |
* |
* @return address on success, (void *) -1 otherwise. |
* |
*/ |
void *as_area_create(void *address, size_t size, int flags) |
{ |
65,8 → 65,7 |
* @param size New requested size of the area. |
* @param flags Currently unused. |
* |
* @return zero on success or a code from @ref errno.h on failure. |
* |
* @return Zero on success or a code from @ref errno.h on failure. |
*/ |
int as_area_resize(void *address, size_t size, int flags) |
{ |
79,8 → 78,7 |
* @param address Virtual address pointing into the address space area being |
* destroyed. |
* |
* @return zero on success or a code from @ref errno.h on failure. |
* |
* @return Zero on success or a code from @ref errno.h on failure. |
*/ |
int as_area_destroy(void *address) |
{ |
93,8 → 91,7 |
* modified. |
* @param flags New flags describing type of the area. |
* |
* @return zero on success or a code from @ref errno.h on failure. |
* |
* @return Zero on success or a code from @ref errno.h on failure. |
*/ |
int as_area_change_flags(void *address, int flags) |
{ |
102,29 → 99,101 |
(sysarg_t) flags); |
} |
static size_t heapsize = 0; |
static size_t maxheapsize = (size_t) (-1); |
static void *last_allocated = 0; |
/* Start of heap linker symbol */ |
extern char _heap; |
/** Sbrk emulation |
* |
* @param incr New area that should be allocated or negative, |
if it should be shrinked |
* @return Pointer to newly allocated area |
*/ |
void *sbrk(ssize_t incr) |
{ |
int rc; |
void *res; |
/* Check for invalid values */ |
if ((incr < 0) && (((size_t) -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; |
rc = as_area_resize(&_heap, heapsize + incr, 0); |
if (rc != 0) |
return NULL; |
/* Compute start of new area */ |
res = (void *) &_heap + heapsize; |
heapsize += incr; |
return res; |
} |
/** Set maximum heap size and return pointer just after the heap */ |
void *set_maxheapsize(size_t mhs) |
{ |
maxheapsize = mhs; |
/* Return pointer to area not managed by sbrk */ |
return ((void *) &_heap + maxheapsize); |
} |
/** Return pointer to some unmapped area, where fits new as_area |
* |
* @param size Requested size of the allocation. |
* @param sz Requested size of the allocation. |
* |
* @return pointer to the beginning |
* @return Pointer to the beginning |
* |
* TODO: make some first_fit/... algorithm, we are now just incrementing |
* the pointer to last area |
*/ |
void *as_get_mappable_page(size_t size) |
void *as_get_mappable_page(size_t sz) |
{ |
if (size == 0) |
void *res; |
uint64_t asz; |
int i; |
if (!sz) |
return NULL; |
size_t sz = 1 << (fnzb(size - 1) + 1); |
if (last_allocated == 0) |
last_allocated = get_max_heap_addr(); |
asz = 1 << (fnzb64(sz - 1) + 1); |
/* Set heapsize to some meaningful value */ |
if (maxheapsize == (size_t) -1) |
set_maxheapsize(MAX_HEAP_SIZE); |
/* |
* Make sure we allocate from naturally aligned address. |
*/ |
uintptr_t res = ALIGN_UP(last_allocated, sz); |
last_allocated = res + ALIGN_UP(size, PAGE_SIZE); |
i = 0; |
if (!last_allocated) { |
last_allocated = (void *) ALIGN_UP((void *) &_heap + |
maxheapsize, asz); |
} else { |
last_allocated = (void *) ALIGN_UP(((uintptr_t) |
last_allocated) + (int) (i > 0), asz); |
} |
return ((void *) res); |
res = last_allocated; |
last_allocated += ALIGN_UP(sz, PAGE_SIZE); |
return res; |
} |
/** @} |
/trunk/uspace/lib/libc/generic/getopt.c |
---|
47,7 → 47,7 |
int optind = 1; /* index into parent argv vector */ |
int optopt = '?'; /* character checked for validity */ |
int optreset; /* reset getopt */ |
const char *optarg; /* argument associated with option */ |
char *optarg; /* argument associated with option */ |
#define IGNORE_FIRST (*options == '-' || *options == '+') |
162,7 → 162,7 |
char **nargv; |
const char *options; |
{ |
const char *oli; /* option letter list index */ |
char *oli; /* option letter list index */ |
int optchar; |
assert(nargv != NULL); |
275,7 → 275,7 |
} else { /* takes (optional) argument */ |
optarg = NULL; |
if (*place) /* no white space */ |
optarg = place; |
optarg = *place; |
/* XXX: disable test for :: if PC? (GNU doesn't) */ |
else if (oli[1] != ':') { /* arg not optional */ |
if (++optind >= nargc) { /* no arg */ |
353,8 → 353,7 |
retval = getopt_internal(nargc, (char **)nargv, options); |
if (retval == -2) { |
char *current_argv; |
const char *has_equal; |
char *current_argv, *has_equal; |
size_t current_argv_len; |
int i, ambiguous, match; |
/trunk/uspace/lib/libc/generic/mman.c |
---|
45,7 → 45,6 |
// if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE))) |
// return MAP_FAILED; |
if (!(flags & MAP_ANONYMOUS)) |
return MAP_FAILED; |
/trunk/uspace/lib/libc/include/async.h |
---|
46,7 → 46,11 |
extern atomic_t async_futex; |
extern int __async_init(void); |
static inline void async_manager(void) |
{ |
fibril_switch(FIBRIL_TO_MANAGER); |
} |
extern ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); |
static inline ipc_callid_t async_get_call(ipc_call_t *data) |
54,11 → 58,6 |
return async_get_call_timeout(data, 0); |
} |
static inline void async_manager(void) |
{ |
fibril_switch(FIBRIL_TO_MANAGER); |
} |
/* |
* User-friendly wrappers for async_send_fast() and async_send_slow(). The |
* macros are in the form async_send_m(), where m denotes the number of payload |
95,6 → 94,7 |
extern void async_usleep(suseconds_t timeout); |
extern void async_create_manager(void); |
extern void async_destroy_manager(void); |
extern int _async_init(void); |
extern void async_set_client_connection(async_client_conn_t conn); |
extern void async_set_interrupt_received(async_client_conn_t conn); |
/trunk/uspace/lib/libc/include/stdio.h |
---|
37,7 → 37,6 |
#include <sys/types.h> |
#include <stdarg.h> |
#include <string.h> |
#include <adt/list.h> |
#define EOF (-1) |
47,10 → 46,10 |
#define DEBUG(fmt, ...) \ |
{ \ |
char _buf[256]; \ |
int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \ |
if (_n > 0) \ |
(void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) _buf, str_size(_buf)); \ |
char buf[256]; \ |
int n = snprintf(buf, sizeof(buf), fmt, ##__VA_ARGS__); \ |
if (n > 0) \ |
(void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, str_size(buf)); \ |
} |
#ifndef SEEK_SET |
/trunk/uspace/lib/libc/include/adt/gcdlcm.h |
---|
File deleted |
/trunk/uspace/lib/libc/include/vfs/vfs.h |
---|
55,8 → 55,8 |
extern int mount(const char *, const char *, const char *, const char *, |
unsigned int); |
extern void __stdio_init(int filc, fdi_node_t *filv[]); |
extern void __stdio_done(void); |
extern void stdio_init(int filc, fdi_node_t *filv[]); |
extern void stdio_done(void); |
extern int open_node(fdi_node_t *, int); |
extern int fd_phone(int); |
/trunk/uspace/lib/libc/include/unistd.h |
---|
65,6 → 65,7 |
extern int chdir(const char *); |
extern void _exit(int status) __attribute__ ((noreturn)); |
extern void *sbrk(ssize_t incr); |
extern int usleep(unsigned long usec); |
extern unsigned int sleep(unsigned int seconds); |
/trunk/uspace/lib/libc/include/errno.h |
---|
35,13 → 35,12 |
#ifndef LIBC_ERRNO_H_ |
#define LIBC_ERRNO_H_ |
#include <kernel/errno.h> |
#include <fibril.h> |
/* TODO: support threads/fibrils */ |
extern int _errno; |
#define errno _errno |
#include <kernel/errno.h> |
#define EMFILE (-17) |
#define ENAMETOOLONG (-256) |
#define EISDIR (-257) |
/trunk/uspace/lib/libc/include/macros.h |
---|
35,9 → 35,6 |
#ifndef LIBC_MACROS_H_ |
#define LIBC_MACROS_H_ |
#define min(a, b) ((a) < (b) ? (a) : (b)) |
#define max(a, b) ((a) > (b) ? (a) : (b)) |
#define SIZE2KB(size) ((size) >> 10) |
#define SIZE2MB(size) ((size) >> 20) |
/trunk/uspace/lib/libc/include/getopt.h |
---|
58,7 → 58,7 |
}; |
/* HelenOS Port - These need to be exposed for legacy getopt() */ |
extern const char *optarg; |
extern char *optarg; |
extern int optind, opterr, optopt; |
extern int optreset; |
/trunk/uspace/lib/libc/include/bitops.h |
---|
42,9 → 42,9 |
* |
* If number is zero, it returns 0 |
*/ |
static inline unsigned int fnzb32(uint32_t arg) |
static inline int fnzb32(uint32_t arg) |
{ |
unsigned int n = 0; |
int n = 0; |
if (arg >> 16) { |
arg >>= 16; |
74,9 → 74,9 |
return n; |
} |
static inline unsigned int fnzb64(uint64_t arg) |
static inline int fnzb64(uint64_t arg) |
{ |
unsigned int n = 0; |
int n = 0; |
if (arg >> 32) { |
arg >>= 32; |
83,13 → 83,10 |
n += 32; |
} |
return (n + fnzb32((uint32_t) arg)); |
return n + fnzb32((uint32_t) arg); |
} |
static inline unsigned int fnzb(size_t arg) |
{ |
return fnzb64(arg); |
} |
#define fnzb(x) fnzb32(x) |
#endif |
/trunk/uspace/lib/libc/include/stdlib.h |
---|
50,7 → 50,6 |
{ |
return random(); |
} |
static inline void srand(unsigned int seed) |
{ |
srandom(seed); |
/trunk/uspace/lib/libc/Makefile |
---|
49,7 → 49,6 |
generic/cap.c \ |
generic/devmap.c \ |
generic/event.c \ |
generic/errno.c \ |
generic/mem.c \ |
generic/string.c \ |
generic/fibril.c \ |
69,7 → 68,7 |
generic/io/vsnprintf.c \ |
generic/io/printf_core.c \ |
generic/io/console.c \ |
generic/malloc.c \ |
malloc/malloc.c \ |
generic/sysinfo.c \ |
generic/ipc.c \ |
generic/async.c \ |
106,7 → 105,7 |
clean: |
-rm -f include/kernel include/arch include/libarch libc.a arch/$(UARCH)/_link.ld Makefile.depend |
find generic/ arch/$(UARCH)/ -name '*.o' -follow -exec rm \{\} \; |
find generic/ arch/$(UARCH)/ malloc -name '*.o' -follow -exec rm \{\} \; |
depend: kerninc |
-makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null |
/trunk/uspace/lib/libc/arch/ia64/Makefile.inc |
---|
37,7 → 37,7 |
arch/$(UARCH)/src/tls.c \ |
arch/$(UARCH)/src/ddi.c |
CFLAGS += -fno-unwind-tables |
CFLAGS += -fno-unwind-tables -DMALLOC_ALIGNMENT_16 |
LFLAGS += -N $(SOFTINT_PREFIX)/libsoftint.a |
ENDIANESS = LE |