-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix Solaris 10 build: missing libproc.h #15525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The libproc.h header file was added on Solaris as of 11.4.
@@ -67,7 +67,9 @@ typedef int boolean_t; | |||
#define _STRUCTURED_PROC 1 | |||
#include <sys/lwp.h> | |||
#include <sys/procfs.h> | |||
#include <libproc.h> | |||
# ifdef HAVE_LIBPROC_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think the related api usage needs to be guarded, well more likely the full function in fact (by line 704). In other words, if no libproc then the function returns false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add a patch for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my lack of clarity, what I meant is something like this
static bool zend_call_stack_get_solaris_proc_maps(zend_call_stack *stack)
{
#ifdef HAVE_LIBPROC_H
char buffer[4096];
uintptr_t addr_on_stack = (uintptr_t) zend_call_stack_position();
bool found = false, r = false;
struct ps_prochandle *proc;
prmap_t *map, *orig;
struct rlimit rlim;
char path[PATH_MAX];
size_t size;
ssize_t len = -1;
pid_t pid;
int error, fd;
pid = getpid();
proc = Pgrab(pid, PGRAB_RDONLY, &error);
if (!proc) {
return false;
}
size = (1 << 20);
snprintf(path, sizeof(path), "/proc/%d/map", (int)pid);
if ((fd = open(path, O_RDONLY)) == -1) {
Prelease(proc, 0);
return false;
}
orig = malloc(size);
if (!orig) {
Prelease(proc, 0);
close(fd);
return false;
}
while (size > 0 && (len = pread(fd, orig, size, 0)) == size) {
prmap_t *tmp;
size <<= 1;
tmp = realloc(orig, size);
if (!tmp) {
goto end;
}
orig = tmp;
}
for (map = orig; len > 0; ++map) {
if ((uintptr_t)map->pr_vaddr <= addr_on_stack && (uintptr_t)map->pr_vaddr + map->pr_size >= addr_on_stack) {
found = true;
break;
}
len -= sizeof(*map);
}
if (!found) {
goto end;
}
error = getrlimit(RLIMIT_STACK, &rlim);
if (error || rlim.rlim_cur == RLIM_INFINITY) {
goto end;
}
stack->base = (void *)map->pr_vaddr + map->pr_size;
stack->max_size = rlim.rlim_cur;
r = true;
end:
free(orig);
Prelease(proc, 0);
close(fd);
return r;
#else
return false;
#endif
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect thanks. :D Appended in the next commit. This looks fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems, let me know if it builds, I no longer have any solaris stuff needs to recreate my VMs :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes, I know. Setting Solaris 10 development environment is not trivial at all. There is even a bug in GCC 5 so the GCC 4.9 needs to be used. And the main issue is getting the re2c newer than 1.0.3 and other dependencies (libxml ...).
It builds successfully with this patch in the current PR.
Zend/zend_call_stack.c
Outdated
@@ -67,7 +67,9 @@ typedef int boolean_t; | |||
#define _STRUCTURED_PROC 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: if we want to be "nitpicky", sys/procfs.h is also not used then in case the libproc api is not used. Can be guarded as well alongside with the #define _STRUCTURED_PROC 1
(which is for the sys/procfs.h to enable the newer procfs api). But again, it s being pedantic here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in the next commit. Builds successfully.
Zend/zend_call_stack.c
Outdated
#include <libproc.h> | ||
# ifdef HAVE_LIBPROC_H | ||
# define _STRUCTURED_PROC 1 | ||
# include <sys/lwp.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, sys/lwp.h is still needed outside I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'm now a bit confused because when fixing the stack grow check direction in Zend/Zend.m4 then there is
Fatal error: Maximum call stack size of 0 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached during compilation. Try splitting expression in /projects/php-src/run-tests.php on line 35
But the sys/lwp.h fix appended in the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes surely zend stack tests do not pass now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't ok then yet. Not that tests don't pass, but any PHP file cannot be run. Because zend_stack_limit_error throws error. Something more then should be adjusted here 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this ? if this still does not work, we might need to implement the call without libproc api, there might be an older system to be used.
#ifdef HAVE_LIBPROC_H
static bool zend_call_stack_get_solaris_proc_maps(zend_call_stack *stack)
{
char buffer[4096];
uintptr_t addr_on_stack = (uintptr_t) zend_call_stack_position();
bool found = false, r = false;
struct ps_prochandle *proc;
prmap_t *map, *orig;
struct rlimit rlim;
char path[PATH_MAX];
size_t size;
ssize_t len = -1;
pid_t pid;
int error, fd;
pid = getpid();
proc = Pgrab(pid, PGRAB_RDONLY, &error);
if (!proc) {
return false;
}
size = (1 << 20);
snprintf(path, sizeof(path), "/proc/%d/map", (int)pid);
if ((fd = open(path, O_RDONLY)) == -1) {
Prelease(proc, 0);
return false;
}
orig = malloc(size);
if (!orig) {
Prelease(proc, 0);
close(fd);
return false;
}
while (size > 0 && (len = pread(fd, orig, size, 0)) == size) {
prmap_t *tmp;
size <<= 1;
tmp = realloc(orig, size);
if (!tmp) {
goto end;
}
orig = tmp;
}
for (map = orig; len > 0; ++map) {
if ((uintptr_t)map->pr_vaddr <= addr_on_stack && (uintptr_t)map->pr_vaddr + map->pr_size >= addr_on_stack) {
found = true;
break;
}
len -= sizeof(*map);
}
if (!found) {
goto end;
}
error = getrlimit(RLIMIT_STACK, &rlim);
if (error || rlim.rlim_cur == RLIM_INFINITY) {
goto end;
}
stack->base = (void *)map->pr_vaddr + map->pr_size;
stack->max_size = rlim.rlim_cur;
r = true;
end:
free(orig);
Prelease(proc, 0);
close(fd);
return r;
}
static bool zend_call_stack_get_solaris(zend_call_stack *stack)
{
if (_lwp_self() == 1) {
return zend_call_stack_get_solaris_proc_maps(stack);
}
return zend_call_stack_get_solaris_pthread(stack);
}
#else
static bool zend_call_stack_get_solaris(zend_call_stack *stack)
{
return zend_call_stack_get_solaris_pthread(stack);
}
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a bit different checks. With this above that was still happening. But the following commit seems to now work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your change is simpler, nice.
Then I'll be merging this soon. Change in the PR looks ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LCTM
The libproc.h header file was added on Solaris as of 11.4.