ReactOS 0.4.16-dev-2122-g1628f5e
dllmain.c File Reference
#include "precomp.h"
#include <mbctype.h>
#include <sys/stat.h>
#include <internal/wine/msvcrt.h>
#include <wine/debug.h>
Include dependency graph for dllmain.c:

Go to the source code of this file.

Classes

struct  crtdll_stat
 

Typedefs

typedef short crtdll_dev_t
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (crtdll)
 
void __getmainargs (int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
 
BOOL crt_process_init (void)
 
void FreeEnvironment (char **environment)
 
static void convert_struct_stat (struct crtdll_stat *dst, const struct _stat *src)
 
BOOL WINAPI DllMain (PVOID hinstDll, ULONG dwReason, PVOID reserved)
 
void __GetMainArgs (int *argc, char ***argv, char ***envp, int expand_wildcards)
 
int CRTDLL__fstat (int fd, struct crtdll_stat *buf)
 
int CRTDLL__stat (const char *path, struct crtdll_stat *buf)
 
char_strdec (const char *str1, const char *str2)
 
char_strinc (const char *str)
 
size_t _strncnt (const char *str, size_t maxlen)
 
unsigned int _strnextc (const char *str)
 
char_strninc (const char *str, size_t len)
 
char_strspnp (const char *str1, const char *str2)
 

Variables

unsigned int CRTDLL__basemajor_dll = 0
 
unsigned int CRTDLL__baseminor_dll = 0
 
unsigned int CRTDLL__baseversion_dll = 0
 
unsigned int CRTDLL__cpumode_dll = 0
 
unsigned int CRTDLL__osmajor_dll = 0
 
unsigned int CRTDLL__osminor_dll = 0
 
unsigned int CRTDLL__osmode_dll = 0
 
unsigned int CRTDLL__osversion_dll = 0
 
int _fileinfo_dll
 
char ** _environ
 
char ** __initenv
 
wchar_t ** _wenviron
 
wchar_t ** __winitenv
 

Typedef Documentation

◆ crtdll_dev_t

Definition at line 54 of file dllmain.c.

Function Documentation

◆ __GetMainArgs()

void __GetMainArgs ( int argc,
char ***  argv,
char ***  envp,
int  expand_wildcards 
)

Definition at line 160 of file dllmain.c.

161{
162 int new_mode = 0;
163 __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
164}
static int argc
Definition: ServiceArgs.c:12
void __getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
Definition: data.c:579
#define argv
Definition: mplay32.c:18

◆ __getmainargs()

void __getmainargs ( int argc,
char ***  argv,
char ***  envp,
int  expand_wildcards,
int new_mode 
)

Definition at line 579 of file data.c.

581{
582 TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
583
584 if (expand_wildcards) {
588 if (wargv_expand) {
590
593 }else {
594 expand_wildcards = 0;
595 }
596 }
597 if (!expand_wildcards) {
598#ifdef __REACTOS__
599 if ((MSVCRT___argv == NULL) || (MSVCRT___argc == 0))
600 {
601 MSVCRT___argv = cmdline_to_argvA(MSVCRT__acmdln, &MSVCRT___argc);
602 }
603#else
606#endif
607 }
608
611 *envp = MSVCRT__environ;
612
613 if (new_mode)
614 _set_new_mode( *new_mode );
615 return 0;
616}
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
static char ** build_argv(WCHAR **wargv)
Definition: data.c:63
static int initial_argc
Definition: data.c:30
static int build_expanded_wargv(int *argc, wchar_t **argv)
Definition: data.c:471
static int wargc_expand
Definition: data.c:32
char ** MSVCRT___argv
Definition: data.c:50
static WCHAR ** initial_wargv
Definition: data.c:29
int MSVCRT___argc
Definition: data.c:31
char ** MSVCRT__environ
Definition: data.c:55
char * MSVCRT__acmdln
Definition: data.c:53
static wchar_t ** wargv_expand
Definition: data.c:52
int CDECL _set_new_mode(int mode)
Definition: heap.c:227
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by __GetMainArgs(), mainCRTStartup(), test__environ(), and test__wenviron().

◆ _strdec()

char * _strdec ( const char str1,
const char str2 
)

Definition at line 198 of file dllmain.c.

199{
200 return (char *)(str2 - 1);
201}

◆ _strinc()

char * _strinc ( const char str)

Definition at line 207 of file dllmain.c.

208{
209 return (char *)(str + 1);
210}
const WCHAR * str

◆ _strncnt()

size_t _strncnt ( const char str,
size_t  maxlen 
)

Definition at line 216 of file dllmain.c.

217{
218 size_t len = strlen(str);
219 return (len > maxlen) ? maxlen : len;
220}
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
GLenum GLsizei len
Definition: glext.h:6722

◆ _strnextc()

unsigned int _strnextc ( const char str)

Definition at line 226 of file dllmain.c.

227{
228 return (unsigned int)str[0];
229}

◆ _strninc()

char * _strninc ( const char str,
size_t  len 
)

Definition at line 235 of file dllmain.c.

236{
237 return (char *)(str + len);
238}

◆ _strspnp()

char * _strspnp ( const char str1,
const char str2 
)

Definition at line 244 of file dllmain.c.

245{
246 str1 += strspn( str1, str2 );
247 return *str1 ? (char*)str1 : NULL;
248}
_ACRTIMP size_t __cdecl strspn(const char *, const char *)
Definition: string.c:3515

◆ convert_struct_stat()

static void convert_struct_stat ( struct crtdll_stat dst,
const struct _stat src 
)
static

Definition at line 72 of file dllmain.c.

73{
74 dst->st_dev = src->st_dev;
75 dst->st_ino = src->st_ino;
76 dst->st_mode = src->st_mode;
77 dst->st_nlink = src->st_nlink;
78 dst->st_uid = src->st_uid;
79 dst->st_gid = src->st_gid;
80 dst->st_rdev = src->st_rdev;
81 dst->st_size = src->st_size;
82 dst->st_atime = src->st_atime;
83 dst->st_mtime = src->st_mtime;
84 dst->st_ctime = src->st_ctime;
85}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by CRTDLL__fstat(), and CRTDLL__stat().

◆ crt_process_init()

BOOL crt_process_init ( void  )

Definition at line 21 of file crt_init.c.

22{
24
25 /* initialize version info */
33
34 /* create tls stuff */
36 return FALSE;
37
38 if (!msvcrt_init_heap())
39 return FALSE;
40
41 if (BlockEnvToEnvironA() < 0)
42 return FALSE;
43
44 if (BlockEnvToEnvironW() < 0)
45 {
47 return FALSE;
48 }
49
52
53 /* Initialization of the WINE code */
55
56 //msvcrt_init_math();
58 //msvcrt_init_console();
59 //msvcrt_init_args();
60 //msvcrt_init_signals();
61
62 return TRUE;
63}
char * _acmdln
Definition: environ.c:18
void msvcrt_init_io(void)
Definition: file.c:720
void msvcrt_init_mt_locks(void)
Definition: lock.c:66
int BlockEnvToEnvironA(void)
Definition: environ.c:34
void FreeEnvironment(char **environment)
Definition: environ.c:190
BOOL msvcrt_init_heap(void)
Definition: heap.c:830
wchar_t * _wcmdln
Definition: environ.c:19
int BlockEnvToEnvironW(void)
Definition: environ.c:86
char ** _environ
Definition: environ.c:22
#define _strdup
Definition: debug_ros.c:7
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
LPWSTR WINAPI GetCommandLineW(void)
Definition: process.c:1338
LPSTR WINAPI GetCommandLineA(void)
Definition: process.c:1329
_ACRTIMP wchar_t *__cdecl _wcsdup(const wchar_t *) __WINE_DEALLOC(free) __WINE_MALLOC
Definition: wcs.c:81
unsigned int _winminor
Definition: environ.c:12
unsigned int _winmajor
Definition: environ.c:13
unsigned int _osver
Definition: environ.c:11
unsigned int _winver
Definition: environ.c:14
static BOOL msvcrt_init_tls(void)
Definition: main.c:43
if(dx< 0)
Definition: linetemp.h:194
unsigned int _osplatform
Definition: environ.c:10
ULONG dwPlatformId
Definition: rtltypes.h:241
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwMajorVersion
Definition: rtltypes.h:238
ULONG dwBuildNumber
Definition: rtltypes.h:240
ULONG dwMinorVersion
Definition: rtltypes.h:239
OSVERSIONINFO osvi
Definition: ver.c:28
struct _OSVERSIONINFOW OSVERSIONINFOW

Referenced by DllMain().

◆ CRTDLL__fstat()

int CRTDLL__fstat ( int  fd,
struct crtdll_stat buf 
)

Definition at line 170 of file dllmain.c.

171{
172 extern int _fstat(int,struct _stat*);
173 struct _stat st;
174 int ret;
175
176 if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
177 return ret;
178}
static void convert_struct_stat(struct crtdll_stat *dst, const struct _stat *src)
Definition: dllmain.c:72
return ret
Definition: mutex.c:146
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define _fstat
Definition: stat.h:144
static int fd
Definition: io.c:51
Definition: stat.h:52

◆ CRTDLL__stat()

int CRTDLL__stat ( const char path,
struct crtdll_stat buf 
)

Definition at line 184 of file dllmain.c.

185{
186 extern int _stat(const char*,struct _stat*);
187 struct _stat st;
188 int ret;
189
190 if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
191 return ret;
192}
#define _stat
Definition: stat.h:146

◆ DllMain()

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

Definition at line 91 of file dllmain.c.

92{
94 switch (dwReason)
95 {
98
99 /* initialize version info */
100 CRTDLL__basemajor_dll = (version >> 24) & 0xFF;
101 CRTDLL__baseminor_dll = (version >> 16) & 0xFF;
103 CRTDLL__cpumode_dll = 1; /* FIXME */
104 CRTDLL__osmajor_dll = (version >>8) & 0xFF;
105 CRTDLL__osminor_dll = (version & 0xFF);
106 CRTDLL__osmode_dll = 1; /* FIXME */
107 CRTDLL__osversion_dll = (version & 0xFFFF);
108
109 if (!crt_process_init())
110 {
111 ERR("crt_init() failed!\n");
112 return FALSE;
113 }
114
115 TRACE("Attach done\n");
116 break;
118 break;
119
122 break;
123
125 TRACE("Detach\n");
126 /* Deinit of the WINE code */
128 if (reserved) break;
131 //msvcrt_free_console();
132 //msvcrt_free_args();
133 //msvcrt_free_signals();
135 if (!msvcrt_free_tls())
136 return FALSE;
137 //MSVCRT__free_locale(MSVCRT_locale);
138
141 if (_wenviron)
142 FreeEnvironment((char**)_wenviron);
143
144 if (__initenv && __initenv != _environ)
146 if (_environ)
148
149 TRACE("Detach done\n");
150 break;
151 }
152
153 return TRUE;
154}
#define ERR(fmt,...)
Definition: precomp.h:57
DWORD dwReason
Definition: misc.cpp:135
unsigned int CRTDLL__osminor_dll
Definition: dllmain.c:42
unsigned int CRTDLL__cpumode_dll
Definition: dllmain.c:40
void FreeEnvironment(char **environment)
Definition: environ.c:190
char ** __initenv
Definition: environ.c:24
unsigned int CRTDLL__baseminor_dll
Definition: dllmain.c:38
wchar_t ** __winitenv
Definition: environ.c:25
wchar_t ** _wenviron
Definition: environ.c:23
unsigned int CRTDLL__osversion_dll
Definition: dllmain.c:44
unsigned int CRTDLL__basemajor_dll
Definition: dllmain.c:37
BOOL crt_process_init(void)
Definition: crt_init.c:21
unsigned int CRTDLL__baseversion_dll
Definition: dllmain.c:39
unsigned int CRTDLL__osmajor_dll
Definition: dllmain.c:41
unsigned int CRTDLL__osmode_dll
Definition: dllmain.c:43
char ** _environ
Definition: environ.c:22
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
static const WCHAR version[]
Definition: asmname.c:66
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
void msvcrt_free_io(void)
Definition: file.c:1392
static void msvcrt_free_tls_mem(void)
Definition: main.c:65
static BOOL msvcrt_free_tls(void)
Definition: main.c:55
void msvcrt_free_popen_data(void)
Definition: process.c:1034
r reserved
Definition: btrfs.c:3006
unsigned long DWORD
Definition: ntddk_ex.h:95
void msvcrt_free_mt_locks(void)
Definition: lock.c:77

◆ 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

Referenced by DllMain().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( crtdll  )

Variable Documentation

◆ __initenv

char** __initenv
extern

Definition at line 24 of file environ.c.

Referenced by DllMain(), and Test___initenv().

◆ __winitenv

wchar_t** __winitenv
extern

Definition at line 25 of file environ.c.

Referenced by DllMain(), and Test___winitenv().

◆ _environ

char** _environ
extern

Definition at line 22 of file environ.c.

Referenced by DllMain().

◆ _fileinfo_dll

int _fileinfo_dll

Definition at line 45 of file dllmain.c.

◆ _wenviron

wchar_t** _wenviron
extern

Definition at line 23 of file environ.c.

Referenced by DllMain().

◆ CRTDLL__basemajor_dll

unsigned int CRTDLL__basemajor_dll = 0

Definition at line 37 of file dllmain.c.

Referenced by DllMain(), and msvcrt_init_args().

◆ CRTDLL__baseminor_dll

unsigned int CRTDLL__baseminor_dll = 0

Definition at line 38 of file dllmain.c.

Referenced by DllMain(), and msvcrt_init_args().

◆ CRTDLL__baseversion_dll

unsigned int CRTDLL__baseversion_dll = 0

Definition at line 39 of file dllmain.c.

Referenced by DllMain(), and msvcrt_init_args().

◆ CRTDLL__cpumode_dll

unsigned int CRTDLL__cpumode_dll = 0

Definition at line 40 of file dllmain.c.

Referenced by DllMain().

◆ CRTDLL__osmajor_dll

unsigned int CRTDLL__osmajor_dll = 0

Definition at line 41 of file dllmain.c.

Referenced by DllMain().

◆ CRTDLL__osminor_dll

unsigned int CRTDLL__osminor_dll = 0

Definition at line 42 of file dllmain.c.

Referenced by DllMain().

◆ CRTDLL__osmode_dll

unsigned int CRTDLL__osmode_dll = 0

Definition at line 43 of file dllmain.c.

Referenced by DllMain().

◆ CRTDLL__osversion_dll

unsigned int CRTDLL__osversion_dll = 0

Definition at line 44 of file dllmain.c.

Referenced by DllMain().