summaryrefslogtreecommitdiffstats
path: root/www/firefox/files/patch-bug789693
blob: 1d2b790a35d52abefef5da1682a9a72f66601c0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
--- toolkit/components/startup/nsAppStartup.cpp
+++ toolkit/components/startup/nsAppStartup.cpp
@@ -50,18 +50,41 @@
 #include <sys/syscall.h>
 #endif
 
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) || defined(__DragonFly__) || defined(__FreeBSD__) \
+  || defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/param.h>
 #include <sys/sysctl.h>
 #endif
 
-#ifdef __OpenBSD__
-#include <sys/param.h>
-#include <sys/sysctl.h>
+#if defined(__DragonFly__) || defined(__FreeBSD__)
+#include <sys/user.h>
 #endif
 
 #include "mozilla/Telemetry.h"
 #include "mozilla/StartupTimeline.h"
 
+#if defined(__NetBSD__)
+#undef KERN_PROC
+#define KERN_PROC KERN_PROC2
+#define KINFO_PROC struct kinfo_proc2
+#else
+#define KINFO_PROC struct kinfo_proc
+#endif
+
+#if defined(XP_MACOSX)
+#define KP_START_SEC kp_proc.p_un.__p_starttime.tv_sec
+#define KP_START_USEC kp_proc.p_un.__p_starttime.tv_usec
+#elif defined(__DragonFly__)
+#define KP_START_SEC kp_start.tv_sec
+#define KP_START_USEC kp_start.tv_usec
+#elif defined(__FreeBSD__)
+#define KP_START_SEC ki_start.tv_sec
+#define KP_START_USEC ki_start.tv_usec
+#else
+#define KP_START_SEC p_ustart_sec
+#define KP_START_USEC p_ustart_usec
+#endif
+
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 #define kPrefLastSuccess "toolkit.startup.last_success"
@@ -836,42 +859,30 @@ CalculateProcessCreationTimestamp()
 #endif
   return timestamp;
 }
-#elif defined(XP_MACOSX)
+#elif defined(XP_MACOSX) || defined(__DragonFly__) || defined(__FreeBSD__) \
+  || defined(__NetBSD__) || defined(__OpenBSD__)
 static PRTime
 CalculateProcessCreationTimestamp()
 {
-  int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
-  size_t buffer_size;
-  if (sysctl(mib, 4, NULL, &buffer_size, NULL, 0))
-    return 0;
+  int mib[] = {
+    CTL_KERN,
+    KERN_PROC,
+    KERN_PROC_PID,
+    getpid(),
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+    sizeof(KINFO_PROC),
+    1,
+#endif
+  };
+  u_int miblen = sizeof(mib) / sizeof(mib[0]);
 
-  struct kinfo_proc *proc = (kinfo_proc*) malloc(buffer_size);  
-  if (sysctl(mib, 4, proc, &buffer_size, NULL, 0)) {
-    free(proc);
-    return 0;
-  }
-  PRTime starttime = static_cast<PRTime>(proc->kp_proc.p_un.__p_starttime.tv_sec) * PR_USEC_PER_SEC;
-  starttime += proc->kp_proc.p_un.__p_starttime.tv_usec;
-  free(proc);
-  return starttime;
-}
-#elif defined(__OpenBSD__)
-static PRTime
-CalculateProcessCreationTimestamp()
-{
-  int mib[6] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid(), sizeof(struct kinfo_proc), 1 };
-  size_t buffer_size;
-  if (sysctl(mib, 6, NULL, &buffer_size, NULL, 0))
+  KINFO_PROC proc;
+  size_t buffer_size = sizeof(proc);
+  if (sysctl(mib, miblen, &proc, &buffer_size, NULL, 0))
     return 0;
 
-  struct kinfo_proc *proc = (struct kinfo_proc*) malloc(buffer_size);
-  if (sysctl(mib, 6, proc, &buffer_size, NULL, 0)) {
-    free(proc);
-    return 0;
-  }
-  PRTime starttime = static_cast<PRTime>(proc->p_ustart_sec) * PR_USEC_PER_SEC;
-  starttime += proc->p_ustart_usec;
-  free(proc);
+  PRTime starttime = static_cast<PRTime>(proc.KP_START_SEC) * PR_USEC_PER_SEC;
+  starttime += proc.KP_START_USEC;
   return starttime;
 }
 #else
OpenPOWER on IntegriCloud