home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Utilities / Partition Logic 0.68 / partlogic-0.68.iso / system / headers / sys / memory.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-10  |  2.7 KB  |  95 lines

  1. // 
  2. //  Visopsys
  3. //  Copyright (C) 1998-2007 J. Andrew McLaughlin
  4. //  
  5. //  This library is free software; you can redistribute it and/or modify it
  6. //  under the terms of the GNU Lesser General Public License as published by
  7. //  the Free Software Foundation; either version 2.1 of the License, or (at
  8. //  your option) any later version.
  9. //
  10. //  This library is distributed in the hope that it will be useful, but
  11. //  WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
  13. //  General Public License for more details.
  14. //
  15. //  You should have received a copy of the GNU Lesser General Public License
  16. //  along with this library; if not, write to the Free Software Foundation,
  17. //  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. //
  19. //  memory.h
  20. //
  21.  
  22. // This file contains definitions and structures for using and manipulating
  23. // memory in Visopsys.
  24.  
  25. #if !defined(_MEMORY_H)
  26.  
  27. #include <sys/debug.h>
  28. #include <sys/errors.h>
  29. #include <sys/lock.h>
  30.  
  31. // Definitions
  32. #define MEMORY_PAGE_SIZE             4096
  33. #define MEMORY_BLOCK_SIZE            MEMORY_PAGE_SIZE
  34. #define MEMORY_MAX_DESC_LENGTH       32
  35.  
  36. #define USER_MEMORY_HEAP_MULTIPLE    (64 * 1024)    // 64 Kb
  37. #define KERNEL_MEMORY_HEAP_MULTIPLE  (1024 * 1024)  // 1 meg
  38.  
  39. typedef struct _mallocBlock {
  40.   int used;
  41.   int process;
  42.   unsigned start;
  43.   unsigned size;
  44.   unsigned heapAlloc;
  45.   struct _mallocBlock *prev;
  46.   struct _mallocBlock *next;
  47.   const char *function;
  48.  
  49. } mallocBlock;
  50.  
  51. // Struct that describes one memory block
  52. typedef struct {
  53.   int processId;
  54.   char description[MEMORY_MAX_DESC_LENGTH];
  55.   unsigned startLocation;
  56.   unsigned endLocation;
  57.  
  58. } memoryBlock;
  59.  
  60. // Struct that describes overall memory statistics
  61. typedef struct {
  62.   unsigned totalBlocks;
  63.   unsigned usedBlocks;
  64.   unsigned totalMemory;
  65.   unsigned usedMemory;
  66.  
  67. } memoryStats;
  68.  
  69. typedef struct {
  70.   int (*multitaskerGetCurrentProcessId) (void);
  71.   void *(*memoryGet) (unsigned, const char *);
  72.   int (*memoryRelease) (void *);
  73.   int (*lockGet) (lock *);
  74.   int (*lockRelease) (lock *);
  75.   void (*debug) (const char *, const char *, int, kernelDebugCategory, 
  76.          const char *, ...) __attribute__((format(printf, 5, 6)));
  77.   void (*error) (const char *, const char *, int, kernelErrorKind, 
  78.          const char *, ...) __attribute__((format(printf, 5, 6)));
  79.  
  80. } mallocKernelOps;
  81.  
  82. // For using malloc() in kernel space
  83. extern unsigned mallocHeapMultiple;
  84. extern mallocKernelOps mallocKernOps;
  85.  
  86. // Extras for malloc debugging
  87. void *_doMalloc(unsigned, const char *);
  88. void _doFree(void *, const char *);
  89. int _mallocBlockInfo(void *, memoryBlock *);
  90. int _mallocGetStats(memoryStats *);
  91. int _mallocGetBlocks(memoryBlock *, int);
  92.  
  93. #define _MEMORY_H
  94. #endif
  95.