Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1360 → Rev 1363

/uspace/trunk/libc/generic/as.c
69,6 → 69,7
}
 
static size_t heapsize = 0;
static size_t maxheapsize = (size_t)(-1);
/* Start of heap linker symbol */
extern char _heap;
 
91,6 → 92,8
/* 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)
103,3 → 106,11
 
return res;
}
 
void *set_maxheapsize(size_t mhs)
{
maxheapsize=mhs;
/* Return pointer to area not managed by sbrk */
return (void *)&_heap + maxheapsize;
 
}
/uspace/trunk/libc/generic/io/io.c
92,10 → 92,12
return EOF;
}
 
/*
ssize_t write(int fd, const void * buf, size_t count)
{
return (ssize_t) __SYSCALL3(SYS_IO, (sysarg_t) fd, (sysarg_t) buf, (sysarg_t) count);
}
}*/
 
 
 
 
/uspace/trunk/libc/generic/io/stream.c
0,0 → 1,123
#include <io/io.h>
#include <io/stream.h>
#include <string.h>
#include <malloc.h>
#include <libc.h>
#include <ipc/ipc.h>
#include <ipc/ns.h>
#include <ipc/fb.h>
#include <ipc/services.h>
 
#define FDS 32
 
typedef struct stream_t
{
pwritefn_t w;
preadfn_t r;
void * param;
}stream_t;
 
 
typedef struct vfb_descriptor_t
{
int phone;
int vfb;
}vfb_descriptor_t;
 
 
stream_t streams[FDS]={{0,0,0}};
 
/*
ssize_t write_stdout(void *param, const void * buf, size_t count);
ssize_t write_stdout(void *param, const void * buf, size_t count)
{
return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}*/
 
static void vfb_send_char(vfb_descriptor_t *d,char c)
{
ipcarg_t r0,r1;
ipc_call_sync_2(d->phone,FB_PUTCHAR,d->vfb,c,&r0,&r1);
}
static ssize_t write_vfb(void *param, const void * buf, size_t count)
{
int i;
for(i=0;i<count;i++) vfb_send_char((vfb_descriptor_t *)param,((char*)buf)[i]);
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
 
static ssize_t write_stderr(void *param, const void * buf, size_t count)
{
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
 
stream_t open_vfb(void);
stream_t open_vfb(void)
{
stream_t stream;
vfb_descriptor_t *vfb;
int phoneid;
int res;
ipcarg_t vfb_no;
while((phoneid=ipc_connect_me_to(PHONE_NS,SERVICE_VIDEO,0))<0)
{
volatile int a;
for(a=0;a<1048576;a++);
}
ipc_call_sync(phoneid,FB_GET_VFB,0,&vfb_no);
vfb=malloc(sizeof(vfb_descriptor_t));
vfb->phone=phoneid;
vfb->vfb=vfb_no;
stream.w=write_vfb;
stream.param=vfb;
return stream;
}
 
 
fd_t open(const char *fname,int flags)
{
int c=0;
while(((streams[c].w)||(streams[c].r))&&(c<FDS))c++;
if(c==FDS) return EMFILE;
 
 
if(!strcmp(fname,"stdin"))
{
streams[c].r=(preadfn_t)1;
return c;
}
if(!strcmp(fname,"stdout"))
{
//streams[c].w=write_stdout;
//return c;
streams[c]=open_vfb();
return c;
}
if(!strcmp(fname,"stderr"))
{
streams[c].w=write_stderr;
return c;
}
}
 
 
ssize_t write(int fd, const void * buf, size_t count)
{
if(fd<FDS) return streams[fd].w(streams[fd].param,buf,count);
return 0;
}
 
 
/uspace/trunk/libc/generic/libc.c
31,7 → 31,10
#include <thread.h>
#include <malloc.h>
#include <psthread.h>
#include <io/stream.h>
 
int __DONT_OPEN_STDIO__;
 
/* We should probably merge libc and libipc together */
extern void _ipc_init(void);
 
42,6 → 45,13
void __main(void) {
tcb_t *tcb;
if(!__DONT_OPEN_STDIO__)
{
open("stdin",0);
open("stdout",0);
open("stderr",0);
}
tcb = __make_tls();
__tcb_set(tcb);
psthread_setup(tcb);