aboutsummaryrefslogtreecommitdiff
path: root/src/common/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/exec.c')
-rw-r--r--src/common/exec.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/exec.c b/src/common/exec.c
index 9428b7393c2..95ef13c322d 100644
--- a/src/common/exec.c
+++ b/src/common/exec.c
@@ -25,6 +25,14 @@
#include <sys/wait.h>
#include <unistd.h>
+#ifdef EXEC_BACKEND
+#if defined(HAVE_SYS_PERSONALITY_H)
+#include <sys/personality.h>
+#elif defined(HAVE_SYS_PROCCTL_H)
+#include <sys/procctl.h>
+#endif
+#endif
+
/*
* Hacky solution to allow expressing both frontend and backend error reports
* in one macro call. First argument of log_error is an errcode() call of
@@ -470,6 +478,31 @@ set_pglocale_pgservice(const char *argv0, const char *app)
}
}
+#ifdef EXEC_BACKEND
+/*
+ * For the benefit of PostgreSQL developers testing EXEC_BACKEND on Unix
+ * systems (code paths normally exercised only on Windows), provide a way to
+ * disable address space layout randomization, if we know how on this platform.
+ * Otherwise, backends may fail to attach to shared memory at the fixed address
+ * chosen by the postmaster. (See also the macOS-specific hack in
+ * sysv_shmem.c.)
+ */
+int
+pg_disable_aslr(void)
+{
+#if defined(HAVE_SYS_PERSONALITY_H)
+ return personality(ADDR_NO_RANDOMIZE);
+#elif defined(HAVE_SYS_PROCCTL_H) && defined(PROC_ASLR_FORCE_DISABLE)
+ int data = PROC_ASLR_FORCE_DISABLE;
+
+ return procctl(P_PID, 0, PROC_ASLR_CTL, &data);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+#endif
+
#ifdef WIN32
/*