common.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package vmem
  2. const (
  3. memDecommit = 0x4000
  4. memRelease = 0x8000
  5. )
  6. type systemInfo struct {
  7. wProcessorArchitecture uint16
  8. wReserved uint16
  9. dwPageSize uint32
  10. lpMinimumApplicationAddress uintptr
  11. lpMaximumApplicationAddress uintptr
  12. dwActiveProcessorMask uintptr
  13. dwNumberOfProcessors uint32
  14. dwProcessorType uint32
  15. dwAllocationGranularity uint32
  16. wProcessorLevel uint16
  17. wProcessorRevision uint16
  18. }
  19. // Enumeration of allocation type values.
  20. const (
  21. MemCommit = 0x00001000
  22. MemReserve = 0x00002000
  23. MemReset = 0x00080000
  24. MemResetUndo = 0x10000000
  25. )
  26. // Enumeration of protection levels.
  27. const (
  28. PageNoAccess = 0x01
  29. PageReadOnly = 0x02
  30. PageReadWrite = 0x04
  31. PageWriteCopy = 0x08
  32. PageExecute = 0x10
  33. PageExecuteRead = 0x20
  34. PageExecuteReadWrite = 0x40
  35. PageExecuteWriteCopy = 0x80
  36. )
  37. // RoundDown rounds an address up to a given multiple of size. Size must be a
  38. // power of two.
  39. func RoundDown(addr uint64, size uint64) uint64 {
  40. if size&(size-1) != 0 {
  41. panic("alignment size is not a power of two")
  42. }
  43. return addr &^ (size - 1)
  44. }
  45. // RoundUp rounds an address up to a given multiple of size. Size must be a
  46. // power of two.
  47. func RoundUp(addr uint64, size uint64) uint64 {
  48. return RoundDown(addr+size-1, size)
  49. }