aboutsummaryrefslogtreecommitdiff
path: root/debian/patches/kfreebsd-support-hotspot.diff
blob: d6ca10c7653d66c0635f8364633ff25015c819f1 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
Description: Initial GNU/kFreeBSD support for openjdk-7 (Hotspot part)
 - Alter build system to consider GNU/kFreeBSD like linux
   since this port is libc based.
   Also treat i386 arch has i686 (uname -m return i386 on BSD*)
   openjdk/hotspot/make/defs.make
 - Use LOCAL_PEERCRED (from kFreeBSD kernel) instead of
   SO_PEERCRED and alter related structs.
   openjdk/hotspot/src/os/linux/vm/attachListener_linux.cpp
 - Use sysctl call instead of sysinfo.
   openjdk/hotspot/src/os/linux/vm/os_linux.cpp
 - Change access to CPU register
   openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
   openjdk/hotspot/agent/src/os/linux/LinuxDebuggerLocal.c
   openjdk/hotspot/agent/src/os/linux/libproc.h
   openjdk/hotspot/agent/src/os/linux/ps_core.c
   (from bsd-port)
 - Fix ptrace usage under freebsd kernel
   openjdk/hotspot/agent/src/os/linux/ps_proc.c
 Should not be keep like this :
 - Undefined UINTPTR_MAX
   openjdk/hotspot/src/share/vm/memory/allocation.hpp
   openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp
Author: Damien Raude-Morvan <drazzib@debian.org>
Last-Update: 2012-03-05
Forwarded: no
--- openjdk/hotspot/agent/src/os/linux/LinuxDebuggerLocal.c.orig
+++ openjdk/hotspot/agent/src/os/linux/LinuxDebuggerLocal.c
@@ -316,7 +316,7 @@
 
 #ifdef i386
 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
-
+#ifdef __linux__
   regs[REG_INDEX(GS)]  = (uintptr_t) gregs.xgs;
   regs[REG_INDEX(FS)]  = (uintptr_t) gregs.xfs;
   regs[REG_INDEX(ES)]  = (uintptr_t) gregs.xes;
@@ -332,7 +332,23 @@
   regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip;
   regs[REG_INDEX(CS)]  = (uintptr_t) gregs.xcs;
   regs[REG_INDEX(SS)]  = (uintptr_t) gregs.xss;
-
+#elif defined(__FreeBSD_kernel__)
+  regs[REG_INDEX(GS)]  = (uintptr_t) gregs.r_gs;
+  regs[REG_INDEX(FS)]  = (uintptr_t) gregs.r_fs;
+  regs[REG_INDEX(ES)]  = (uintptr_t) gregs.r_es;
+  regs[REG_INDEX(DS)]  = (uintptr_t) gregs.r_ds;
+  regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi;
+  regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi;
+  regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp;
+  regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp;
+  regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx;
+  regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx;
+  regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx;
+  regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax;
+  regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip;
+  regs[REG_INDEX(CS)]  = (uintptr_t) gregs.r_cs;
+  regs[REG_INDEX(SS)]  = (uintptr_t) gregs.r_ss;
+#endif
 #endif /* i386 */
 
 #if ia64
@@ -344,7 +360,7 @@
 
 #ifdef amd64
 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
-
+#ifdef __linux__
   regs[REG_INDEX(R15)] = gregs.r15;
   regs[REG_INDEX(R14)] = gregs.r14;
   regs[REG_INDEX(R13)] = gregs.r13;
@@ -370,7 +386,27 @@
   regs[REG_INDEX(ES)] = gregs.es;
   regs[REG_INDEX(FS)] = gregs.fs;
   regs[REG_INDEX(GS)] = gregs.gs;
