1 | /* $Id: libWin32kSetEnvironment.c,v 1.1 2001-07-08 02:51:24 bird Exp $
|
---|
2 | *
|
---|
3 | * libWin32kSetEnvironment - Set the Odin32 environment block pointer for the
|
---|
4 | * current process.
|
---|
5 | *
|
---|
6 | * Copyright (c) 2001 knut st. osmundsen (kosmunds@csc.no)
|
---|
7 | *
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
9 | *
|
---|
10 | */
|
---|
11 |
|
---|
12 |
|
---|
13 | /*******************************************************************************
|
---|
14 | * Header Files *
|
---|
15 | *******************************************************************************/
|
---|
16 | #define INCL_DOSERRORS
|
---|
17 | #define INCL_DOSFILEMGR
|
---|
18 | #define INCL_DOSDEVICES
|
---|
19 |
|
---|
20 |
|
---|
21 | /*******************************************************************************
|
---|
22 | * Internal Functions *
|
---|
23 | *******************************************************************************/
|
---|
24 | #include <os2.h>
|
---|
25 | #include "win32k.h"
|
---|
26 | #include "libPrivate.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Sets the environment block pointer for a given process.
|
---|
31 | * @returns OS2 returncode.
|
---|
32 | * @param pszzEnvironment Pointer to environment block.
|
---|
33 | * @param cchEnvironment Size of the environment block.
|
---|
34 | * If 0 we'll do a DosQueryMem on the address
|
---|
35 | * to get the size of the memory block.
|
---|
36 | * @param pid Process id.
|
---|
37 | * @status completely implelemented.
|
---|
38 | * @author knut st. osmundsen (kosmunds@csc.no)
|
---|
39 | */
|
---|
40 | APIRET APIENTRY libWin32kSetEnvironment(PSZ pszzEnvironment, ULONG cchEnvironment, PID pid)
|
---|
41 | {
|
---|
42 | APIRET rc;
|
---|
43 |
|
---|
44 | /*
|
---|
45 | * Simple validation.
|
---|
46 | */
|
---|
47 | if ( pszzEnvironment < (PSZ)0x10000
|
---|
48 | || pszzEnvironment >= (PSZ)0xc0000000
|
---|
49 | || cchEnvironment > 1024*1024 /* Max 1MB environment. */
|
---|
50 | || pid >= (PID)0x10000 /* pid range check. */
|
---|
51 | )
|
---|
52 | return ERROR_INVALID_PARAMETER;
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * Query object size if not given.
|
---|
56 | */
|
---|
57 | if (cchEnvironment == 0)
|
---|
58 | {
|
---|
59 | ULONG flFlags = ~0UL;
|
---|
60 | ULONG cb = ~0UL;
|
---|
61 | rc = DosQueryMem(pszzEnvironment, &cb, &flFlags);
|
---|
62 | if (rc || cb <= 0x1000) /* DosQueryMem was broken on some Warp Fixpacks (FP9 for instance). */
|
---|
63 | rc = DosQueryMem(pszzEnvironment, &cb, &flFlags);
|
---|
64 | if (rc)
|
---|
65 | return rc;
|
---|
66 | cchEnvironment = cb;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * Check that we're initiated.
|
---|
71 | */
|
---|
72 | if (fInited)
|
---|
73 | {
|
---|
74 | /*
|
---|
75 | * Build parameters and call win32k.
|
---|
76 | */
|
---|
77 | K32SETENVIRONMENT Param;
|
---|
78 | ULONG cbParam = sizeof(Param);
|
---|
79 | ULONG cbData = 0UL;
|
---|
80 |
|
---|
81 | Param.hdr.cb = sizeof(Param);
|
---|
82 | Param.hdr.rc = ERROR_NOT_SUPPORTED;
|
---|
83 | Param.pszzEnvironment = pszzEnvironment;
|
---|
84 | Param.cchEnvironment = cchEnvironment;
|
---|
85 | Param.pid = pid;
|
---|
86 |
|
---|
87 | if (usCGSelector)
|
---|
88 | return libCallThruCallGate(K32_SETENVIRONMENT, &Param);
|
---|
89 | rc = DosDevIOCtl(hWin32k,
|
---|
90 | IOCTL_W32K_K32,
|
---|
91 | K32_SETENVIRONMENT,
|
---|
92 | &Param, sizeof(Param), &cbParam,
|
---|
93 | "", 1, &cbData);
|
---|
94 |
|
---|
95 | if (rc == NO_ERROR)
|
---|
96 | rc = Param.hdr.rc;
|
---|
97 | }
|
---|
98 | else
|
---|
99 | rc = ERROR_INIT_ROUTINE_FAILED;
|
---|
100 |
|
---|
101 | return rc;
|
---|
102 | }
|
---|
103 |
|
---|