Advertisement
Guest User

add SetProcessWorkingSetSize to wine

a guest
Apr 13th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. --- wine-1.5.20/dlls/kernel32/process.c.orig 2012-12-21 14:14:41.000000000 -0500
  2. +++ wine-1.5.20/dlls/kernel32/process.c 2012-12-29 17:20:33.052096000 -0500
  3. @@ -47,6 +47,10 @@
  4. #ifdef HAVE_UNISTD_H
  5. # include <unistd.h>
  6. #endif
  7. +#include <sys/resource.h>
  8. +#ifdef HAVE_SYS_MMAN_H
  9. +#include <sys/mman.h>
  10. +#endif
  11. #ifdef __APPLE__
  12. #include <CoreFoundation/CoreFoundation.h>
  13. #include <pthread.h>
  14. @@ -3273,11 +3277,61 @@
  15. BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T minset,
  16. SIZE_T maxset)
  17. {
  18. - WARN("(%p,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
  19. + struct rlimit limits;
  20. +
  21. + if (hProcess != GetCurrentProcess()) {
  22. + FIXME("Cannot get info for another process");
  23. + SetLastError(ERROR_INVALID_PARAMETER);
  24. + return FALSE;
  25. + }
  26. +
  27. + TRACE("(%p,%ld,%ld)\n",hProcess,minset,maxset);
  28. +
  29. if(( minset == (SIZE_T)-1) && (maxset == (SIZE_T)-1)) {
  30. - /* Trim the working set to zero */
  31. - /* Swap the process out of physical RAM */
  32. +#ifdef HAVE_SYS_MMAN
  33. + if (munlockall() == -1) {
  34. + switch(errno) {
  35. + case ENOSYS:
  36. + SetLastError(ERROR_INVALID_FUNCTION);
  37. + break;
  38. + default:
  39. + FIXME("Converting munlockall errno %d to ERROR_GEN_FAILURE\n", errno);
  40. + SetLastError(ERROR_GEN_FAILURE);
  41. + break;
  42. + }
  43. + return FALSE;
  44. + }
  45. +
  46. + limits.rlim_cur = 0;
  47. + limits.rlim_max = 0;
  48. +#else
  49. + FIXME("(%p,%ld,%ld): stub\n",hProcess,minset,maxset);
  50. + SetLastError(ERROR_INVALID_PARAMETER);
  51. + return FALSE;
  52. +#endif
  53. + }
  54. + else {
  55. + limits.rlim_cur = maxset;
  56. + limits.rlim_max = maxset;
  57. + }
  58. +
  59. + if (setrlimit(RLIMIT_MEMLOCK, &limits) == -1) {
  60. + switch(errno) {
  61. + case EINVAL:
  62. + SetLastError(ERROR_INVALID_PARAMETER);
  63. + break;
  64. + case EPERM:
  65. + SetLastError(ERROR_ACCESS_DENIED);
  66. + break;
  67. + default:
  68. + FIXME("Converting errno %d to ERROR_GEN_FAILURE\n", errno);
  69. + SetLastError(ERROR_GEN_FAILURE);
  70. + break;
  71. + }
  72. +
  73. + return FALSE;
  74. }
  75. +
  76. return TRUE;
  77. }
  78.  
  79. @@ -3295,10 +3349,45 @@
  80. BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess, PSIZE_T minset,
  81. PSIZE_T maxset)
  82. {
  83. - FIXME("(%p,%p,%p): stub\n",hProcess,minset,maxset);
  84. - /* 32 MB working set size */
  85. - if (minset) *minset = 32*1024*1024;
  86. - if (maxset) *maxset = 32*1024*1024;
  87. + struct rlimit limits;
  88. +
  89. + if (hProcess != GetCurrentProcess()) {
  90. + FIXME("Cannot get info for another process");
  91. + SetLastError(ERROR_INVALID_PARAMETER);
  92. + return FALSE;
  93. + }
  94. +
  95. + TRACE("(%p,%p,%p)\n",hProcess,minset,maxset);
  96. +
  97. + /* 32 MB minimum working set size - no rlimit for this */
  98. + if (minset)
  99. + *minset = 32*1024*1024;
  100. +
  101. + if (maxset) {
  102. + if (getrlimit(RLIMIT_MEMLOCK, &limits) == -1) {
  103. + switch(errno) {
  104. + case EINVAL:
  105. + SetLastError(ERROR_INVALID_PARAMETER);
  106. + break;
  107. + case EPERM:
  108. + SetLastError(ERROR_ACCESS_DENIED);
  109. + break;
  110. + default:
  111. + FIXME("Converting errno %d to ERROR_GEN_FAILURE\n", errno);
  112. + SetLastError(ERROR_GEN_FAILURE);
  113. + break;
  114. + }
  115. +
  116. + return FALSE;
  117. + }
  118. +
  119. + if (limits.rlim_max == RLIM_INFINITY)
  120. + *maxset = MAXUINT_PTR;
  121. + else
  122. + *maxset = limits.rlim_max;
  123. + }
  124. +
  125. +
  126. return TRUE;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement