Skip to content

Commit

Permalink
Update .github
Browse files Browse the repository at this point in the history
  • Loading branch information
winebox64 authored Nov 30, 2024
1 parent fcac220 commit 9a5d2a5
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion android_sysvshm/.github
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
box64
int shmget(key_t key, size_t size, int flags) {
if (key != IPC_PRIVATE) return -1;

pthread_mutex_lock(&mutex);

sysvshm_connect();
int shmid = sysvshm_shmget_request(size);
if (shmid == 0) {
pthread_mutex_unlock(&mutex);
return -1;
}

int fd = sysvshm_get_fd_request(shmid);
if (fd == -1) {
sysvshm_delete_request(shmid);
pthread_mutex_unlock(&mutex);
return -1;
}

void* addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED) {
sysvshm_delete_request(shmid);
close(fd);
pthread_mutex_unlock(&mutex);
return -1;
}

if (shmemory_count == 0) {
shmemories = (shmemory_t*)malloc(sizeof(shmemory_t));
} else {
shmemories = (shmemory_t*)realloc(shmemories, (shmemory_count + 1) * sizeof(shmemory_t));
}

shmemories[shmemory_count].id = shmid;
shmemories[shmemory_count].addr = addr;
shmemories[shmemory_count].fd = fd;
shmemories[shmemory_count].size = size;
shmemories[shmemory_count].marked_for_delete = 0;

shmemory_count++;

pthread_mutex_unlock(&mutex);

return shmid;
}

0 comments on commit 9a5d2a5

Please sign in to comment.