1 | /* $Id: PerTaskW32kData.c,v 1.1 2001-07-08 03:09:03 bird Exp $
|
---|
2 | *
|
---|
3 | * Per Task (Win32k) Data.
|
---|
4 | *
|
---|
5 | * Copyright (c) 2001 knut st. osmundsen (kosmunds@csc.no)
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 | /*******************************************************************************
|
---|
14 | * Defined Constants And Macros *
|
---|
15 | *******************************************************************************/
|
---|
16 | #define INCL_DOSERRORS /* Error codes */
|
---|
17 | #define INCL_OS2KRNL_VM /* OS2KRNL: Virtual Memory Management */
|
---|
18 | #define INCL_OS2KRNL_TK /* OS2KRNL: Task Stuff */
|
---|
19 |
|
---|
20 | /*******************************************************************************
|
---|
21 | * Header Files *
|
---|
22 | *******************************************************************************/
|
---|
23 | #include <os2.h>
|
---|
24 |
|
---|
25 | #include "devSegDf.h" /* Win32k segment definitions. */
|
---|
26 | #include "dev32.h"
|
---|
27 | #include "dev32hlp.h"
|
---|
28 | #include "log.h"
|
---|
29 | #include "OS2Krnl.h"
|
---|
30 | #include <string.h>
|
---|
31 | #include "macros.h"
|
---|
32 | #include "avl.h"
|
---|
33 | #include "PerTaskW32kData.h"
|
---|
34 | #include "rmalloc.h"
|
---|
35 |
|
---|
36 |
|
---|
37 | /*******************************************************************************
|
---|
38 | * Global Variables *
|
---|
39 | *******************************************************************************/
|
---|
40 | /*static*/ PAVLNODECORE pPTDTree; /* Pointer to PTD tree */
|
---|
41 | /* Currently assumed protected by ldrSem. */
|
---|
42 |
|
---|
43 |
|
---|
44 | /*******************************************************************************
|
---|
45 | * Internal Functions *
|
---|
46 | *******************************************************************************/
|
---|
47 | PID InternalGetPid(void);
|
---|
48 |
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Get the task data structure for a given process id.
|
---|
52 | * If it doesn't exist we'll allocate a new one.
|
---|
53 | * @returns Pointer to task data structure.
|
---|
54 | * @param pid Process id. 0 means current pid.
|
---|
55 | * @status completely implemented.
|
---|
56 | * @author knut st. osmundsen (kosmunds@csc.no)
|
---|
57 | * @remark Do we need a Get function which doesn't make a node if no data was found?
|
---|
58 | */
|
---|
59 | PPTD GetTaskData(PID pid)
|
---|
60 | {
|
---|
61 | PPTD pptd;
|
---|
62 | if (pid == 0)
|
---|
63 | pid = InternalGetPid();
|
---|
64 | pptd = (PPTD)(void*)AVLGet(&pPTDTree, pid);
|
---|
65 | if (!pptd)
|
---|
66 | {
|
---|
67 | pptd = rmalloc(sizeof(*pptd));
|
---|
68 | if (!pptd)
|
---|
69 | {
|
---|
70 | kprintf(("GetTaskData: rmalloc failed!\n"));
|
---|
71 | return NULL;
|
---|
72 | }
|
---|
73 | memset(pptd, 0, sizeof(*pptd));
|
---|
74 | pptd->core.Key = pid;
|
---|
75 | AVLInsert(&pPTDTree, &pptd->core);
|
---|
76 | }
|
---|
77 | return pptd;
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Remove the give process id.
|
---|
83 | * @param pid Process id to remove. 0 means current pid.
|
---|
84 | * @status completely implemented.
|
---|
85 | * @author knut st. osmundsen (kosmunds@csc.no)
|
---|
86 | */
|
---|
87 | void RemoveTaskData(PID pid)
|
---|
88 | {
|
---|
89 | PPTD pptd;
|
---|
90 | if (pid == 0)
|
---|
91 | pid = InternalGetPid();
|
---|
92 | pptd = (PPTD)(void*)AVLRemove(&pPTDTree, pid);
|
---|
93 | if (pptd)
|
---|
94 | {
|
---|
95 | /* perhaps free data here... */
|
---|
96 | rfree(pptd);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Get the current Process Id.
|
---|
103 | * @returns Process id.
|
---|
104 | * -1 on error.
|
---|
105 | * @status completely implemented.
|
---|
106 | * @author knut st. osmundsen (kosmunds@csc.no)
|
---|
107 | * @remark
|
---|
108 | */
|
---|
109 | PID InternalGetPid(void)
|
---|
110 | {
|
---|
111 | struct InfoSegLDT * pLIS;
|
---|
112 | pLIS = (struct InfoSegLDT*)D32Hlp_GetDOSVar(DHGETDOSV_LOCINFOSEG, 0);
|
---|
113 | if (!pLIS)
|
---|
114 | {
|
---|
115 | kprintf(("InternalGetPid: D32Hlp_GetDOSVar(DHGETDOSV_LOCINFOSEG, 0) failed\n"));
|
---|
116 | return (PID)-1;
|
---|
117 | }
|
---|
118 | return pLIS->LIS_CurProcID;
|
---|
119 | }
|
---|
120 |
|
---|