-
+#elif defined(__FreeBSD_kernel__)
+  regs[REG_INDEX(R15)] = gregs.r_r15;
+  regs[REG_INDEX(R14)] = gregs.r_r14;
+  regs[REG_INDEX(R13)] = gregs.r_r13;
+  regs[REG_INDEX(R12)] = gregs.r_r12;
+  regs[REG_INDEX(RBP)] = gregs.r_rbp;
+  regs[REG_INDEX(RBX)] = gregs.r_rbx;
+  regs[REG_INDEX(R11)] = gregs.r_r11;
+  regs[REG_INDEX(R10)] = gregs.r_r10;
+  regs[REG_INDEX(R9)] = gregs.r_r9;
+  regs[REG_INDEX(R8)] = gregs.r_r8;
+  regs[REG_INDEX(RAX)] = gregs.r_rax;
+  regs[REG_INDEX(RCX)] = gregs.r_rcx;
+  regs[REG_INDEX(RDX)] = gregs.r_rdx;
+  regs[REG_INDEX(RSI)] = gregs.r_rsi;
+  regs[REG_INDEX(RDI)] = gregs.r_rdi;
+  regs[REG_INDEX(RIP)] = gregs.r_rip;
+  regs[REG_INDEX(CS)] = gregs.r_cs;
+  regs[REG_INDEX(RSP)] = gregs.r_rsp;
+  regs[REG_INDEX(SS)] = gregs.r_ss;
+#endif
 #endif /* amd64 */
 
 #if defined(sparc) || defined(sparcv9)
--- openjdk/hotspot/agent/src/os/linux/libproc.h.orig
+++ openjdk/hotspot/agent/src/os/linux/libproc.h
@@ -27,6 +27,10 @@
 
 #include <unistd.h>
 #include <stdint.h>
+#if defined(__FreeBSD_kernel__)
+#include <sys/types.h>
+#include <machine/reg.h>
+#endif
 #include "proc_service.h"
 
 #if defined(sparc) || defined(sparcv9)
@@ -112,6 +116,10 @@
 #define user_regs_struct  pt_regs
 #endif
 
+#if defined(__FreeBSD_kernel__)
+#define user_regs_struct reg
+#endif
+
 // This C bool type must be int for compatibility with Linux calls and
 // it would be a mistake to equivalence it to C++ bool on many platforms
 
--- openjdk/hotspot/agent/src/os/linux/ps_core.c.orig
+++ openjdk/hotspot/agent/src/os/linux/ps_core.c
@@ -539,11 +539,16 @@
       return false;
 
    // copy regs
+#if defined(__FreeBSD_kernel__)
+   memcpy(&newthr->regs, &prstat->pr_reg, sizeof(struct user_regs_struct));
+#else
    memcpy(&newthr->regs, prstat->pr_reg, sizeof(struct user_regs_struct));
+#endif
 
    if (is_debug()) {
       print_debug("integer regset\n");
 #ifdef i386
+#ifdef __linux__
       // print the regset
       print_debug("\teax = 0x%x\n", newthr->regs.eax);
       print_debug("\tebx = 0x%x\n", newthr->regs.ebx);
@@ -554,9 +559,21 @@
       print_debug("\tesi = 0x%x\n", newthr->regs.esi);
       print_debug("\tedi = 0x%x\n", newthr->regs.edi);
       print_debug("\teip = 0x%x\n", newthr->regs.eip);
+#elif defined(__FreeBSD_kernel__)
+      print_debug("\teax = 0x%x\n", newthr->regs.r_eax);
+      print_debug("\tebx = 0x%x\n", newthr->regs.r_ebx);
+      print_debug("\tecx = 0x%x\n", newthr->regs.r_ecx);
+      print_debug("\tedx = 0x%x\n", newthr->regs.r_edx);
+      print_debug("\tesp = 0x%x\n", newthr->regs.r_esp);
+      print_debug("\tebp = 0x%x\n", newthr->regs.r_ebp);
+      print_debug("\tesi = 0x%x\n", newthr->regs.r_esi);
+      print_debug("\tedi = 0x%x\n", newthr->regs.r_edi);
+      print_debug("\teip = 0x%x\n", newthr->regs.r_eip);
+#endif
 #endif
 
 #if defined(amd64) || defined(x86_64)
+#ifdef __linux__
       // print the regset
       print_debug("\tr15 = 0x%lx\n", newthr->regs.r15);
       print_debug("\tr14 = 0x%lx\n", newthr->regs.r14);
@@ -585,6 +602,27 @@
       print_debug("\tes = 0x%lx\n", newthr->regs.es);
       print_debug("\tfs = 0x%lx\n", newthr->regs.fs);
       print_debug("\tgs = 0x%lx\n", newthr->regs.gs);
+#elif defined(__FreeBSD_kernel__)
+      print_debug("\tr15 = 0x%lx\n", newthr->regs.r_r15);
+      print_debug("\tr14 = 0x%lx\n", newthr->regs.r_r14);
+      print_debug("\tr13 = 0x%lx\n", newthr->regs.r_r13);
+      print_debug("\tr12 = 0x%lx\n", newthr->regs.r_r12);
+      print_debug("\trbp = 0x%lx\n", newthr->regs.r_rbp);
+      print_debug("\trbx = 0x%lx\n", newthr->regs.r_rbx);
+      print_debug("\tr11 = 0x%lx\n", newthr->regs.r_r11);
+      print_debug("\tr10 = 0x%lx\n", newthr->regs.r_r10);
+      print_debug("\tr9 = 0x%lx\n", newthr->regs.r_r9);
+      print_debug("\tr8 = 0x%lx\n", newthr->regs.r_r8);
+      print_debug("\trax = 0x%lx\n", newthr->regs.r_rax);
+      print_debug("\trcx = 0x%lx\n", newthr->regs.r_rcx);
+      print_debug("\trdx = 0x%lx\n", newthr->regs.r_rdx);
+      print_debug("\trsi = 0x%lx\n", newthr->regs.r_rsi);
+      print_debug("\trdi = 0x%lx\n", newthr->regs.r_rdi);
+      print_debug("\trip = 0x%lx\n", newthr->regs.r_rip);
+      print_debug("\tcs = 0x%lx\n", newthr->regs.r_cs);
+      print_debug("\trsp = 0x%lx\n", newthr->regs.r_rsp);
+      print_debug("\tss = 0x%lx\n", newthr->regs.r_ss);
+#endif
 #endif
    }
 
