Commit 6cd673b4eb6ec69f90031359731cc174e6148453
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 | 30 | long psize = sysconf(_SC_PAGESIZE); |
31 | 31 | size_t size; |
32 | 32 | int shm; |
33 | - void * shm_addr; | |
34 | 33 | |
35 | 34 | this->shm_name = malloc(strlen(shm_name) + 1); |
36 | 35 | strcpy(this->shm_name, shm_name); |
... | ... | @@ -52,25 +51,24 @@ ctor(void * _this, va_list * params) |
52 | 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 | 55 | PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); |
64 | 56 | if (this->buffer == MAP_FAILED) { |
65 | - shm_addr = NULL; | |
57 | + this->buffer = NULL; | |
66 | 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 | 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 | 74 | state = 1; |
... | ... | @@ -82,10 +80,6 @@ ctor(void * _this, va_list * params) |
82 | 80 | } |
83 | 81 | |
84 | 82 | if (1 != state) { |
85 | - if (shm_addr) { | |
86 | - munmap(shm_addr, this->bsize<<1); | |
87 | - } | |
88 | - | |
89 | 83 | dtor(this); |
90 | 84 | } |
91 | 85 | } |
... | ... | @@ -100,12 +94,12 @@ dtor(void * _this) |
100 | 94 | free(this->shm_name); |
101 | 95 | } |
102 | 96 | |
103 | - if (this->buffer) { | |
97 | + if (NULL != this->buffer) { | |
104 | 98 | munmap(this->buffer, this->bsize); |
105 | 99 | this->buffer = NULL; |
106 | 100 | } |
107 | 101 | |
108 | - if (this->mirror) { | |
102 | + if (NULL != this->mirror) { | |
109 | 103 | munmap(this->mirror, this->bsize); |
110 | 104 | this->mirror = NULL; |
111 | 105 | } | ... | ... |
Please
register
or
login
to post a comment