Skip to content

Commit e1814f0

Browse files
committed
WIN64 support
1 parent f088268 commit e1814f0

22 files changed

+78
-53
lines changed

TSRM/TSRM.h

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
# define TSRM_API
3131
#endif
3232

33+
#ifdef _WIN64
34+
typedef unsigned __int64 tsrm_intptr_t;
35+
typedef __int64 tsrm_uintptr_t;
36+
#else
37+
typedef long tsrm_intptr_t;
38+
typedef unsigned long tsrm_uintptr_t;
39+
#endif
40+
3341
/* Only compile multi-threading functions if we're in ZTS mode */
3442
#ifdef ZTS
3543

TSRM/tsrm_win32.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
228228
proc = process_get(NULL TSRMLS_CC);
229229

230230
if (read) {
231-
fno = _open_osfhandle((long)in, _O_RDONLY | mode);
231+
fno = _open_osfhandle((tsrm_intptr_t)in, _O_RDONLY | mode);
232232
CloseHandle(out);
233233
} else {
234-
fno = _open_osfhandle((long)out, _O_WRONLY | mode);
234+
fno = _open_osfhandle((tsrm_intptr_t)out, _O_WRONLY | mode);
235235
CloseHandle(in);
236236
}
237237

Zend/zend_API.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ZEND_API int zend_get_parameters(int ht, int param_count, ...)
4444
TSRMLS_FETCH();
4545

4646
p = EG(argument_stack).top_element-2;
47-
arg_count = (ulong) *p;
47+
arg_count = (int)(zend_uintptr_t) *p;
4848

