xref: /PHP-8.4/win32/dllmain.c (revision b86dfd76)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Anatol Belski <ab@php.net>                                  |
14    +----------------------------------------------------------------------+
15  */
16 
17 #include <config.w32.h>
18 
19 #include <php.h>
20 #include <win32/ioutil.h>
21 
22 #ifdef HAVE_LIBXML
23 #include <libxml/threads.h>
24 #endif
25 
26 /* TODO this file, or part of it, could be machine generated, to
27 	allow extensions and SAPIs adding their own init stuff.
28 	However expected is that MINIT is enough in most cases.
29 	This file is only useful for some really internal stuff,
30 	eq. initializing something before the DLL even is
31 	available to be called. */
32 
DllMain(HINSTANCE inst,DWORD reason,LPVOID dummy)33 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
34 {
35 	BOOL ret = TRUE;
36 
37 	switch (reason)
38 	{
39 		case DLL_PROCESS_ATTACH:
40 			ret = ret && php_win32_ioutil_init();
41 			if (!ret) {
42 				fprintf(stderr, "ioutil initialization failed");
43 				return ret;
44 			}
45 			break;
46 #if 0 /* prepared */
47 		case DLL_PROCESS_DETACH:
48 			/* pass */
49 			break;
50 
51 		case DLL_THREAD_ATTACH:
52 			/* pass */
53 			break;
54 
55 		case DLL_THREAD_DETACH:
56 			/* pass */
57 			break;
58 #endif
59 	}
60 
61 #ifdef HAVE_LIBXML
62 	/* This imply that only LIBXML_STATIC_FOR_DLL is supported ATM.
63 		If that changes, this place will need some rework.
64 	   TODO Also this should be revisited as no initialization
65 		might be needed for TS build (libxml build with TLS
66 		support. */
67 	ret = ret && xmlDllMain(inst, reason, dummy);
68 #endif
69 
70 	return ret;
71 }
72