Commit 6cd673b4eb6ec69f90031359731cc174e6148453

Authored by Georg Hopp
1 parent e8a21ace

this change hopefully makes the shm trick work on amd64

Showing 1 changed file with 14 additions and 20 deletions
@@ -30,7 +30,6 @@ ctor(void * _this, va_list * params) @@ -30,7 +30,6 @@ ctor(void * _this, va_list * params)
30 long psize = sysconf(_SC_PAGESIZE); 30 long psize = sysconf(_SC_PAGESIZE);
31 size_t size; 31 size_t size;
32 int shm; 32 int shm;
33 - void * shm_addr;  
34 33
35 this->shm_name = malloc(strlen(shm_name) + 1); 34 this->shm_name = malloc(strlen(shm_name) + 1);
36 strcpy(this->shm_name, shm_name); 35 strcpy(this->shm_name, shm_name);
@@ -52,25 +51,24 @@ ctor(void * _this, va_list * params) @@ -52,25 +51,24 @@ ctor(void * _this, va_list * params)
52 ftruncate(shm, this->bsize); 51 ftruncate(shm, this->bsize);
53 } 52 }
54 53
55 - shm_addr = mmap (0, this->bsize<<1,  
56 - PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0);  
57 - if (shm_addr == MAP_FAILED)  
58 - break;  
59 -  
60 - munmap(shm_addr, this->bsize<<1);  
61 -  
62 - this->buffer = mmap (shm_addr, this->bsize, 54 + this->buffer = mmap (0, this->bsize<<1,
63 PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); 55 PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0);
64 if (this->buffer == MAP_FAILED) { 56 if (this->buffer == MAP_FAILED) {
65 - shm_addr = NULL; 57 + this->buffer = NULL;
66 break; 58 break;
67 } 59 }
68 60
69 - this->mirror = mmap (shm_addr + this->bsize, this->bsize, 61 + this->mirror = mmap (this->buffer + this->bsize, this->bsize,
70 PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); 62 PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0);
71 - if (this->mirror != shm_addr + this->bsize) {  
72 - shm_addr = NULL;  
73 - break; 63 + if (this->mirror != this->buffer + this->bsize) {
  64 + if (this->mirror == this->buffer - this->bsize) {
  65 + this->buffer = this->mirror;
  66 + this->mirror += this->bsize;
  67 + }
  68 + else {
  69 + this->mirror = NULL;
  70 + break;
  71 + }
74 } 72 }
75 73
76 state = 1; 74 state = 1;
@@ -82,10 +80,6 @@ ctor(void * _this, va_list * params) @@ -82,10 +80,6 @@ ctor(void * _this, va_list * params)
82 } 80 }
83 81
84 if (1 != state) { 82 if (1 != state) {
85 - if (shm_addr) {  
86 - munmap(shm_addr, this->bsize<<1);  
87 - }  
88 -  
89 dtor(this); 83 dtor(this);
90 } 84 }
91 } 85 }
@@ -100,12 +94,12 @@ dtor(void * _this) @@ -100,12 +94,12 @@ dtor(void * _this)
100 free(this->shm_name); 94 free(this->shm_name);
101 } 95 }
102 96
103 - if (this->buffer) { 97 + if (NULL != this->buffer) {
104 munmap(this->buffer, this->bsize); 98 munmap(this->buffer, this->bsize);
105 this->buffer = NULL; 99 this->buffer = NULL;
106 } 100 }
107 101
108 - if (this->mirror) { 102 + if (NULL != this->mirror) {
109 munmap(this->mirror, this->bsize); 103 munmap(this->mirror, this->bsize);
110 this->mirror = NULL; 104 this->mirror = NULL;
111 } 105 }
Please register or login to post a comment