summaryrefslogtreecommitdiff
path: root/missing
diff options
context:
space:
mode:
Diffstat (limited to 'missing')
-rw-r--r--missing/dtoa.c11
-rw-r--r--missing/explicit_bzero.c5
-rw-r--r--missing/procstat_vm.c34
-rw-r--r--missing/setproctitle.c46
4 files changed, 65 insertions, 31 deletions
diff --git a/missing/dtoa.c b/missing/dtoa.c
index b7a8302875..bce2cb22a1 100644
--- a/missing/dtoa.c
+++ b/missing/dtoa.c
@@ -183,7 +183,10 @@
#undef Long
#undef ULong
+#include <assert.h>
#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
#if (INT_MAX >> 30) && !(INT_MAX >> 31)
#define Long int
@@ -195,7 +198,7 @@
#error No 32bit integer
#endif
-#if HAVE_LONG_LONG
+#if defined(HAVE_LONG_LONG) && (HAVE_LONG_LONG)
#define Llong LONG_LONG
#else
#define NO_LONG_LONG
@@ -221,12 +224,12 @@
#ifdef MALLOC
extern void *MALLOC(size_t);
#else
-#define MALLOC xmalloc
+#define MALLOC malloc
#endif
#ifdef FREE
extern void FREE(void*);
#else
-#define FREE xfree
+#define FREE free
#endif
#ifndef NO_SANITIZE
#define NO_SANITIZE(x, y) y
@@ -502,7 +505,7 @@ extern double rnd_prod(double, double), rnd_quot(double, double);
#endif
#ifndef ATOMIC_PTR_CAS
-#define ATOMIC_PTR_CAS(var, old, new) ((var) = (new), (old))
+#define ATOMIC_PTR_CAS(var, old, new) ((var) = (new), (void *)(old))
#endif
#ifndef LIKELY
#define LIKELY(x) (x)
diff --git a/missing/explicit_bzero.c b/missing/explicit_bzero.c
index 1220e5f9ad..59417e158e 100644
--- a/missing/explicit_bzero.c
+++ b/missing/explicit_bzero.c
@@ -1,12 +1,9 @@
#ifndef __STDC_WANT_LIB_EXT1__
-#define __STDC_WANT_LIB_EXT1__ 1
+#define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s() */
#endif
#include "ruby/missing.h"
#include <string.h>
-#ifdef HAVE_MEMSET_S
-# include <string.h>
-#endif
#ifdef _WIN32
#include <windows.h>
diff --git a/missing/procstat_vm.c b/missing/procstat_vm.c
index 76fd8f61ba..155ee355d1 100644
--- a/missing/procstat_vm.c
+++ b/missing/procstat_vm.c
@@ -6,7 +6,7 @@
# define KVME_TYPE_MGTDEVICE 8
# endif
void
-procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
+procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp, FILE *errout)
{
struct kinfo_vmentry *freep, *kve;
int ptrwidth;
@@ -17,7 +17,7 @@ procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
#else
ptrwidth = 2*sizeof(void *) + 2;
#endif
- fprintf(stderr, "%*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n",
+ fprintf(errout, "%*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n",
ptrwidth, "START", ptrwidth, "END", "PRT", "RES",
"P""RES", "REF", "SHD", "FL", "TP", "PATH");
@@ -30,20 +30,20 @@ procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
return;
for (i = 0; i < cnt; i++) {
kve = &freep[i];
- fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start);
- fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end);
- fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-");
- fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-");
- fprintf(stderr, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-");
- fprintf(stderr, "%4d ", kve->kve_resident);
- fprintf(stderr, "%4d ", kve->kve_private_resident);
- fprintf(stderr, "%3d ", kve->kve_ref_count);
- fprintf(stderr, "%3d ", kve->kve_shadow_count);
- fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-");
- fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" :
+ fprintf(errout, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start);
+ fprintf(errout, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end);
+ fprintf(errout, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-");
+ fprintf(errout, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-");
+ fprintf(errout, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-");
+ fprintf(errout, "%4d ", kve->kve_resident);
+ fprintf(errout, "%4d ", kve->kve_private_resident);
+ fprintf(errout, "%3d ", kve->kve_ref_count);
+ fprintf(errout, "%3d ", kve->kve_shadow_count);
+ fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-");
+ fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" :
"-");
- fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
- fprintf(stderr, "%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" :
+ fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
+ fprintf(errout, "%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" :
kve->kve_flags & KVME_FLAG_GROWS_DOWN ? "D" : "-");
switch (kve->kve_type) {
case KVME_TYPE_NONE:
@@ -78,8 +78,8 @@ procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
str = "??";
break;
}
- fprintf(stderr, "%-2s ", str);
- fprintf(stderr, "%-s\n", kve->kve_path);
+ fprintf(errout, "%-2s ", str);
+ fprintf(errout, "%-s\n", kve->kve_path);
}
free(freep);
}
diff --git a/missing/setproctitle.c b/missing/setproctitle.c
index 811829c060..1522657b9b 100644
--- a/missing/setproctitle.c
+++ b/missing/setproctitle.c
@@ -80,10 +80,21 @@ static char **argv1_addr = NULL;
#endif /* HAVE_SETPROCTITLE */
+#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV
+# define ALLOCATE_ENVIRON 1
+#else
+# define ALLOCATE_ENVIRON 0
+#endif
+
+#if ALLOCATE_ENVIRON
+static char **orig_environ = NULL;
+static char **alloc_environ = NULL;
+#endif
+
void
compat_init_setproctitle(int argc, char *argv[])
{
-#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV
+#if ALLOCATE_ENVIRON
extern char **environ;
char *lastargv = NULL;
char *lastenvp = NULL;
@@ -100,9 +111,13 @@ compat_init_setproctitle(int argc, char *argv[])
return;
/* Fail if we can't allocate room for the new environment */
- for (i = 0; envp[i] != NULL; i++)
- ;
- if ((environ = calloc(i + 1, sizeof(*environ))) == NULL) {
+ for (i = 0; envp[i] != NULL; i++);
+
+ orig_environ = environ;
+
+ alloc_environ = xcalloc(i + 1, sizeof(*environ));
+ environ = xcalloc(i + 1, sizeof(*environ));
+ if (environ == NULL) {
environ = envp; /* put it back */
return;
}
@@ -129,12 +144,31 @@ compat_init_setproctitle(int argc, char *argv[])
argv_env_len = lastenvp - argv[0];
for (i = 0; envp[i] != NULL; i++)
- environ[i] = ruby_strdup(envp[i]);
- environ[i] = NULL;
+ alloc_environ[i] = environ[i] = ruby_strdup(envp[i]);
+ alloc_environ[i] = environ[i] = NULL;
#endif /* SPT_REUSEARGV */
}
+void
+ruby_free_proctitle(void)
+{
+#if ALLOCATE_ENVIRON
+ extern char **environ;
+
+ if (!orig_environ) return; /* environ is allocated by OS */
+
+ for (int i = 0; alloc_environ[i] != NULL; i++) {
+ xfree(alloc_environ[i]);
+ }
+ xfree(alloc_environ);
+ xfree(environ);
+
+ environ = orig_environ;
+#endif
+}
+
#ifndef HAVE_SETPROCTITLE
+
void
setproctitle(const char *fmt, ...)
{