Changed shared memory allocation to a standard malloc to prevent crash

on systems that do not allow large shm sizes.
This commit is contained in:
mjbudd77 2020-11-13 11:17:35 -05:00
parent 7dab1976f6
commit 58a1d76e2c
1 changed files with 23 additions and 20 deletions

View File

@ -16,32 +16,35 @@ nes_shm_t *nes_shm = NULL;
//************************************************************************
nes_shm_t *open_nes_shm(void)
{
int shmId;
nes_shm_t *vaddr;
struct shmid_ds ds;
shmId = shmget( IPC_PRIVATE, sizeof(struct nes_shm_t), IPC_CREAT | S_IRWXU | S_IRWXG );
vaddr = (nes_shm_t*)malloc( sizeof(struct nes_shm_t) );
if ( shmId == -1 )
{
perror("Error: GL shmget Failed:");
return NULL;
}
printf("Created ShmID: %i \n", shmId );
//int shmId;
//struct shmid_ds ds;
vaddr = (nes_shm_t*)shmat( shmId, NULL, 0);
//shmId = shmget( IPC_PRIVATE, sizeof(struct nes_shm_t), IPC_CREAT | S_IRWXU | S_IRWXG );
if ( vaddr == (nes_shm_t*)-1 )
{
perror("Error: NES shmat Failed:");
return NULL;
}
memset( vaddr, 0, sizeof(struct nes_shm_t));
//if ( shmId == -1 )
//{
// perror("Error: GL shmget Failed:");
// return NULL;
//}
//printf("Created ShmID: %i \n", shmId );
if ( shmctl( shmId, IPC_RMID, &ds ) != 0 )
{
perror("Error: GLX shmctl IPC_RMID Failed:");
}
//vaddr = (nes_shm_t*)shmat( shmId, NULL, 0);
//if ( vaddr == (nes_shm_t*)-1 )
//{
// perror("Error: NES shmat Failed:");
// return NULL;
//}
//memset( vaddr, 0, sizeof(struct nes_shm_t));
//if ( shmctl( shmId, IPC_RMID, &ds ) != 0 )
//{
// perror("Error: GLX shmctl IPC_RMID Failed:");
//}
//sem_init( &vaddr->sem, 1, 1 );