32
32
#include <sys/stat.h>
33
33
#include <fcntl.h>
34
34
35
+ #ifdef HAVE_LIBDL
36
+ #ifdef PHP_WIN32
37
+ #include "win32/param.h"
38
+ #include "win32/winutil.h"
39
+ #define GET_DL_ERROR () php_win_err()
40
+ #else
41
+ #include <sys/param.h>
42
+ #define GET_DL_ERROR () DL_ERROR()
43
+ #endif
44
+ #endif
45
+
35
46
#ifdef HAVE_GLOB
36
47
#ifdef PHP_WIN32
37
48
#include "win32/glob.h"
@@ -2934,6 +2945,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
2934
2945
zend_string * lib = NULL ;
2935
2946
zend_ffi * ffi = NULL ;
2936
2947
DL_HANDLE handle = NULL ;
2948
+ char * err ;
2937
2949
void * addr ;
2938
2950
2939
2951
ZEND_FFI_VALIDATE_API_RESTRICTION ();
@@ -2946,9 +2958,21 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
2946
2958
if (lib ) {
2947
2959
handle = DL_LOAD (ZSTR_VAL (lib ));
2948
2960
if (!handle ) {
2949
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s'" , ZSTR_VAL (lib ));
2961
+ err = GET_DL_ERROR ();
2962
+ #ifdef PHP_WIN32
2963
+ if (err && err [0 ]) {
2964
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s' (%s)" , ZSTR_VAL (lib ), err );
2965
+ php_win32_error_msg_free (err );
2966
+ } else {
2967
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s' (Unknown reason)" , ZSTR_VAL (lib ));
2968
+ }
2969
+ #else
2970
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s' (%s)" , ZSTR_VAL (lib ), err );
2971
+ GET_DL_ERROR (); /* free the buffer storing the error */
2972
+ #endif
2950
2973
RETURN_THROWS ();
2951
2974
}
2975
+
2952
2976
#ifdef RTLD_DEFAULT
2953
2977
} else if (1 ) {
2954
2978
// TODO: this might need to be disabled or protected ???
@@ -3201,7 +3225,7 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
3201
3225
{
3202
3226
struct stat buf ;
3203
3227
int fd ;
3204
- char * code , * code_pos , * scope_name , * lib ;
3228
+ char * code , * code_pos , * scope_name , * lib , * err ;
3205
3229
size_t code_size , scope_name_len ;
3206
3230
zend_ffi * ffi ;
3207
3231
DL_HANDLE handle = NULL ;
@@ -3278,7 +3302,18 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
3278
3302
if (preload ) {
3279
3303
zend_error (E_WARNING , "FFI: Failed pre-loading '%s'" , lib );
3280
3304
} else {
3281
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s'" , lib );
3305
+ err = GET_DL_ERROR ();
3306
+ #ifdef PHP_WIN32
3307
+ if (err && err [0 ]) {
3308
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s' (%s)" , lib , err );
3309
+ php_win32_error_msg_free (err );
3310
+ } else {
3311
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s' (Unknown reason)" , lib );
3312
+ }
3313
+ #else
3314
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s' (%s)" , lib , err );
3315
+ GET_DL_ERROR (); /* free the buffer storing the error */
3316
+ #endif
3282
3317
}
3283
3318
goto cleanup ;
3284
3319
}
0 commit comments