More changes for a kernel-mode allocator (more to be done)

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5724 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2013-03-09 21:12:20 +00:00
parent 43d8762499
commit 1c52dce216
264 changed files with 1277 additions and 1648 deletions
+21 -4
View File
@@ -369,14 +369,31 @@ void up_schedule_sigaction(FAR struct tcb_s *tcb, sig_deliver_t sigdeliver);
* Name: up_allocate_heap
*
* Description:
* The heap may be statically allocated by defining CONFIG_HEAP_BASE and
* CONFIG_HEAP_SIZE. If these are not defined, then this function will be
* called to dynamically set aside the heap region.
* This function will be called to dynamically set aside the heap region.
*
* For the kernel build (CONFIG_NUTTX_KERNEL=y) with both kernel- and
* user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the
* size of the unprotected, user-space heap.
*
* If a protected kernel-space heap is provided, the kernel heap must be
* allocated (and protected) by an analogous up_allocate_kheap().
*
****************************************************************************/
#ifndef CONFIG_HEAP_BASE
void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
/****************************************************************************
* Name: up_allocate_kheap
*
* Description:
* For the kernel build (CONFIG_NUTTX_KERNEL=y) with both kernel- and
* user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates
* (and protects) the kernel-space heap.
*
****************************************************************************/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
void up_allocate_kheap(FAR void **heap_start, size_t *heap_size);
#endif
/****************************************************************************
+56 -5
View File
@@ -47,6 +47,8 @@
#include <nuttx/mm.h>
#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__)
/****************************************************************************
* Public Types
****************************************************************************/
@@ -73,9 +75,43 @@ extern "C"
* be used for both the kernel- and user-mode objects.
*/
/* This familiy of allocators is used to manage user-accessible memory
* from the kernel.
*/
#ifndef CONFIG_NUTTX_KERNEL
# define kmm_initialize(h,s) umm_initialize(h,s)
# define kumm_initialize(h,s) umm_initialize(h,s)
# define kumm_addregion(h,s) umm_addregion(h,s)
# define kumm_trysemaphore() umm_trysemaphore()
# define kumm_givesemaphore() umm_givesemaphore()
# define kumalloc(s) malloc(s)
# define kuzalloc(s) zalloc(s)
# define kurealloc(p,s) realloc(p,s)
# define kufree(p) free(p)
#else
/* This familiy of allocators is used to manage kernel protected memory */
void kumm_initialize(FAR void *heap_start, size_t heap_size);
void kumm_addregion(FAR void *heapstart, size_t heapsize);
int kumm_trysemaphore(void);
void kumm_givesemaphore(void);
FAR void *kumalloc(size_t size);
FAR void *kuzalloc(size_t size);
FAR void *kurealloc(FAR void *oldmem, size_t newsize);
void kufree(FAR void *mem);
#endif
/* This familiy of allocators is used to manage kernel protected memory */
#ifndef CONFIG_NUTTX_KERNEL
# define kmm_initialize(h,s) /* Initialization done by kumm_initialize */
# define kmm_addregion(h,s) umm_addregion(h,s)
# define kmm_trysemaphore() umm_trysemaphore()
# define kmm_givesemaphore() umm_givesemaphore()
@@ -85,6 +121,18 @@ extern "C"
# define krealloc(p,s) realloc(p,s)
# define kfree(p) free(p)
#elif !defined(CONFIG_MM_KERNEL_HEAP)
# define kmm_initialize(h,s) /* Initialization done by kumm_initialize */
# define kmm_addregion(h,s) kumm_addregion(h,s)
# define kmm_trysemaphore() kumm_trysemaphore()
# define kmm_givesemaphore() kumm_givesemaphore()
# define kmalloc(s) kumalloc(s)
# define kzalloc(s) kuzalloc(s)
# define krealloc(p,s) kurealloc(p,s)
# define kfree(p) kufree(p)
#else
void kmm_initialize(FAR void *heap_start, size_t heap_size);
@@ -92,10 +140,12 @@ void kmm_addregion(FAR void *heapstart, size_t heapsize);
int kmm_trysemaphore(void);
void kmm_givesemaphore(void);
FAR void *kmalloc(size_t);
FAR void *kzalloc(size_t);
FAR void *krealloc(FAR void*, size_t);
void kfree(FAR void*);
FAR void *kmalloc(size_t size);
FAR void *kzalloc(size_t size);
FAR void *krealloc(FAR void *oldmem, size_t newsize);
void kfree(FAR void *mem);
bool kmm_heapmember(FAR void *mem);
#endif
@@ -124,4 +174,5 @@ void sched_garbagecollection(void);
}
#endif
#endif /* !CONFIG_NUTTX_KERNEL || __KERNEL__ */
#endif /* __INCLUDE_NUTTX_KMALLOC_H */
+43 -42
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* include/stdio.h
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -88,65 +88,66 @@ typedef struct file_struct FILE;
* Public Variables
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* ANSI-like File System Interfaces */
/* Operations on streams (FILE) */
EXTERN void clearerr(register FILE *stream);
EXTERN int fclose(FAR FILE *stream);
EXTERN int fflush(FAR FILE *stream);
EXTERN int feof(FAR FILE *stream);
EXTERN int ferror(FAR FILE *stream);
EXTERN int fileno(FAR FILE *stream);
EXTERN int fgetc(FAR FILE *stream);
EXTERN int fgetpos(FAR FILE *stream, FAR fpos_t *pos);
EXTERN char *fgets(FAR char *s, int n, FAR FILE *stream);
EXTERN FAR FILE *fopen(FAR const char *path, FAR const char *type);
EXTERN int fprintf(FAR FILE *stream, FAR const char *format, ...);
EXTERN int fputc(int c, FAR FILE *stream);
EXTERN int fputs(FAR const char *s, FAR FILE *stream);
EXTERN size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream);
EXTERN int fseek(FAR FILE *stream, long int offset, int whence);
EXTERN int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
EXTERN long ftell(FAR FILE *stream);
EXTERN size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream);
EXTERN FAR char *gets(FAR char *s);
EXTERN int ungetc(int c, FAR FILE *stream);
void clearerr(register FILE *stream);
int fclose(FAR FILE *stream);
int fflush(FAR FILE *stream);
int feof(FAR FILE *stream);
int ferror(FAR FILE *stream);
int fileno(FAR FILE *stream);
int fgetc(FAR FILE *stream);
int fgetpos(FAR FILE *stream, FAR fpos_t *pos);
char *fgets(FAR char *s, int n, FAR FILE *stream);
FAR FILE *fopen(FAR const char *path, FAR const char *type);
int fprintf(FAR FILE *stream, FAR const char *format, ...);
int fputc(int c, FAR FILE *stream);
int fputs(FAR const char *s, FAR FILE *stream);
size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream);
int fseek(FAR FILE *stream, long int offset, int whence);
int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
long ftell(FAR FILE *stream);
size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream);
FAR char *gets(FAR char *s);
int ungetc(int c, FAR FILE *stream);
/* Operations on the stdout stream, buffers, paths, and the whole printf-family */
EXTERN int printf(const char *format, ...);
EXTERN int puts(FAR const char *s);
EXTERN int rename(FAR const char *oldpath, FAR const char *newpath);
EXTERN int sprintf(FAR char *buf, const char *format, ...);
EXTERN int asprintf (FAR char **ptr, const char *fmt, ...);
EXTERN int snprintf(FAR char *buf, size_t size, const char *format, ...);
EXTERN int sscanf(const char *buf, const char *fmt, ...);
EXTERN void perror(FAR const char *s);
int printf(const char *format, ...);
int puts(FAR const char *s);
int rename(FAR const char *oldpath, FAR const char *newpath);
int sprintf(FAR char *buf, const char *format, ...);
int asprintf (FAR char **ptr, const char *fmt, ...);
int snprintf(FAR char *buf, size_t size, const char *format, ...);
int sscanf(const char *buf, const char *fmt, ...);
void perror(FAR const char *s);
EXTERN int vprintf(FAR const char *format, va_list ap);
EXTERN int vfprintf(FAR FILE *stream, const char *format, va_list ap);
EXTERN int vsprintf(FAR char *buf, const char *format, va_list ap);
EXTERN int avsprintf(FAR char **ptr, const char *fmt, va_list ap);
EXTERN int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap);
EXTERN int vsscanf(char *buf, const char *s, va_list ap);
int vprintf(FAR const char *format, va_list ap);
int vfprintf(FAR FILE *stream, const char *format, va_list ap);
int vsprintf(FAR char *buf, const char *format, va_list ap);
int avsprintf(FAR char **ptr, const char *fmt, va_list ap);
int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap);
int vsscanf(char *buf, const char *s, va_list ap);
/* POSIX-like File System Interfaces */
EXTERN FAR FILE *fdopen(int fd, FAR const char *type);
EXTERN int statfs(FAR const char *path, FAR struct statfs *buf);
FAR FILE *fdopen(int fd, FAR const char *type);
int statfs(FAR const char *path, FAR struct statfs *buf);
#undef EXTERN
#if defined(__cplusplus)