ReactOS  0.4.14-dev-998-g623dd26
dllmain.c File Reference
#include "precomp.h"
Include dependency graph for dllmain.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msvcrt)
 
int BlockEnvToEnvironA (void)
 
int BlockEnvToEnvironW (void)
 
void FreeEnvironment (char **environment)
 
BOOL WINAPI DllMain (PVOID hinstDll, ULONG dwReason, PVOID reserved)
 

Variables

unsigned int _osplatform
 
unsigned int _osver
 
unsigned int _winminor
 
unsigned int _winmajor
 
unsigned int _winver
 
char_acmdln
 
wchar_t_wcmdln
 
char ** _environ
 
char ** __initenv
 
wchar_t ** _wenviron
 
wchar_t ** __winitenv
 

Function Documentation

◆ BlockEnvToEnvironA()

int BlockEnvToEnvironA ( void  )

Definition at line 34 of file environ.c.

35 {
36  char *ptr, *environment_strings;
37  char **envptr;
38  int count = 1;
39  size_t len;
40 
41  TRACE("BlockEnvToEnvironA()\n");
42 
43  environment_strings = GetEnvironmentStringsA();
44  if (environment_strings == NULL) {
45  return -1;
46  }
47 
48  for (ptr = environment_strings; *ptr; ptr += len)
49  {
50  len = strlen(ptr) + 1;
51  /* Skip drive letter settings. */
52  if (*ptr != '=')
53  count++;
54  }
55 
56  __initenv = _environ = malloc(count * sizeof(char*));
57  if (_environ)
58  {
59  for (ptr = environment_strings, envptr = _environ; count > 1; ptr += len)
60  {
61  len = strlen(ptr) + 1;
62  /* Skip drive letter settings. */
63  if (*ptr != '=')
64  {
65  if ((*envptr = malloc(len)) == NULL)
66  {
67  for (envptr--; envptr >= _environ; envptr--)
68  free(*envptr);
69  FreeEnvironmentStringsA(environment_strings);
70  free(_environ);
72  return -1;
73  }
74  memcpy(*envptr++, ptr, len);
75  count--;
76  }
77  }
78  /* Add terminating NULL entry. */
79  *envptr = NULL;
80  }
81 
82  FreeEnvironmentStringsA(environment_strings);
83  return _environ ? 0 : -1;
84 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define free
Definition: debug_ros.c:5
BOOL WINAPI FreeEnvironmentStringsA(IN LPSTR EnvironmentStrings)
Definition: environ.c:379
char ** _environ
Definition: environ.c:22
char ** __initenv
Definition: environ.c:24
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
LPSTR WINAPI GetEnvironmentStringsA(VOID)
Definition: environ.c:293
#define malloc
Definition: debug_ros.c:4

◆ BlockEnvToEnvironW()

int BlockEnvToEnvironW ( void  )

Definition at line 86 of file environ.c.

87 {
88  wchar_t *ptr, *environment_strings;
89  wchar_t **envptr;
90  int count = 1;
91  size_t len;
92 
93  TRACE("BlockEnvToEnvironW()\n");
94 
95  environment_strings = GetEnvironmentStringsW();
96  if (environment_strings == NULL) {
97  return -1;
98  }
99 
100  for (ptr = environment_strings; *ptr; ptr += len)
101  {
102  len = wcslen(ptr) + 1;
103  /* Skip drive letter settings. */
104  if (*ptr != '=')
105  count++;
106  }
107 
108  __winitenv = _wenviron = malloc(count * sizeof(wchar_t*));
109  if (_wenviron)
110  {
111  for (ptr = environment_strings, envptr = _wenviron; count > 1; ptr += len)
112  {
113  len = wcslen(ptr) + 1;
114  /* Skip drive letter settings. */
115  if (*ptr != '=')
116  {
117  if ((*envptr = malloc(len * sizeof(wchar_t))) == NULL)
118  {
119  for (envptr--; envptr >= _wenviron; envptr--)
120  free(*envptr);
121  FreeEnvironmentStringsW(environment_strings);
122  free(_wenviron);
124  return -1;
125  }
126  memcpy(*envptr++, ptr, len * sizeof(wchar_t));
127  count--;
128  }
129  }
130  /* Add terminating NULL entry. */
131  *envptr = NULL;
132  }
133 
134  FreeEnvironmentStringsW(environment_strings);
135  return _wenviron ? 0 : -1;
136 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define free
Definition: debug_ros.c:5
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
wchar_t ** _wenviron
Definition: environ.c:23
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
Definition: environ.c:389
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
LPWSTR WINAPI GetEnvironmentStringsW(VOID)
Definition: environ.c:344
wchar_t ** __winitenv
Definition: environ.c:25
#define malloc
Definition: debug_ros.c:4
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ DllMain()

BOOL WINAPI DllMain ( PVOID  hinstDll,
ULONG  dwReason,
PVOID  reserved 
)

Definition at line 46 of file dllmain.c.

47 {
49  switch (dwReason)
50  {
51  case DLL_PROCESS_ATTACH:
52  /* initialize version info */
53  TRACE("Process Attach\n");
55  GetVersionExW( &osvi );
61 
62  /* create tls stuff */
63  if (!msvcrt_init_tls())
64  return FALSE;
65 
66  if (BlockEnvToEnvironA() < 0)
67  return FALSE;
68 
69  if (BlockEnvToEnvironW() < 0)
70  {
72  return FALSE;
73  }
74 
77 
78  /* Initialization of the WINE code */
80  //msvcrt_init_math();
82  //msvcrt_init_console();
83  //msvcrt_init_args();
84  //msvcrt_init_signals();
85  TRACE("Attach done\n");
86  break;
87 
88  case DLL_THREAD_ATTACH:
89  //msvcrt_get_thread_data creates data when first called
90  break;
91 
92  case DLL_THREAD_DETACH:
94  break;
95 
96  case DLL_PROCESS_DETACH:
97  TRACE("Detach\n");
98  /* Deinit of the WINE code */
100  if (reserved) break;
103  //msvcrt_free_console();
104  //msvcrt_free_args();
105  //msvcrt_free_signals();
107  if (!msvcrt_free_tls())
108  return FALSE;
109  if(global_locale)
111 
112  if (__winitenv && __winitenv != _wenviron)
113  FreeEnvironment((char**)__winitenv);
114  if (_wenviron)
115  FreeEnvironment((char**)_wenviron);
116 
117  if (__initenv && __initenv != _environ)
119  if (_environ)
121 
122  TRACE("Detach done\n");
123  break;
124  }
125 
126  return TRUE;
127 }
#define TRUE
Definition: types.h:120
ULONG dwMajorVersion
Definition: rtltypes.h:234
void msvcrt_free_io(void)
Definition: file.c:1100
wchar_t ** _wenviron
Definition: environ.c:23
OSVERSIONINFO osvi
Definition: ver.c:28
#define DLL_THREAD_ATTACH
Definition: compat.h:121
void msvcrt_free_tls_mem(void)
Definition: tls.c:51
unsigned int _osplatform
Definition: environ.c:10
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
void msvcrt_init_io(void)
Definition: file.c:457
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
#define _strdup
Definition: debug_ros.c:7
#define DLL_THREAD_DETACH
Definition: compat.h:122
unsigned int _winminor
Definition: environ.c:12
wchar_t ** __winitenv
Definition: environ.c:25
void msvcrt_free_popen_data(void)
Definition: popen.c:29
BOOL msvcrt_free_tls(void)
Definition: tls.c:21
DWORD dwReason
Definition: misc.cpp:154
char ** _environ
Definition: environ.c:22
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
r reserved
Definition: btrfs.c:2865
char * _acmdln
Definition: environ.c:18
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:233
unsigned int _osver
Definition: environ.c:11
#define DLL_PROCESS_DETACH
Definition: compat.h:119
ULONG dwBuildNumber
Definition: rtltypes.h:236
void msvcrt_free_mt_locks(void)
Definition: lock.c:77
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int _winmajor
Definition: environ.c:13
if(!(yy_init))
Definition: macro.lex.yy.c:714
BOOL msvcrt_init_tls(void)
Definition: tls.c:9
unsigned int _winver
Definition: environ.c:14
struct _OSVERSIONINFOW OSVERSIONINFOW
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2003
MSVCRT__locale_t global_locale
Definition: locale.c:1495
char ** __initenv
Definition: environ.c:24
ULONG dwMinorVersion
Definition: rtltypes.h:235
wchar_t * _wcmdln
Definition: environ.c:19
void FreeEnvironment(char **environment)
Definition: environ.c:190
ULONG dwPlatformId
Definition: rtltypes.h:237
int BlockEnvToEnvironW(void)
Definition: environ.c:86
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t)
Definition: locale.c:711
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
int BlockEnvToEnvironA(void)
Definition: environ.c:34
void msvcrt_init_mt_locks(void)
Definition: lock.c:54

◆ FreeEnvironment()

void FreeEnvironment ( char **  environment)

Internal function to deallocate environment block. Although it's parameter are defined as char**, it's able to work also with wide character environment block which are of type wchar_t**.

Parameters
environmentEnvironment to free.

Definition at line 190 of file environ.c.

191 {
192  char **envptr;
193  for (envptr = environment; *envptr != NULL; envptr++)
194  free(*envptr);
195  free(environment);
196 }
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msvcrt  )

Variable Documentation

◆ __initenv

char** __initenv

Definition at line 24 of file environ.c.

◆ __winitenv

wchar_t** __winitenv

Definition at line 25 of file environ.c.

◆ _acmdln

char* _acmdln

Definition at line 18 of file environ.c.

◆ _environ

char** _environ

Definition at line 22 of file environ.c.

◆ _osplatform

unsigned int _osplatform

Definition at line 10 of file environ.c.

Referenced by DllMain().

◆ _osver

unsigned int _osver

Definition at line 11 of file environ.c.

◆ _wcmdln

wchar_t* _wcmdln

Definition at line 19 of file environ.c.

◆ _wenviron

wchar_t** _wenviron

Definition at line 23 of file environ.c.

◆ _winmajor

unsigned int _winmajor

Definition at line 13 of file environ.c.

◆ _winminor

unsigned int _winminor

Definition at line 12 of file environ.c.

◆ _winver

unsigned int _winver

Definition at line 14 of file environ.c.