9
0
Fork 0

Move memory manager into user space

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3460 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2011-04-03 20:41:49 +00:00
parent 0fe79fa1bf
commit 5fb8eb530a
20 changed files with 90 additions and 64 deletions

View File

@ -106,7 +106,7 @@ endif
# USERDIRS - When NuttX is build is a monolithic kernel, this provides the
# list of directories that must be built
NONFSDIRS = sched $(ARCH_SRC) mm $(NUTTX_ADDONS)
NONFSDIRS = sched $(ARCH_SRC) $(NUTTX_ADDONS)
FSDIRS = fs drivers binfmt
NETFSDIRS = fs drivers
CONTEXTDIRS = $(APPDIR)
@ -115,9 +115,9 @@ USERDIRS =
ifeq ($(CONFIG_NUTTX_KERNEL),y)
NONFSDIRS += syscall
CONTEXTDIRS += syscall
USERDIRS += syscall lib $(USER_ADDONS)
USERDIRS += syscall lib mm $(USER_ADDONS)
else
NONFSDIRS += lib
NONFSDIRS += lib mm
endif
ifeq ($(CONFIG_NX),y)
@ -175,16 +175,18 @@ endif
# USERLIBS is the list of libraries used to build the final user-space
# application
NUTTXLIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT) mm/libmm$(LIBEXT) \
lib/liblib$(LIBEXT)
NUTTXLIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT) lib/liblib$(LIBEXT)
USERLIBS =
# Add libraries for syscall support. The C library will be needed by
# both the kernel- and user-space builds.
# both the kernel- and user-space builds. For now, the memory manager (mm)
# is placed in user space (only).
ifeq ($(CONFIG_NUTTX_KERNEL),y)
NUTTXLIBS += syscall/libstubs$(LIBEXT)
USERLIBS += syscall/libproxies$(LIBEXT) lib/liblib$(LIBEXT)
USERLIBS += syscall/libproxies$(LIBEXT) lib/liblib$(LIBEXT) mm/libmm$(LIBEXT)
else
NUTTXLIBS += mm/libmm$(LIBEXT)
endif
# Add libraries for network support. CXX, CXXFLAGS, and COMPILEXX must
@ -332,11 +334,6 @@ graphics/libgraphics$(LIBEXT): context
syscall/libstubs$(LIBEXT): context
@$(MAKE) -C syscall TOPDIR="$(TOPDIR)" libstubs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
# Still need to think about this one
mm/libmm$(LIBEXT): context
@$(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT)
# Possible user-mode builds
lib/liblib$(LIBEXT): context
@ -345,6 +342,9 @@ lib/liblib$(LIBEXT): context
libxx/liblibxx$(LIBEXT): context
@$(MAKE) -C libxx TOPDIR="$(TOPDIR)" liblibxx$(LIBEXT)
mm/libmm$(LIBEXT): context
@$(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
$(APPDIR)/libapps$(LIBEXT): context
@$(MAKE) -C $(APPDIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT)

View File

@ -94,7 +94,7 @@ int up_create_stack(_TCB *tcb, size_t stack_size)
if (!tcb->stack_alloc_ptr)
{
tcb->stack_alloc_ptr = (uint32_t*)kzmalloc(stack_size);
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
}
if (tcb->stack_alloc_ptr)

View File

@ -95,7 +95,7 @@ int up_create_stack(_TCB *tcb, size_t stack_size)
if (!tcb->stack_alloc_ptr)
{
tcb->stack_alloc_ptr = (uint32_t*)kzmalloc(stack_size);
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
}
if (tcb->stack_alloc_ptr)

View File

@ -93,7 +93,7 @@ int up_create_stack(_TCB *tcb, size_t stack_size)
if (!tcb->stack_alloc_ptr)
{
tcb->stack_alloc_ptr = (uint32_t*)kzmalloc(stack_size);
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
}
if (tcb->stack_alloc_ptr)

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
###########################################################################
# configs/ea3131/locked/mklocked.sh
#

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_files.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -45,6 +45,7 @@
#include <assert.h>
#include <sched.h>
#include <errno.h>
#include <nuttx/fs.h>
#include <nuttx/kmalloc.h>
@ -157,7 +158,7 @@ void files_initialize(void)
FAR struct filelist *files_alloclist(void)
{
FAR struct filelist *list;
list = (FAR struct filelist*)kzmalloc(sizeof(struct filelist));
list = (FAR struct filelist*)kzalloc(sizeof(struct filelist));
if (list)
{
/* Start with a reference count of one */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/kmalloc.h
*
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -63,21 +63,28 @@ extern "C" {
# include <stdlib.h>
# define kmalloc(s) malloc(s)
#else
KMALLOC_EXTERN FAR void *kmalloc(size_t);
KMALLOC_EXTERN FAR void *kmalloc(size_t);
#endif
#ifndef CONFIG_ARCH_KZMALLOC
#ifndef CONFIG_ARCH_KZALLOC
# include <stdlib.h>
# define kzmalloc(s) zalloc(s)
# define kzalloc(s) zalloc(s)
#else
KMALLOC_EXTERN FAR void *kzalloc(size_t);
KMALLOC_EXTERN FAR void *kzalloc(size_t);
#endif
#ifndef CONFIG_ARCH_KREALLOC
# include <stdlib.h>
# define krealloc(p,s) realloc(p,s)
#else
KMALLOC_EXTERN FAR void *krealloc(FAR void*, size_t);
#endif
#ifndef CONFIG_ARCH_KFREE
# include <stdlib.h>
# define kfree(p) free(p)
#else
KMALLOC_EXTERN void kfree(FAR void*);
KMALLOC_EXTERN void kfree(FAR void*);
#endif
/* Functions defined in os_list.c *******************************************/

View File

@ -1,7 +1,7 @@
/************************************************************
* lib_init.c
* lib/misc/lib_init.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -37,12 +37,16 @@
* Included Files
************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
#include <nuttx/lib.h>
#include "lib_internal.h"
/************************************************************
@ -79,7 +83,7 @@ void weak_const_function lib_initialize(void)
FAR struct streamlist *lib_alloclist(void)
{
FAR struct streamlist *list;
list = (FAR struct streamlist*)kzmalloc(sizeof(struct streamlist));
list = (FAR struct streamlist*)zalloc(sizeof(struct streamlist));
if (list)
{
int i;

View File

@ -114,7 +114,7 @@ extern void mm_addregion(FAR void *heapstart, size_t heapsize);
# define mvdbg(format, arg...) printf(format, ##arg)
#else
# define mm_errno (*get_errno_ptr())
# define mm_errno get_errno()
#endif
/****************************************************************************

View File

@ -121,7 +121,7 @@ void net_initialize(void)
FAR struct socketlist *net_alloclist(void)
{
FAR struct socketlist *list;
list = (FAR struct socketlist*)kzmalloc(sizeof(struct socketlist));
list = (FAR struct socketlist*)kzalloc(sizeof(struct socketlist));
if (list)
{
/* Start with a reference count of one */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/env_dup.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -45,6 +45,9 @@
#include <sched.h>
#include <string.h>
#include <errno.h>
#include <nuttx/kmalloc.h>
#include "os_internal.h"
#include "env_internal.h"
@ -101,7 +104,7 @@ int env_dup(FAR _TCB *ptcb)
/* Yes..The parent task has an environment, duplicate it */
size_t envlen = parent->envp->ev_alloc;
envp = (environ_t*)malloc(SIZEOF_ENVIRON_T( envlen ));
envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T( envlen ));
if (!envp)
{
ret = -ENOMEM;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* eched/env_dupenv.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -43,7 +43,9 @@
#include <sys/types.h>
#include <sched.h>
#include <stdlib.h>
#include <nuttx/kmalloc.h>
#include "os_internal.h"
/****************************************************************************
@ -91,7 +93,7 @@ FAR environ_t *dupenv(FAR _TCB *ptcb)
/* Yes..The parent task has an environment, duplicate it */
size_t envlen = ptcb->envp->ev_alloc
envp = (environ_t*)malloc(SIZEOF_ENVIRON_T( envlen ));
envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T( envlen ));
if (envp)
{
envp->ev_crefs = 1;
@ -99,6 +101,7 @@ FAR environ_t *dupenv(FAR _TCB *ptcb)
memcmp( envp->ev_env, ptcb->envp->ev_env, envlen );
}
}
sched_unlock();
return envp;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/env_putenv.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -43,9 +43,10 @@
#include <sched.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <nuttx/kmalloc.h>
/****************************************************************************
* Private Data
****************************************************************************/
@ -106,11 +107,12 @@ int putenv(FAR const char *string)
*pequal = '\0';
ret = setenv(pname, pequal+1, TRUE);
}
free(pname);
kfree(pname);
return ret;
errout:
*get_errno_ptr() = ret;
errno = ret;
return ERROR;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/env_setenv.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -44,9 +44,10 @@
#include <stdio.h>
#include <sched.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <nuttx/kmalloc.h>
#include "os_internal.h"
#include "env_internal.h"
@ -156,7 +157,7 @@ int setenv(const char *name, const char *value, int overwrite)
if (envp)
{
int alloc = envp->ev_alloc;
environ_t *tmp = (environ_t*)realloc(envp, SIZEOF_ENVIRON_T(alloc + varlen));
environ_t *tmp = (environ_t*)krealloc(envp, SIZEOF_ENVIRON_T(alloc + varlen));
if (!tmp)
{
ret = ENOMEM;
@ -169,7 +170,7 @@ int setenv(const char *name, const char *value, int overwrite)
}
else
{
envp = (environ_t*)malloc(SIZEOF_ENVIRON_T(varlen));
envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T(varlen));
if (!envp)
{
ret = ENOMEM;
@ -196,7 +197,7 @@ int setenv(const char *name, const char *value, int overwrite)
errout_with_lock:
sched_unlock();
errout:
*get_errno_ptr() = ret;
errno = ret;
return ERROR;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/env_unsetenv.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -43,9 +43,10 @@
#include <sched.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <nuttx/kmalloc.h>
#include "os_internal.h"
#include "env_internal.h"
@ -109,7 +110,7 @@ int unsetenv(const char *name)
/* Reallocate the new environment buffer */
alloc = envp->ev_alloc;
tmp = (environ_t*)realloc(envp, SIZEOF_ENVIRON_T(alloc));
tmp = (environ_t*)krealloc(envp, SIZEOF_ENVIRON_T(alloc));
if (!tmp)
{
ret = ENOMEM;
@ -127,7 +128,7 @@ int unsetenv(const char *name)
errout_with_lock:
sched_unlock();
errout:
*get_errno_ptr() = ret;
errno = ret;
return ERROR;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/mq_open.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -157,7 +157,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
* of the message queue name+1.
*/
msgq = (FAR msgq_t*)kzmalloc(SIZEOF_MQ_HEADER + namelen + 1);
msgq = (FAR msgq_t*)kzalloc(SIZEOF_MQ_HEADER + namelen + 1);
if (msgq)
{
/* Create a message queue descriptor for the TCB */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/pthread_create.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -262,7 +262,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Allocate a TCB for the new task. */
ptcb = (FAR _TCB*)kzmalloc(sizeof(_TCB));
ptcb = (FAR _TCB*)kzalloc(sizeof(_TCB));
if (!ptcb)
{
return ENOMEM;
@ -283,7 +283,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Allocate a detachable structure to support pthread_join logic */
pjoin = (FAR join_t*)kzmalloc(sizeof(join_t));
pjoin = (FAR join_t*)kzalloc(sizeof(join_t));
if (!pjoin)
{
sched_releasetcb(ptcb);

View File

@ -38,8 +38,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <nuttx/kmalloc.h>
#include "os_internal.h"
@ -111,7 +110,7 @@ void sched_garbagecollection(void)
if (address)
{
free(address);
kfree(address);
}
}
}

View File

@ -38,11 +38,15 @@
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sched.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include "os_internal.h"
#include "env_internal.h"
@ -121,10 +125,10 @@ int task_create(const char *name, int priority,
/* Allocate a TCB for the new task. */
tcb = (FAR _TCB*)kzmalloc(sizeof(_TCB));
tcb = (FAR _TCB*)kzalloc(sizeof(_TCB));
if (!tcb)
{
*get_errno_ptr() = ENOMEM;
errno = ENOMEM;
return ERROR;
}

View File

@ -1,7 +1,7 @@
/********************************************************************************
* sched/timer_create.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -40,13 +40,14 @@
#include <nuttx/config.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <wdog.h>
#include <errno.h>
#include <nuttx/kmalloc.h>
#include "timer_internal.h"
#ifndef CONFIG_DISABLE_POSIX_TIMERS
@ -99,7 +100,7 @@ static struct posix_timer_s *timer_allocate(void)
{
/* Allocate a new timer from the heap */
ret = (struct posix_timer_s*)malloc(sizeof(struct posix_timer_s));
ret = (struct posix_timer_s*)kmalloc(sizeof(struct posix_timer_s));
pt_flags = 0;
}
@ -183,7 +184,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer
if (!timerid || clockid != CLOCK_REALTIME)
{
*get_errno_ptr() = EINVAL;
errno = EINVAL;
return ERROR;
}
@ -192,7 +193,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer
wdog = wd_create();
if (!wdog)
{
*get_errno_ptr() = EAGAIN;
errno = EAGAIN;
return ERROR;
}
@ -201,7 +202,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer
ret = timer_allocate();
if (!ret)
{
*get_errno_ptr() = EAGAIN;
errno = EAGAIN;
return ERROR;
}