patch-code_qcommon_vm_x86_c 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. $OpenBSD: patch-code_qcommon_vm_x86_c,v 1.1 2012/03/18 16:48:16 kirby Exp $
  2. * Add PROT_READ to x86 and x86_64 VM mmap calls[1]
  3. [1] According to OpenBSD's mmap(2):
  4. BUGS
  5. Due to a limitation of the current vm system (see uvm(9)), mapping
  6. descriptors PROT_WRITE without also specifying PROT_READ is useless
  7. (results in a segmentation fault when first accessing the mapping). This
  8. means that such descriptors must be opened with O_RDWR, which requires
  9. both read and write permissions on the underlying object.
  10. --- code/qcommon/vm_x86.c.orig Sat Dec 24 14:29:32 2011
  11. +++ code/qcommon/vm_x86.c Sun Mar 11 15:22:08 2012
  12. @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  13. /* need this on NX enabled systems (i386 with PAE kernel or
  14. * noexec32=on x86_64) */
  15. -#if defined(__linux__) || defined(__FreeBSD__)
  16. +#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
  17. #define VM_X86_MMAP
  18. #endif
  19. @@ -1094,7 +1094,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
  20. // copy to an exact size buffer on the hunk
  21. vm->codeLength = compiledOfs;
  22. #ifdef VM_X86_MMAP
  23. - vm->codeBase = mmap(NULL, compiledOfs, PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
  24. + vm->codeBase = mmap(NULL, compiledOfs, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
  25. if(vm->codeBase == MAP_FAILED)
  26. Com_Error(ERR_FATAL, "VM_CompileX86: can't mmap memory");
  27. #elif _WIN32