aboutsummaryrefslogtreecommitdiff
path: root/src/common/exec.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-02-08 13:09:52 +0900
committerMichael Paquier <michael@paquier.xyz>2023-02-08 13:09:52 +0900
commit6b4dba711a4ec4be87850108d4f9db12eecd399e (patch)
tree21264989dfc5d2850392cc4f50ffe31092785f51 /src/common/exec.c
parent533cc39b750bd7600e8e2e5cab819a27f1717960 (diff)
downloadpostgresql-6b4dba711a4ec4be87850108d4f9db12eecd399e.tar.gz
postgresql-6b4dba711a4ec4be87850108d4f9db12eecd399e.zip
Make EXEC_BACKEND more convenient on Linux and FreeBSD.
Try to disable ASLR when building in EXEC_BACKEND mode, to avoid random memory mapping failures while testing. For developer use only, no effect on regular builds. This has been originally applied as of f3e7806 for v15~, but recently-added buildfarm member gokiburi tests this configuration on older branches as well, causing it to fail randomly as ASLR would be enabled. Suggested-by: Andres Freund <andres@anarazel.de> Tested-by: Bossart, Nathan <bossartn@amazon.com> Discussion: https://postgr.es/m/20210806032944.m4tz7j2w47mant26%40alap3.anarazel.de Backpatch-through: 12
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 ccdb443ea88..14270083797 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
+
/* Inhibit mingw CRT's auto-globbing of command line arguments */
#if defined(WIN32) && !defined(_MSC_VER)
extern int _CRT_glob = 0; /* 0 turns off globbing; 1 turns it on */
@@ -623,6 +631,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
/*