summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-03 20:41:49 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-03 20:41:49 +0000
commit758d4800642060f50cdf26f7063c9825ea635d15 (patch)
treee689f42a002a2fd57548de0a3eb2aab98fe8f0f0 /nuttx/sched
parentc5ec7c478098273586b7a5716e30dc82c1e6aba5 (diff)
downloadpx4-nuttx-758d4800642060f50cdf26f7063c9825ea635d15.tar.gz
px4-nuttx-758d4800642060f50cdf26f7063c9825ea635d15.tar.bz2
px4-nuttx-758d4800642060f50cdf26f7063c9825ea635d15.zip
Move memory manager into user space
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3460 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/env_dup.c7
-rw-r--r--nuttx/sched/env_dupenv.c9
-rw-r--r--nuttx/sched/env_putenv.c10
-rw-r--r--nuttx/sched/env_setenv.c11
-rw-r--r--nuttx/sched/env_unsetenv.c9
-rw-r--r--nuttx/sched/mq_open.c4
-rw-r--r--nuttx/sched/pthread_create.c6
-rwxr-xr-xnuttx/sched/sched_garbage.c5
-rw-r--r--nuttx/sched/task_create.c8
-rw-r--r--nuttx/sched/timer_create.c13
10 files changed, 48 insertions, 34 deletions
diff --git a/nuttx/sched/env_dup.c b/nuttx/sched/env_dup.c
index 716dcc47c..cbde5251d 100644
--- a/nuttx/sched/env_dup.c
+++ b/nuttx/sched/env_dup.c
@@ -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;
diff --git a/nuttx/sched/env_dupenv.c b/nuttx/sched/env_dupenv.c
index d11e44330..fd3ccd7b7 100644
--- a/nuttx/sched/env_dupenv.c
+++ b/nuttx/sched/env_dupenv.c
@@ -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;
}
diff --git a/nuttx/sched/env_putenv.c b/nuttx/sched/env_putenv.c
index 43ca44d4d..65c3d4c03 100644
--- a/nuttx/sched/env_putenv.c
+++ b/nuttx/sched/env_putenv.c
@@ -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;
}
diff --git a/nuttx/sched/env_setenv.c b/nuttx/sched/env_setenv.c
index 0eacd7793..8193aa564 100644
--- a/nuttx/sched/env_setenv.c
+++ b/nuttx/sched/env_setenv.c
@@ -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;
}
diff --git a/nuttx/sched/env_unsetenv.c b/nuttx/sched/env_unsetenv.c
index f397eab6b..a751661c7 100644
--- a/nuttx/sched/env_unsetenv.c
+++ b/nuttx/sched/env_unsetenv.c
@@ -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;
}
diff --git a/nuttx/sched/mq_open.c b/nuttx/sched/mq_open.c
index 9e3a3e77c..de9388195 100644
--- a/nuttx/sched/mq_open.c
+++ b/nuttx/sched/mq_open.c
@@ -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 */
diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c
index bedb7d3ba..d1f838a9e 100644
--- a/nuttx/sched/pthread_create.c
+++ b/nuttx/sched/pthread_create.c
@@ -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);
diff --git a/nuttx/sched/sched_garbage.c b/nuttx/sched/sched_garbage.c
index 7c9f434a1..946198ede 100755
--- a/nuttx/sched/sched_garbage.c
+++ b/nuttx/sched/sched_garbage.c
@@ -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);
}
}
}
diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c
index d70f337c0..3965e61ef 100644
--- a/nuttx/sched/task_create.c
+++ b/nuttx/sched/task_create.c
@@ -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;
}
diff --git a/nuttx/sched/timer_create.c b/nuttx/sched/timer_create.c
index c4f3cbd87..b1ad142c7 100644
--- a/nuttx/sched/timer_create.c
+++ b/nuttx/sched/timer_create.c
@@ -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;
}