comparison src/gpf/osl/os_mem_ir.c @ 6:8b2a9a374324

src/gpf: addition of Magnetite src/gpf2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 08:15:49 +0000
parents
children 82ae724ca0d7
comparison
equal deleted inserted replaced
5:1ea54a97e831 6:8b2a9a374324
1 /*
2 * This C module is a reconstruction based on the disassembly of
3 * os_mem.obj in frame_na7_db_ir.lib from the Leonardo package.
4 */
5
6 /* set of included headers from COFF symtab: */
7 #include <stdio.h>
8 #include <string.h>
9 #include "nucleus.h"
10 #include "typedefs.h"
11 #include "os.h"
12 #include "gdi.h"
13 #include "os_types.h"
14 #include "os_glob.h"
15
16 extern T_OS_PART_GRP_TABLE_ENTRY PartGrpTable[];
17 extern T_OS_POOL_BORDER PoolBorder[];
18
19 GLOBAL LONG
20 os_is_valid_partition(T_VOID_STRUCT *Buffer)
21 {
22 int i;
23
24 for (i = 0; i <= MaxPoolGroups; i++) {
25 if (PoolBorder[i].End == 0)
26 return(OS_ERROR);
27 if ((char *)Buffer < PoolBorder[i].Start)
28 continue;
29 if ((char *)Buffer >= PoolBorder[i].End)
30 continue;
31 return(OS_OK);
32 }
33 return(OS_ERROR);
34 }
35
36 GLOBAL LONG
37 os_PartitionCheck(ULONG *ptr)
38 {
39 PM_HEADER *phdr;
40 PM_PCB *pool;
41
42 phdr = (PM_HEADER *)(ptr - 2);
43 if (phdr->pm_next_available)
44 return(OS_PARTITION_FREE);
45 pool = phdr->pm_partition_pool;
46 if (ptr[(pool->pm_partition_size - 4) >> 2] == GUARD_PATTERN)
47 return(OS_OK);
48 else
49 return(OS_PARTITION_GUARD_PATTERN_DESTROYED);
50 }
51
52 GLOBAL LONG
53 os_DeallocatePartition(OS_HANDLE TaskHandle, T_VOID_STRUCT *Buffer)
54 {
55 if (os_is_valid_partition(Buffer) != OS_OK)
56 return(OS_ERROR);
57 if (NU_Deallocate_Partition(Buffer) != NU_SUCCESS)
58 return(OS_ERROR);
59 return(OS_OK);
60 }
61
62 GLOBAL LONG
63 os_AllocatePartition(OS_HANDLE TaskHandle, T_VOID_STRUCT **Buffer, ULONG Size,
64 ULONG Suspend, OS_HANDLE GroupHandle)
65 {
66 T_OS_PART_POOL *pool, *requested_pool;
67 ULONG nu_suspend;
68 STATUS sts;
69 int ret;
70
71 for (pool = PartGrpTable[GroupHandle].grp_head; pool;
72 pool = pool->next)
73 if (Size <= pool->size)
74 break;
75 if (!pool)
76 return(OS_ERROR);
77 requested_pool = pool;
78 ret = OS_OK;
79 nu_suspend = NU_NO_SUSPEND;
80 try_alloc:
81 sts = NU_Allocate_Partition(&pool->pcb, (VOID **) Buffer, nu_suspend);
82 switch (sts) {
83 case NU_SUCCESS:
84 return(ret);
85 case NU_TIMEOUT:
86 case NU_INVALID_SUSPEND:
87 *Buffer = 0;
88 return(OS_TIMEOUT);
89 case NU_NO_PARTITION:
90 pool = pool->next;
91 if (pool) {
92 ret = OS_ALLOCATED_BIGGER;
93 goto try_alloc;
94 }
95 pool = requested_pool;
96 if (Suspend) {
97 nu_suspend = Suspend;
98 ret = OS_WAITED;
99 goto try_alloc;
100 }
101 return(OS_TIMEOUT);
102 default:
103 *Buffer = 0;
104 return(OS_ERROR);
105 }
106 }