4949
if (param_count>arg_count) {
5050
return FAILURE;
@@ -82,7 +82,7 @@ ZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument
8282
zval *param_ptr;
8383

8484
p = EG(argument_stack).top_element-2;
85-
arg_count = (ulong) *p;
85+
arg_count = (int)(zend_uintptr_t) *p;
8686

8787
if (param_count>arg_count) {
8888
return FAILURE;
@@ -122,7 +122,7 @@ ZEND_API int zend_get_parameters_ex(int param_count, ...)
122122
TSRMLS_FETCH();
123123

124124
p = EG(argument_stack).top_element-2;
125-
arg_count = (ulong) *p;
125+
arg_count = (int)(zend_uintptr_t) *p;
126126

127127
if (param_count>arg_count) {
128128
return FAILURE;
@@ -145,7 +145,7 @@ ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_arr
145145
int arg_count;
146146

147147
p = EG(argument_stack).top_element-2;
148-
arg_count = (ulong) *p;
148+
arg_count = (int)(zend_uintptr_t) *p;
149149

150150
if (param_count>arg_count) {
151151
return FAILURE;
@@ -187,7 +187,7 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TS
187187
int arg_count;
188188

189189
p = EG(argument_stack).top_element-2;
190-
arg_count = (ulong) *p;
190+
arg_count = (int)(zend_uintptr_t) *p;
191191

192192
if (param_count>arg_count) {
193193
return FAILURE;
@@ -698,7 +698,7 @@ static int zend_parse_va_args(int num_args, char *type_spec, va_list *va, int fl
698698
}
699699

700700
p = EG(argument_stack).top_element-2;
701-
arg_count = (ulong) *p;
701+
arg_count = (int)(zend_uintptr_t) *p;
702702

703703
if (num_args > arg_count) {
704704
zend_error(E_WARNING, "%s(): could not obtain parameters for parsing",
@@ -878,7 +878,7 @@ ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC
878878
zend_update_class_constants(class_type->parent TSRMLS_CC);
879879
}
880880
#if ZTS
881-
ALLOC_HASHTABLE(CG(static_members)[(long)(class_type->static_members)]);
881+
ALLOC_HASHTABLE(CG(static_members)[(zend_intptr_t)(class_type->static_members)]);
882882
#else
883883
ALLOC_HASHTABLE(class_type->static_members);
884884
#endif

Zend/zend_API.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ typedef struct _zend_function_entry {
160160
INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset, NULL, NULL)
161161

162162
#ifdef ZTS
163-
# define CE_STATIC_MEMBERS(ce) (((ce)->type==ZEND_USER_CLASS)?(ce)->static_members:CG(static_members)[(long)(ce)->static_members])
163+
# define CE_STATIC_MEMBERS(ce) (((ce)->type==ZEND_USER_CLASS)?(ce)->static_members:CG(static_members)[(zend_intptr_t)(ce)->static_members])
164164
#else
165165
# define CE_STATIC_MEMBERS(ce) ((ce)->static_members)
166166
#endif

Zend/zend_alloc.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@
5050
# define ZEND_MM_COOKIES ZEND_DEBUG
5151
#endif
5252

53+
#ifdef _WIN64
54+
# define PTR_FMT "0x%0.16I64x"
55+
/*
56+
#elif sizeof(long) == 8
57+
# define PTR_FMT "0x%0.16lx"
58+
*/
59+
#else
60+
# define PTR_FMT "0x%0.8lx"
61+
#endif
62+
5363
#if ZEND_DEBUG
5464
void zend_debug_alloc_output(char *format, ...)
5565
{
@@ -1180,7 +1190,7 @@ static void zend_mm_check_leaks(zend_mm_heap *heap)
11801190
repeated = zend_mm_find_leaks(segment, p);
11811191
total += 1 + repeated;
11821192
if (repeated) {
1183-
zend_message_dispatcher(ZMSG_MEMORY_LEAK_REPEATED, (void *)repeated);
1193+
zend_message_dispatcher(ZMSG_MEMORY_LEAK_REPEATED, (void *)(zend_uintptr_t)repeated);
11841194
}
11851195
#if ZEND_MM_CACHE
11861196
} else if (p->magic == MEM_BLOCK_CACHED) {
@@ -1221,7 +1231,7 @@ static int zend_mm_check_ptr(zend_mm_heap *heap, void *ptr, int silent ZEND_FILE
12211231
if (!silent) {
12221232
zend_message_dispatcher(ZMSG_LOG_SCRIPT_NAME, NULL);
12231233
zend_debug_alloc_output("---------------------------------------\n");
1224-
zend_debug_alloc_output("%s(%d) : Block 0x%0.8lX status:\n" ZEND_FILE_LINE_RELAY_CC, (long) ptr);
1234+
zend_debug_alloc_output("%s(%d) : Block "PTR_FMT" status:\n" ZEND_FILE_LINE_RELAY_CC, ptr);
12251235
if (__zend_orig_filename) {
12261236
zend_debug_alloc_output("%s(%d) : Actual location (location was relayed)\n" ZEND_FILE_LINE_ORIG_RELAY_CC);
12271237
}
@@ -1253,7 +1263,7 @@ static int zend_mm_check_ptr(zend_mm_heap *heap, void *ptr, int silent ZEND_FILE
12531263

12541264
if (p->info._size != ZEND_MM_NEXT_BLOCK(p)->info._prev) {
12551265
if (!silent) {
1256-
zend_debug_alloc_output("Invalid pointer: ((size=0x%0.8X) != (next.prev=0x%0.8X))\n", p->info._size, ZEND_MM_NEXT_BLOCK(p)->info._prev);
1266+
zend_debug_alloc_output("Invalid pointer: ((size="PTR_FMT") != (next.prev="PTR_FMT"))\n", p->info._size, ZEND_MM_NEXT_BLOCK(p)->info._prev);
12571267
had_problems = 1;
12581268
} else {
12591269
return zend_mm_check_ptr(heap, ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
@@ -1262,7 +1272,7 @@ static int zend_mm_check_ptr(zend_mm_heap *heap, void *ptr, int silent ZEND_FILE
12621272
if (p->info._prev != ZEND_MM_GUARD_BLOCK &&
12631273
ZEND_MM_PREV_BLOCK(p)->info._size != p->info._prev) {
12641274
if (!silent) {
1265-
zend_debug_alloc_output("Invalid pointer: ((prev=0x%0.8X) != (prev.size=0x%0.8X))\n", p->info._prev, ZEND_MM_PREV_BLOCK(p)->info._size);
1275+
zend_debug_alloc_output("Invalid pointer: ((prev="PTR_FMT") != (prev.size="PTR_FMT"))\n", p->info._prev, ZEND_MM_PREV_BLOCK(p)->info._size);
12661276
had_problems = 1;
12671277
} else {
12681278
return zend_mm_check_ptr(heap, ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);

Zend/zend_builtin_functions.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ ZEND_FUNCTION(func_num_args)
172172
int arg_count;
173173

174174
p = EG(argument_stack).top_element-1-1;
175-
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */
175+
arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_num_args(); */
176176
p -= 1+arg_count;
177177
if (*p) {
178178
zend_error(E_ERROR, "func_num_args(): Can't be used as a function parameter");
179179
}
180180
--p;
181181
if (p>=EG(argument_stack).elements) {
182-
RETURN_LONG((ulong) *p);
182+
RETURN_LONG((long)(zend_uintptr_t) *p);
183183
} else {
184184
zend_error(E_WARNING, "func_num_args(): Called from the global scope - no function context");
185185
RETURN_LONG(-1);
@@ -210,7 +210,7 @@ ZEND_FUNCTION(func_get_arg)
210210
}
211211

212212
p = EG(argument_stack).top_element-1-1;
213-
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_get_arg(); */
213+
arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_get_arg(); */
214214
p -= 1+arg_count;
215215
if (*p) {
216216
zend_error(E_ERROR, "func_get_arg(): Can't be used as a function parameter");
@@ -220,7 +220,7 @@ ZEND_FUNCTION(func_get_arg)
220220
zend_error(E_WARNING, "func_get_arg(): Called from the global scope - no function context");
221221
RETURN_FALSE;
222222
}
223-
arg_count = (ulong) *p;
223+
arg_count = (int)(zend_uintptr_t) *p;
224224

225225
if (requested_offset>=arg_count) {
226226
zend_error(E_WARNING, "func_get_arg(): Argument %ld not passed to function", requested_offset);
@@ -244,7 +244,7 @@ ZEND_FUNCTION(func_get_args)
244244
int i;
245245

246246
p = EG(argument_stack).top_element-1-1;
247-
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_get_args(); */
247+
arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_get_args(); */
248248
p -= 1+arg_count;
249249
if (*p) {
250250
zend_error(E_ERROR, "func_get_args(): Can't be used as a function parameter");
@@ -255,7 +255,7 @@ ZEND_FUNCTION(func_get_args)
255255
zend_error(E_WARNING, "func_get_args(): Called from the global scope - no function context");
256256
RETURN_FALSE;
257257
}
258-
arg_count = (ulong) *p;
258+
arg_count = (int)(zend_uintptr_t) *p;
259259

260260

261261
array_init(return_value);
@@ -1655,7 +1655,7 @@ static zval *debug_backtrace_get_args(void ***curpos TSRMLS_DC)
16551655
{
16561656
void **p = *curpos - 2;
16571657
zval *arg_array, **arg;
1658-
int arg_count = (ulong) *p;
1658+
int arg_count = (int)(zend_uintptr_t) *p;
16591659

16601660
*curpos -= (arg_count+2);
16611661

Zend/zend_compile.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4189,7 +4189,7 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify
41894189
CG(static_members) = realloc(CG(static_members), (n+1)*sizeof(HashTable*));
41904190
CG(static_members)[n] = NULL;
41914191
}
4192-
ce->static_members = (HashTable*)n;
4192+
ce->static_members = (HashTable*)(zend_intptr_t)n;
41934193
#else
41944194
ce->static_members = NULL;
41954195
#endif

Zend/zend_execute.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ static inline void zend_pzval_unlock_free_func(zval *z)
104104

105105
#define FREE_OP(should_free) \
106106
if (should_free.var) { \
107-
if ((long)should_free.var & 1L) { \
108-
zval_dtor((zval*)((long)should_free.var & ~1L)); \
107+
if ((zend_uintptr_t)should_free.var & 1L) { \
108+
zval_dtor((zval*)((zend_uintptr_t)should_free.var & ~1L)); \
109109
} else { \
110110
zval_ptr_dtor(&should_free.var); \
111111
} \
112112
}
113113

114114
#define FREE_OP_IF_VAR(should_free) \
115-
if (should_free.var != NULL && (((long)should_free.var & 1L) == 0)) { \
115+
if (should_free.var != NULL && (((zend_uintptr_t)should_free.var & 1L) == 0)) { \
116116
zval_ptr_dtor(&should_free.var); \
117117
}
118118

@@ -121,9 +121,9 @@ static inline void zend_pzval_unlock_free_func(zval *z)
121121
zval_ptr_dtor(&should_free.var); \
122122
}
123123

124-
#define TMP_FREE(z) (zval*)(((long)(z)) | 1L)
124+
#define TMP_FREE(z) (zval*)(((zend_uintptr_t)(z)) | 1L)
125125

126-
#define IS_TMP_FREE(should_free) ((long)should_free.var & 1L)
126+
#define IS_TMP_FREE(should_free) ((zend_uintptr_t)should_free.var & 1L)
127127

128128
#define INIT_PZVAL_COPY(z,v) \
129129
(z)->value = (v)->value; \

Zend/zend_execute.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco
146146
static inline void zend_ptr_stack_clear_multiple(TSRMLS_D)
147147
{
148148
void **p = EG(argument_stack).top_element-2;
149-
int delete_count = (ulong) *p;
149+
int delete_count = (int)(zend_uintptr_t) *p;
150150

151151
EG(argument_stack).top -= (delete_count+2);
152152
while (--delete_count>=0) {
@@ -160,7 +160,7 @@ static inline void zend_ptr_stack_clear_multiple(TSRMLS_D)
160160
static inline int zend_ptr_stack_get_arg(int requested_arg, void **data TSRMLS_DC)
161161
{
162162
void **p = EG(argument_stack).top_element-2;
163-
int arg_count = (ulong) *p;
163+
int arg_count = (int)(zend_uintptr_t) *p;
164164

165165
if (requested_arg>arg_count) {
166166
return FAILURE;

Zend/zend_execute_API.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ ZEND_API int zend_is_true(zval *op)
451451
ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *scope TSRMLS_DC)
452452
{
453453
zval *p = *pp;
454-
zend_bool inline_change = (zend_bool) (unsigned long) arg;
454+
zend_bool inline_change = (zend_bool) (zend_uintptr_t) arg;
455455
zval const_value;
456456

457457
if (Z_TYPE_P(p) == IS_CONSTANT) {
@@ -867,7 +867,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
867867
if (fci->no_separation) {
868868
if(i) {
869869
/* hack to clean up the stack */
870-
zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) (long) i, NULL);
870+
zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) (zend_uintptr_t) i, NULL);
871871
zend_ptr_stack_clear_multiple(TSRMLS_C);
872872
}
873873

@@ -908,7 +908,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
908908
fci->param_count = 2;
909909
}
910910

911-
zend_ptr_stack_2_push(&EG(argument_stack), (void *) (long) fci->param_count, NULL);
911+
zend_ptr_stack_2_push(&EG(argument_stack), (void *) (zend_uintptr_t) fci->param_count, NULL);
912912

913913
original_function_state_ptr = EG(function_state_ptr);
914914
EG(function_state_ptr) = &EX(function_state);

Zend/zend_ini.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static int zend_ini_refresh_cache(zend_ini_entry *p, int stage TSRMLS_DC)
225225

226226
ZEND_API void zend_ini_refresh_caches(int stage TSRMLS_DC)
227227
{
228-
zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) zend_ini_refresh_cache, (void *)(long) stage TSRMLS_CC);
228+
zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) zend_ini_refresh_cache, (void *)(zend_intptr_t) stage TSRMLS_CC);
229229
}
230230
#endif
231231

Zend/zend_opcode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC)
160160
zend_hash_destroy(CE_STATIC_MEMBERS(*pce));
161161
FREE_HASHTABLE(CE_STATIC_MEMBERS(*pce));
162162
#ifdef ZTS
163-
CG(static_members)[(long)((*pce)->static_members)] = NULL;
163+
CG(static_members)[(zend_intptr_t)((*pce)->static_members)] = NULL;
164164
#else
165165
(*pce)->static_members = NULL;
166166
#endif

Zend/zend_types.h

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ typedef unsigned int zend_uint;
2828
typedef unsigned long zend_ulong;
2929
typedef unsigned short zend_ushort;
3030

31+
#ifdef _WIN64
32+
typedef unsigned __int64 zend_intptr_t;
33+
typedef __int64 zend_uintptr_t;
34+
#else
35+
typedef long zend_intptr_t;
36+
typedef unsigned long zend_uintptr_t;
37+
#endif
38+
3139
typedef unsigned int zend_object_handle;
3240
typedef struct _zend_object_handlers zend_object_handlers;
3341

Zend/zend_vm_def.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
18571857
}
18581858
}
18591859

1860-
zend_ptr_stack_2_push(&EG(argument_stack), (void *) opline->extended_value, NULL);
1860+
zend_ptr_stack_2_push(&EG(argument_stack), (void *)(zend_uintptr_t)opline->extended_value, NULL);
18611861

18621862
EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr;
18631863

@@ -1900,7 +1900,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
19001900
ulong arg_count;
19011901

19021902
p = (zval **) EG(argument_stack).top_element-2;
1903-
arg_count = (ulong) *p;
1903+
arg_count = (ulong)(zend_uintptr_t) *p;
19041904

19051905
while (arg_count>0) {
19061906
zend_verify_arg_type(EX(function_state).function, ++i, *(p-arg_count) TSRMLS_CC);

Zend/zend_vm_execute.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
145145
}
146146
}
147147

148-
zend_ptr_stack_2_push(&EG(argument_stack), (void *) opline->extended_value, NULL);
148+
zend_ptr_stack_2_push(&EG(argument_stack), (void *)(zend_uintptr_t)opline->extended_value, NULL);
149149

150150
EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr;
151151

@@ -188,7 +188,7 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
188188
ulong arg_count;
189189

190190
p = (zval **) EG(argument_stack).top_element-2;
191-
arg_count = (ulong) *p;
191+
arg_count = (ulong)(zend_uintptr_t) *p;
192192

193193
while (arg_count>0) {
194194
zend_verify_arg_type(EX(function_state).function, ++i, *(p-arg_count) TSRMLS_CC);

ext/standard/proc_open.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ PHP_FUNCTION(proc_open)
946946
break;
947947
}
948948
#ifdef PHP_WIN32
949-
stream = php_stream_fopen_from_fd(_open_osfhandle((long)descriptors[i].parentend,
949+
stream = php_stream_fopen_from_fd(_open_osfhandle((zend_intptr_t)descriptors[i].parentend,
950950
descriptors[i].mode_flags), mode_string, NULL);
951951
#else
952952
stream = php_stream_fopen_from_fd(descriptors[i].parentend, mode_string, NULL);

main/SAPI.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
541541

542542
switch (op) {
543543
case SAPI_HEADER_SET_STATUS:
544-
sapi_update_response_code((long) arg TSRMLS_CC);
544+
sapi_update_response_code((int)(zend_intptr_t) arg TSRMLS_CC);
545545
return SUCCESS;
546546

547547
case SAPI_HEADER_REPLACE:

0 commit comments

Comments
 (0)