Skip to content

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

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ dnl
AC_DEFUN([ZEND_INIT], [dnl
AC_REQUIRE([AC_PROG_CC])

AC_CHECK_HEADERS([cpuid.h])
AC_CHECK_HEADERS(m4_normalize([
cpuid.h
libproc.h
]))

dnl Check for library functions.
AC_CHECK_FUNCS(m4_normalize([
Expand Down
14 changes: 10 additions & 4 deletions Zend/zend_call_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ typedef int boolean_t;
#include <sys/syscall.h>
#endif
#ifdef __sun
#define _STRUCTURED_PROC 1
#include <sys/lwp.h>
#include <sys/procfs.h>
#include <libproc.h>
# include <sys/lwp.h>
# ifdef HAVE_LIBPROC_H
Copy link
Member

@devnexen devnexen Aug 21, 2024

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.

Copy link
Member Author

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?

Copy link
Member

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
}

Copy link
Member Author

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?

Copy link
Member

@devnexen devnexen Aug 21, 2024

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 :)

Copy link
Member Author

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.

# define _STRUCTURED_PROC 1
# include <sys/procfs.h>
# include <libproc.h>
# endif
#include <thread.h>
#endif

Expand Down Expand Up @@ -699,6 +701,7 @@ static bool zend_call_stack_get_solaris_pthread(zend_call_stack *stack)
return true;
}

#ifdef HAVE_LIBPROC_H
static bool zend_call_stack_get_solaris_proc_maps(zend_call_stack *stack)
{
char buffer[4096];
Expand Down Expand Up @@ -771,12 +774,15 @@ static bool zend_call_stack_get_solaris_proc_maps(zend_call_stack *stack)
close(fd);
return r;
}
#endif

static bool zend_call_stack_get_solaris(zend_call_stack *stack)
{
#ifdef HAVE_LIBPROC_H
if (_lwp_self() == 1) {
return zend_call_stack_get_solaris_proc_maps(stack);
}
#endif
return zend_call_stack_get_solaris_pthread(stack);
}
#else
Expand Down
Loading