source: trunk/src/win32k/k32/k32SetEnvironment.cpp@ 6214

Last change on this file since 6214 was 6214, checked in by bird, 24 years ago

Environment fix. Initial coding.

File size: 3.7 KB
Line 
1/* $Id: k32SetEnvironment.cpp,v 1.1 2001-07-08 02:52:11 bird Exp $
2 *
3 * k32SetEnvironment - Sets the Odin32 environment for a process.
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* Defined Constants And Macros *
14*******************************************************************************/
15#define INCL_DOSERRORS
16#define INCL_OS2KRNL_TK
17#define INCL_OS2KRNL_SEM
18#define INCL_OS2KRNL_LDR
19#define NO_WIN32K_LIB_FUNCTIONS
20
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <os2.h>
26#include "devSegDf.h" /* Win32k segment definitions. */
27#include "OS2Krnl.h"
28#include "win32k.h"
29#include "k32.h"
30#include "options.h"
31#include "dev32.h"
32#include "dev32hlp.h"
33#include "log.h"
34#include "macros.h"
35#include "avl.h"
36#include "PerTaskW32kData.h"
37
38
39
40/**
41 * Set the Odin32 environment pointer for a process.
42 * @returns NO_ERROR on success.
43 * Appropriate error code on failure.
44 * @param pszzEnvironment Pointer to environment block for the process identified by pid.
45 * @param cchEnvironment Size of the environment block.
46 * @param pid Process Id to set environment for.
47 * Currently limited to the current process (if pszzEnvironment != NULL).
48 * @status Completely implemented.
49 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
50 * @remark This is called by the kernel32 initterm proc.
51 * It should be called by any environment replacement later...
52 */
53APIRET k32SetEnvironment(PSZ pszzEnvironment, ULONG cchEnvironment, PID pid)
54{
55 APIRET rc;
56 PPTD pptd;
57
58
59 /*
60 * Validate pid a little bit...
61 */
62 if (pid >= 0x10000)
63 {
64 kprintf(("k32SetEnvironment: invalid pid=%x\n", pid));
65 return ERROR_INVALID_PARAMETER;
66 }
67
68
69 /*
70 * Take Loader semaphore as that currently protects everything in this driver...
71 */
72 rc = LDRRequestSem();
73 if (rc != NO_ERROR)
74 {
75 kprintf(("k32SetEnvironment: LDRRequestSem failed with rc = %d\n", rc));
76 return rc;
77 }
78
79
80 /*
81 * Get Per Task Data and try set next environment pointer.
82 */
83 pptd = GetTaskData(pid);
84 if (pptd)
85 {
86 if (pptd->cUsage != 0 && pptd->pszzOdin32Env)
87 D32Hlp_VMUnLock(&pptd->lockOdin32Env);
88 pptd->pszzOdin32Env = NULL;
89 if (pptd->cUsage != 0 && pszzEnvironment != NULL && cchEnvironment != 0)
90 {
91 /*
92 * Currently we're limited to the current process.
93 */
94 if (pid != 0 || GetTaskData(0) != pptd)
95 {
96 kprintf(("k32SetEnvironment: not current process (pid=%d)\n", pid));
97 LDRClearSem();
98 return ERROR_INVALID_PARAMETER;
99 }
100
101
102 /*
103 * Lock the memory (so we don't block or trap during environment searchs).
104 */
105 rc = D32Hlp_VMLock2(pszzEnvironment, cchEnvironment,
106 VMDHL_LONG | VMDHL_WRITE, &pptd->lockOdin32Env);
107 if (rc == NO_ERROR)
108 pptd->pszzOdin32Env = pszzEnvironment;
109 else
110 {
111 kprintf(("k32SetEnvironment: VMLock2 failed with rc=%d\n", rc));
112 }
113 }
114 else
115 rc = NO_ERROR;
116 }
117 else
118 rc = ERROR_NOT_ENOUGH_MEMORY;
119
120 LDRClearSem();
121 return rc;
122}
123
Note: See TracBrowser for help on using the repository browser.