Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1500 → Rev 1501

//uspace/trunk/libc/include/align.h
42,6 → 42,6
* @param s Address or size to be aligned.
* @param a Size of alignment, must be power of 2.
*/
#define ALIGN_UP(s, a) (((s) + ((a) - 1)) & ~((a) - 1))
#define ALIGN_UP(s, a) ((long)((s) + ((a) - 1)) & ~((long) (a) - 1))
 
#endif
//uspace/trunk/libc/include/as.h
40,5 → 40,6
extern int as_area_resize(void *address, size_t size, int flags);
extern int as_area_destroy(void *address);
extern void *set_maxheapsize(size_t mhs);
extern void * as_get_mappable_page(size_t sz);
 
#endif
//uspace/trunk/libc/generic/time.c
56,7 → 56,6
* useconds again. This provides assurance, that at least the
* sequence of subsequent gettimeofday calls is ordered.
*/
#define TMAREA (100*1024*1024)
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
void *mapping;
65,12 → 64,10
int res;
 
if (!ktime) {
/* TODO: specify better, where to map the area */
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,
TMAREA,
PAGE_SIZE,
0,
mapping, PAGE_SIZE, 0,
NULL,&rights,NULL);
if (res) {
printf("Failed to initialize timeofday memarea\n");
79,10 → 76,10
if (rights != (AS_AREA_READ | AS_AREA_CACHEABLE)) {
printf("Received bad rights on time area: %X\n",
rights);
as_area_destroy(TMAREA);
as_area_destroy(mapping);
_exit(1);
}
ktime = (void *) (TMAREA);
ktime = mapping;
}
if (tz) {
tz->tz_minuteswest = 0;
//uspace/trunk/libc/generic/as.c
26,10 → 26,24
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ddi.h>
#include <sysinfo.h>
#include <align.h>
#include <as.h>
#include <ipc/fb.h>
#include <ipc/ipc.h>
#include <ipc/ns.h>
#include <ipc/services.h>
#include <kernel/errno.h>
 
 
#include <as.h>
#include <libc.h>
#include <unistd.h>
#include <task.h>
#include <align.h>
 
/** Create address space area.
*
70,6 → 84,9
 
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;
 
107,6 → 124,7
return res;
}
 
/** Set maximum heap size and return pointer just after the heap */
void *set_maxheapsize(size_t mhs)
{
maxheapsize=mhs;
114,3 → 132,25
return (void *)&_heap + maxheapsize;
 
}
 
/** Return pointer to some unmapped area, where fits new as_area
*
* TODO: make some first_fit/... algorithm, we are now just incrementing
* the pointer to last area
*/
void * as_get_mappable_page(size_t sz)
{
void *res;
 
/* 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);
sz = ALIGN_UP(sz, PAGE_SIZE);
res = last_allocated;
last_allocated += sz;
 
return res;
}