--- openjdk/hotspot/agent/src/os/linux/ps_proc.c.orig
+++ openjdk/hotspot/agent/src/os/linux/ps_proc.c
@@ -37,6 +37,18 @@
 #define __WALL          0x40000000  // Copied from /usr/include/linux/wait.h
 #endif
 
+#ifndef PTRACE_PEEKDATA
+#define PTRACE_PEEKDATA PT_READ_D
+#endif
+
+#ifndef PTRACE_ATTACH
+#define PTRACE_ATTACH PT_ATTACH
+#endif
+
+#ifndef PTRACE_DETACH
+#define PTRACE_DETACH PT_DETACH
+#endif
+
 // This file has the libproc implementation specific to live process
 // For core files, refer to ps_core.c
 
@@ -54,7 +66,11 @@
 // before calling process_read_data.
 
 static bool process_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) {
+#if defined(__FreeBSD_kernel__)
+  int rslt;
+#else
   long rslt;
+#endif
   size_t i, words;
   uintptr_t end_addr = addr + size;
   uintptr_t aligned_addr = align(addr, sizeof(long));
@@ -62,36 +78,62 @@
   if (aligned_addr != addr) {
     char *ptr = (char *)&rslt;
     errno = 0;
+#if defined(__FreeBSD_kernel__)
+    rslt = ptrace(PTRACE_PEEKDATA, ph->pid, (caddr_t) aligned_addr, 0);
+#else
     rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
+#endif
     if (errno) {
       print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
       return false;
     }
     for (; aligned_addr != addr; aligned_addr++, ptr++);
+#if defined(__FreeBSD_kernel__)
+    for (; ((intptr_t)aligned_addr % sizeof(int)) && aligned_addr < end_addr;
+#else
     for (; ((intptr_t)aligned_addr % sizeof(long)) && aligned_addr < end_addr;
+#endif
         aligned_addr++)
        *(buf++) = *(ptr++);
   }
 
+#if defined(__FreeBSD_kernel__)
+  words = (end_addr - aligned_addr) / sizeof(int);
+#else
   words = (end_addr - aligned_addr) / sizeof(long);
+#endif
 
   // assert((intptr_t)aligned_addr % sizeof(long) == 0);
   for (i = 0; i < words; i++) {
     errno = 0;
+#if defined(__FreeBSD_kernel__)
+    rslt = ptrace(PTRACE_PEEKDATA, ph->pid, (caddr_t) aligned_addr, 0);
+#else
     rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
+#endif
     if (errno) {
       print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
       return false;
     }
+#if defined(__FreeBSD_kernel__)
+    *(int *)buf = rslt;
+    buf += sizeof(int);
+    aligned_addr += sizeof(int);
+#else
     *(long *)buf = rslt;
     buf += sizeof(long);
     aligned_addr += sizeof(long);
+#endif
   }
 
   if (aligned_addr != end_addr) {
     char *ptr = (char *)&rslt;
     errno = 0;
+#if defined(__FreeBSD_kernel__)
+    rslt = ptrace(PTRACE_PEEKDATA, ph->pid, (caddr_t) aligned_addr, 0);
+#else
     rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
+#endif
     if (errno) {
       print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
       return false;
@@ -130,7 +172,11 @@
 #endif
 
 #ifdef PTRACE_GETREGS_REQ
+#if defined(__FreeBSD_kernel__)
+ if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, (caddr_t) user, 0) < 0) {
+#else
  if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) {
+#endif
    print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp %d\n", pid);
    return false;
  }
@@ -144,7 +190,11 @@
 
 // attach to a process/thread specified by "pid"
 static bool ptrace_attach(pid_t pid) {
+#if defined(__FreeBSD_kernel__)
+  if (ptrace(PTRACE_ATTACH, pid, NULL, 0) < 0) {
+#else
   if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
+#endif
     print_debug("ptrace(PTRACE_ATTACH, ..) failed for %d\n", pid);
     return false;
   } else {
@@ -271,7 +321,11 @@
 
 // detach a given pid
 static bool ptrace_detach(pid_t pid) {
+#if defined(__FreeBSD_kernel__)
+  if (pid && ptrace(PTRACE_DETACH, pid, NULL, 0) < 0) {
+#else
   if (pid && ptrace(PTRACE_DETACH, pid, NULL, NULL) < 0) {
+#endif
     print_debug("ptrace(PTRACE_DETACH, ..) failed for %d\n", pid);
     return false;
   } else {
--- openjdk/hotspot/make/defs.make.orig
+++ openjdk/hotspot/make/defs.make
@@ -132,6 +132,10 @@
   OSNAME=linux
 endif
 
+ifeq ($(OS), GNU/kFreeBSD)
+  OSNAME=linux
+endif
+
 # Determinations of default make arguments and platform specific settings
 MAKE_ARGS=
 
--- openjdk/hotspot/make/linux/Makefile.orig
+++ openjdk/hotspot/make/linux/Makefile
@@ -234,6 +234,9 @@
 SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3%
 OS_VERSION := $(shell uname -r)
 EMPTY_IF_NOT_SUPPORTED = $(filter $(SUPPORTED_OS_VERSION),$(OS_VERSION))
+ifeq ($(shell uname -s), GNU/kFreeBSD)
+EMPTY_IF_NOT_SUPPORTED = supported
+endif
 
 check_os_version:
 ifeq ($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),)
--- openjdk/hotspot/make/linux/makefiles/defs.make.orig
+++ openjdk/hotspot/make/linux/makefiles/defs.make
@@ -91,7 +91,7 @@
 endif
 
 # i686
-ifeq ($(ARCH), i686)
+ifneq (,$(filter i686 i386, $(ARCH)))
   ARCH_DATA_MODEL  = 32
   PLATFORM         = linux-i586
   VM_PLATFORM      = linux_i486
--- openjdk/hotspot/src/os/linux/vm/attachListener_linux.cpp.orig
+++ openjdk/hotspot/src/os/linux/vm/attachListener_linux.cpp
@@ -39,6 +39,10 @@
 #define UNIX_PATH_MAX   sizeof(((struct sockaddr_un *)0)->sun_path)
 #endif
 
+#if defined(__FreeBSD_kernel__)
+#include <sys/ucred.h>
+#endif
+
 // The attach mechanism on Linux uses a UNIX domain socket. An attach listener
 // thread is created at startup or is created on-demand via a signal from
 // the client tool. The attach listener creates a socket and binds it to a file
@@ -337,9 +341,15 @@
 
     // get the credentials of the peer and check the effective uid/guid
     // - check with jeff on this.
+#if defined(LOCAL_PEERCRED) /* GNU/kFreeBSD */
+    struct xucred cred_info;
+    socklen_t optlen = sizeof(cred_info);
+    if (::getsockopt(s, SOL_SOCKET, LOCAL_PEERCRED, (void*)&cred_info, &optlen) == -1) {
+#else
     struct ucred cred_info;
     socklen_t optlen = sizeof(cred_info);
     if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) {
+#endif
       int res;
       RESTARTABLE(::close(s), res);
       continue;
@@ -347,10 +357,14 @@
     uid_t euid = geteuid();
     gid_t egid = getegid();
 
+#if defined(LOCAL_PEERCRED) /* GNU/kFreeBSD */
+    if (cred_info.cr_uid != euid || cred_info.cr_gid != egid) {
+#else
     if (cred_info.uid != euid || cred_info.gid != egid) {
-      int res;
+#endif
+      int res;   
       RESTARTABLE(::close(s), res);
-      continue;
+      continue;  
     }
 
     // peer credential look okay so we read the request
--- openjdk/hotspot/src/os/linux/vm/jvm_linux.cpp.orig
+++ openjdk/hotspot/src/os/linux/vm/jvm_linux.cpp
@@ -169,7 +169,9 @@
   "WINCH",      SIGWINCH,       /* Window size change (4.3 BSD, Sun).  */
   "POLL",       SIGPOLL,        /* Pollable event occurred (System V).  */
   "IO",         SIGIO,          /* I/O now possible (4.2 BSD).  */
+#ifdef SIGPWR
   "PWR",        SIGPWR,         /* Power failure restart (System V).  */
+#endif
 #ifdef SIGSYS
   "SYS",        SIGSYS          /* Bad system call. Only on some Linuxen! */
 #endif
--- openjdk/hotspot/src/os/linux/vm/os_linux.cpp.orig
+++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp
@@ -115,8 +115,13 @@
 # include <semaphore.h>
 # include <fcntl.h>
 # include <string.h>
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# include <sys/param.h>
+# include <sys/sysctl.h>
+#else
 # include <syscall.h>
 # include <sys/sysinfo.h>
+#endif
 # include <gnu/libc-version.h>
 # include <sys/ipc.h>
 # include <sys/shm.h>
@@ -127,6 +132,10 @@
 
 #define MAX_PATH    (2 * K)
 
+#ifndef ETIME
+#define ETIME ETIMEDOUT
+#endif
+
 // for timer info max values which include all bits
 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 #define SEC_IN_NANOSECS  1000000000LL
@@ -208,11 +217,22 @@
 }
 
 julong os::Linux::available_memory() {
+#ifndef __FreeBSD_kernel__
   // values in struct sysinfo are "unsigned long"
   struct sysinfo si;
   sysinfo(&si);
 
   return (julong)si.freeram * si.mem_unit;
+#else
+  int mib[2] = {CTL_HW, HW_USERMEM}, mem;
+  size_t len;
+  len = sizeof(mem);
+  if (sysctl(mib, 2, &mem, &len, NULL, 0) == 0) {
+    return (julong) mem;
+  } else {
+    return 0;
+  }
+#endif
 }
 
 julong os::physical_memory() {
@@ -2161,18 +2181,22 @@
   st->print("Memory:");
   st->print(" %dk page", os::vm_page_size()>>10);
 
+#ifndef __FreeBSD_kernel__
   // values in struct sysinfo are "unsigned long"
   struct sysinfo si;
   sysinfo(&si);
+#endif
 
   st->print(", physical " UINT64_FORMAT "k",
             os::physical_memory() >> 10);
   st->print("(" UINT64_FORMAT "k free)",
             os::available_memory() >> 10);
+#ifndef __FreeBSD_kernel__
   st->print(", swap " UINT64_FORMAT "k",
             ((jlong)si.totalswap * si.mem_unit) >> 10);
   st->print("(" UINT64_FORMAT "k free)",
             ((jlong)si.freeswap * si.mem_unit) >> 10);
+#endif
   st->cr();
 }
 
@@ -5389,6 +5413,7 @@
 int os::fork_and_exec(char* cmd) {
   const char * argv[4] = {"sh", "-c", cmd, NULL};
 
+#ifdef __linux__
   // fork() in LinuxThreads/NPTL is not async-safe. It needs to run
   // pthread_atfork handlers and reset pthread library. All we need is a
   // separate process to execve. Make a direct syscall to fork process.
@@ -5396,6 +5421,9 @@
   // the best...
   pid_t pid = NOT_IA64(syscall(__NR_fork);)
               IA64_ONLY(fork();)
+#else
+  pid_t pid = fork();
+#endif
 
   if (pid < 0) {
     // fork failed
@@ -5404,6 +5432,7 @@
   } else if (pid == 0) {
     // child process
 
+#ifdef __linux__
     // execve() in LinuxThreads will call pthread_kill_other_threads_np()
     // first to kill every thread on the thread list. Because this list is
     // not reset by fork() (see notes above), execve() will instead kill
@@ -5413,6 +5442,9 @@
     // above.
     NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);)
     IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);)
+#else
+    execve("/bin/sh", (char* const*)argv, environ);
+#endif
 
     // execve failed
     _exit(-1);
--- openjdk/hotspot/src/os/posix/launcher/java_md.c.orig
+++ openjdk/hotspot/src/os/posix/launcher/java_md.c
@@ -41,7 +41,7 @@
 #include "version_comp.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
 #include <pthread.h>
 #else
 #include <thread.h>
@@ -89,7 +89,7 @@
  *      A collection of useful strings. One should think of these as #define
  *      entries, but actual strings can be more efficient (with many compilers).
  */
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
 static const char *system_dir   = "/usr/java";
 static const char *user_dir     = "/java";
 #else /* Solaris */
@@ -426,7 +426,7 @@
       runpath = getenv("LD_LIBRARY_PATH");
 #endif /* __sun */
 
-#ifdef __linux
+#if defined(__linux__) || defined(__GLIBC__)
       /*
        * On linux, if a binary is running as sgid or suid, glibc sets
        * LD_LIBRARY_PATH to the empty string for security purposes.  (In
@@ -792,7 +792,7 @@
 jboolean
 GetApplicationHome(char *buf, jint bufsize)
 {
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
     char *execname = GetExecname();
     if (execname) {
         strncpy(buf, execname, bufsize-1);
@@ -961,7 +961,7 @@
             }
         }
     }
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__GLIBC__)
     {
         const char* self = "/proc/self/exe";
         char buf[PATH_MAX+1];
@@ -1821,7 +1821,7 @@
 int
 ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
     int rslt;
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
     pthread_t tid;
     pthread_attr_t attr;
     pthread_attr_init(&attr);
--- openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp.orig
+++ openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
@@ -81,6 +81,7 @@
 # include <ucontext.h>
 # include <fpu_control.h>
 
+#ifdef __linux__
 #ifdef AMD64
 #define REG_SP REG_RSP
 #define REG_PC REG_RIP
@@ -94,6 +95,54 @@
 #define SPELL_REG_SP "esp"
 #define SPELL_REG_FP "ebp"
 #endif // AMD64
+#endif
+
+#if defined(__FreeBSD_kernel__)
+#define context_trapno uc_mcontext.mc_trapno
+#ifdef AMD64
+#define SPELL_REG_SP "rsp"
+#define SPELL_REG_FP "rbp"
+#define context_sp uc_mcontext.mc_rsp
+#define context_pc uc_mcontext.mc_rip
+#define context_fp uc_mcontext.mc_rbp
+#define context_rip uc_mcontext.mc_rip
+#define context_rsp uc_mcontext.mc_rsp
+#define context_rbp uc_mcontext.mc_rbp
+#define context_flags uc_mcontext.mc_flags
+#define context_err uc_mcontext.mc_err
+#define context_rax uc_mcontext.mc_rax
+#define context_rbx uc_mcontext.mc_rbx
+#define context_rcx uc_mcontext.mc_rcx
+#define context_rdx uc_mcontext.mc_rdx
+#define context_rsi uc_mcontext.mc_rsi
+#define context_rdi uc_mcontext.mc_rdi
+#define context_r8 uc_mcontext.mc_r8
+#define context_r9 uc_mcontext.mc_r9
+#define context_r10 uc_mcontext.mc_r10
+#define context_r11 uc_mcontext.mc_r11
+#define context_r12 uc_mcontext.mc_r12
+#define context_r13 uc_mcontext.mc_r13
+#define context_r14 uc_mcontext.mc_r14
+#define context_r15 uc_mcontext.mc_r15
+#else
+#define SPELL_REG_SP "esp"
+#define SPELL_REG_FP "ebp"
+#define context_sp uc_mcontext.mc_esp
+#define context_pc uc_mcontext.mc_eip
+#define context_fp uc_mcontext.mc_ebp
+#define context_eip uc_mcontext.mc_eip
+#define context_esp uc_mcontext.mc_esp
+#define context_eax uc_mcontext.mc_eax
+#define context_ebx uc_mcontext.mc_ebx
+#define context_ecx uc_mcontext.mc_ecx
+#define context_edx uc_mcontext.mc_edx
+#define context_ebp uc_mcontext.mc_ebp
+#define context_esi uc_mcontext.mc_esi
+#define context_edi uc_mcontext.mc_edi
+#define context_eflags uc_mcontext.mc_eflags
+#define context_trapno uc_mcontext.mc_trapno
+#endif // AMD64
+#endif
 
 address os::current_stack_pointer() {
 #ifdef SPARC_WORKS
@@ -119,15 +168,27 @@
 }
 
 address os::Linux::ucontext_get_pc(ucontext_t * uc) {
+#if defined(__FreeBSD_kernel__)
+  return (address)uc->context_pc;
+#else
   return (address)uc->uc_mcontext.gregs[REG_PC];
+#endif
 }
 
 intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) {
+#if defined(__FreeBSD_kernel__)
+  return (intptr_t*)uc->context_sp;
+#else
   return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
+#endif
 }
 
 intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) {
+#if defined(__FreeBSD_kernel__)
+  return (intptr_t*)uc->context_fp;
+#else
   return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
+#endif
 }
 
 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
@@ -279,12 +340,20 @@
     pc = (address) os::Linux::ucontext_get_pc(uc);
 
     if (pc == (address) Fetch32PFI) {
+#if defined(__FreeBSD_kernel__)
+       uc->context_pc = intptr_t(Fetch32Resume) ;
+#else
        uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ;
+#endif
        return 1 ;
     }
 #ifdef AMD64
     if (pc == (address) FetchNPFI) {
+#if defined(__FreeBSD_kernel__)
+       uc->context_pc = intptr_t (FetchNResume) ;
+#else
        uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ;
+#endif
        return 1 ;
     }
 #endif // AMD64
@@ -430,7 +499,11 @@
   // Furthermore, a false-positive should be harmless.
   if (UnguardOnExecutionViolation > 0 &&
       (sig == SIGSEGV || sig == SIGBUS) &&
+#if defined(__FreeBSD_kernel__)
+      uc->context_trapno == trap_page_fault) {
+#else
       uc->uc_mcontext.gregs[REG_TRAPNO] == trap_page_fault) {
+#endif
     int page_size = os::vm_page_size();
     address addr = (address) info->si_addr;
     address pc = os::Linux::ucontext_get_pc(uc);
@@ -500,7 +573,11 @@
     // save all thread context in case we need to restore it
     if (thread != NULL) thread->set_saved_exception_pc(pc);
 
+#if defined(__FreeBSD_kernel__)
+    uc->context_pc = (intptr_t)stub;
+#else
     uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub;
+#endif
     return true;
   }
 
@@ -752,6 +829,7 @@
 
   ucontext_t *uc = (ucontext_t*)context;
   st->print_cr("Registers:");
+#ifdef __linux__
 #ifdef AMD64
   st->print(  "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]);
   st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]);
@@ -794,6 +872,48 @@
   st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]);
   st->print(", CR2=" INTPTR_FORMAT, uc->uc_mcontext.cr2);
 #endif // AMD64
+#elif defined(__FreeBSD_kernel__)
+#ifdef AMD64
+  st->print(  "RAX=" INTPTR_FORMAT, uc->context_rax);
+  st->print(", RBX=" INTPTR_FORMAT, uc->context_rbx);
+  st->print(", RCX=" INTPTR_FORMAT, uc->context_rcx);
+  st->print(", RDX=" INTPTR_FORMAT, uc->context_rdx);
+  st->cr();
+  st->print(  "RSP=" INTPTR_FORMAT, uc->context_rsp);
+  st->print(", RBP=" INTPTR_FORMAT, uc->context_rbp);
+  st->print(", RSI=" INTPTR_FORMAT, uc->context_rsi);
+  st->print(", RDI=" INTPTR_FORMAT, uc->context_rdi);
+  st->cr();
+  st->print(  "R8 =" INTPTR_FORMAT, uc->context_r8);
+  st->print(", R9 =" INTPTR_FORMAT, uc->context_r9);
+  st->print(", R10=" INTPTR_FORMAT, uc->context_r10);
+  st->print(", R11=" INTPTR_FORMAT, uc->context_r11);
+  st->cr();
+  st->print(  "R12=" INTPTR_FORMAT, uc->context_r12);
+  st->print(", R13=" INTPTR_FORMAT, uc->context_r13);
+  st->print(", R14=" INTPTR_FORMAT, uc->context_r14);
+  st->print(", R15=" INTPTR_FORMAT, uc->context_r15);
+  st->cr();
+  st->print(  "RIP=" INTPTR_FORMAT, uc->context_rip);
+  st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_flags);
+  st->print(", ERR=" INTPTR_FORMAT, uc->context_err);
+  st->cr();
+  st->print("  TRAPNO=" INTPTR_FORMAT, uc->context_trapno);
+#else
+  st->print(  "EAX=" INTPTR_FORMAT, uc->context_eax);
+  st->print(", EBX=" INTPTR_FORMAT, uc->context_ebx);
+  st->print(", ECX=" INTPTR_FORMAT, uc->context_ecx);
+  st->print(", EDX=" INTPTR_FORMAT, uc->context_edx);
+  st->cr();
+  st->print(  "ESP=" INTPTR_FORMAT, uc->context_esp);
+  st->print(", EBP=" INTPTR_FORMAT, uc->context_ebp);
+  st->print(", ESI=" INTPTR_FORMAT, uc->context_esi);
+  st->print(", EDI=" INTPTR_FORMAT, uc->context_edi);
+  st->cr();
+  st->print(  "EIP=" INTPTR_FORMAT, uc->context_eip);
+  st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_eflags);
+#endif // AMD64
+#endif
   st->cr();
   st->cr();
 
@@ -824,6 +944,7 @@
 
   // this is only for the "general purpose" registers
 
+#ifdef __linux__
 #ifdef AMD64
   st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]);
   st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]);
@@ -851,6 +972,35 @@
   st->print("ESI="); print_location(st, uc->uc_mcontext.gregs[REG_ESI]);
   st->print("EDI="); print_location(st, uc->uc_mcontext.gregs[REG_EDI]);
 #endif // AMD64
+#elif defined(__FreeBSD_kernel__)
+#ifdef AMD64
+  st->print("RAX="); print_location(st, uc->context_rax);
+  st->print("RBX="); print_location(st, uc->context_rbx);
+  st->print("RCX="); print_location(st, uc->context_rcx);
+  st->print("RDX="); print_location(st, uc->context_rdx);
+  st->print("RSP="); print_location(st, uc->context_rsp);
+  st->print("RBP="); print_location(st, uc->context_rbp);
+  st->print("RSI="); print_location(st, uc->context_rsi);
+  st->print("RDI="); print_location(st, uc->context_rdi);
+  st->print("R8 ="); print_location(st, uc->context_r8);
+  st->print("R9 ="); print_location(st, uc->context_r9);
+  st->print("R10="); print_location(st, uc->context_r10);
+  st->print("R11="); print_location(st, uc->context_r11);
+  st->print("R12="); print_location(st, uc->context_r12);
+  st->print("R13="); print_location(st, uc->context_r13);
+  st->print("R14="); print_location(st, uc->context_r14);
+  st->print("R15="); print_location(st, uc->context_r15);
+#else
+  st->print("EAX="); print_location(st, uc->context_eax);
+  st->print("EBX="); print_location(st, uc->context_ebx);
+  st->print("ECX="); print_location(st, uc->context_ecx);
+  st->print("EDX="); print_location(st, uc->context_edx);
+  st->print("ESP="); print_location(st, uc->context_esp);
+  st->print("EBP="); print_location(st, uc->context_ebp);
+  st->print("ESI="); print_location(st, uc->context_esi);
+  st->print("EDI="); print_location(st, uc->context_edi);
+#endif // AMD64
+#endif
 
   st->cr();
 }
--- openjdk/hotspot/src/share/vm/memory/allocation.hpp.orig
+++ openjdk/hotspot/src/share/vm/memory/allocation.hpp
@@ -218,9 +218,9 @@
   void signal_out_of_memory(size_t request, const char* whence) const;
 
   void check_for_overflow(size_t request, const char* whence) const {
-    if (UINTPTR_MAX - request < (uintptr_t)_hwm) {
-      signal_out_of_memory(request, whence);
-    }
+//    if (UINTPTR_MAX - request < (uintptr_t)_hwm) {
+//      signal_out_of_memory(request, whence);
+//    }
  }
 
  public:
--- openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp.orig
+++ openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp
@@ -970,11 +970,11 @@
   // The product of bbNo and _state_len can get large if there are lots of
   // basic blocks and stack/locals/monitors.  Need to check to make sure
   // we don't overflow the capacity of a pointer.
-  if ((unsigned)bbNo > UINTPTR_MAX / sizeof(CellTypeState) / _state_len) {
-    report_error("The amount of memory required to analyze this method "
-                 "exceeds addressable range");
-    return;
-  }
+//  if ((unsigned)bbNo > UINTPTR_MAX / sizeof(CellTypeState) / _state_len) {
+//    report_error("The amount of memory required to analyze this method "
+//                 "exceeds addressable range");
+//    return;
+//  }
 
   CellTypeState *basicBlockState =
       NEW_RESOURCE_ARRAY(CellTypeState, bbNo * _state_len);