Skip to content

Commit

Permalink
CogVM source as per VMConstruction-Plugins-OSProcessPlugin.oscog-eem.77
Browse files Browse the repository at this point in the history
Finally understand (Thanks John Mac) the difference between sa_sigaction
and sa_handler in a struct sigaction, and apply this to setting handlers.
  • Loading branch information
eliotmiranda committed Apr 26, 2024
1 parent a187764 commit 6c22cca
Showing 1 changed file with 31 additions and 45 deletions.
76 changes: 31 additions & 45 deletions src/plugins/UnixOSProcessPlugin/UnixOSProcessPlugin.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3307 uuid: bea33bb5-98d1-4d1a-8004-40be76e0b94c
VMPluginCodeGenerator VMMaker.oscog-eem.3368 uuid: 9f9dc531-0e56-45f7-8c71-b567cfe447f0
from
UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.76 uuid: 93eb5d11-9cfa-4785-806d-c317358b8c5a
UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.77 uuid: 7461988b-d953-46d9-9506-613e2c3c2f1f
*/
static char __buildInfo[] = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.76 uuid: 93eb5d11-9cfa-4785-806d-c317358b8c5a " __DATE__ ;
static char __buildInfo[] = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.77 uuid: 7461988b-d953-46d9-9506-613e2c3c2f1f " __DATE__ ;
/* D T Lewis - UnixOSProcessPlugin.c translated from class
UnixOSProcessPlugin of OSProcessPlugin version 4.6.7 Cog */

Expand Down Expand Up @@ -224,7 +224,6 @@ static sqInt sigAlrmNumber(void);
static sqInt sigChldNumber(void);
static sqInt sigContNumber(void);
static void * sigDefaultNumber(void);
static void * sigErrorNumber(void);
static void * sigHoldNumber(void);
static sqInt sigHupNumber(void);
static void * sigIgnoreNumber(void);
Expand Down Expand Up @@ -344,7 +343,7 @@ extern sqInt trueObject(void);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.76 " INT_EXT;
static const char *moduleName = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.77 " INT_EXT;
static void *originalSigHandlers[NSIG + 1];
static pid_t *pidArray = NULL;
static sqInt pidCount;
Expand Down Expand Up @@ -1075,7 +1074,7 @@ forwardSignaltoSemaphoreAt(sqInt sigNum, sqInt semaphoreIndex)
return SIG_ERR;
}
oldHandler = setSignalNumberhandler(sigNum, handleSignalFunctionAddress());
if (oldHandler != (sigErrorNumber())) {
if (oldHandler != SIG_ERR) {
(originalSignalHandlers())[sigNum] = oldHandler;
semaIndices[sigNum] = semaphoreIndex;
}
Expand Down Expand Up @@ -1451,36 +1450,35 @@ needSigaltstack(void)
}
GetAttributeString = ioLoadFunctionFrom("GetAttributeString", "os_exports");
if ((GetAttributeString == null)
|| ((GetAttributeString(1008)) == null)) {
|| ((GetAttributeString(0x3F0)) == null)) {
useSignalStack = 0;
return 0;
}

/* Now see if there's already a sigaltstack in place */
useSignalStack = 1;
if ((sigaltstack(0,&sigstack)) < 0) {
if ((sigaltstack(0, (&sigstack))) < 0) {
perror("sigaltstack");
}
# if defined(SA_DISABLE)
if (!(sigstack.ss_size == 0 || (sigstack.ss_flags & SA_DISABLE))) {
if (!((((sigstack.ss_size)) == 0)
|| (((((sigstack.ss_flags)) & (
# if defined(SA_DISABLE)
SA_DISABLE
# else
SS_DISABLE
# endif
)) != 0)))) {
return 1;
}
# else

/* e.g. Mac OS documents SA_DISABLE but defines SS_DISABLE */
if (!(sigstack.ss_size == 0 || (sigstack.ss_flags & SS_DISABLE))) {
return 1;
}
# endif // defined(SA_DISABLE)
SigStackSize = ((((0x400 * (sizeof(void *))) * 16) < MINSIGSTKSZ) ? MINSIGSTKSZ : ((0x400 * (sizeof(void *))) * 16));
if (null == (sigstack.ss_size = SigStackSize, sigstack.ss_sp = malloc(SigStackSize))) {
if (!((sigstack.ss_sp = malloc((sigstack.ss_size = SigStackSize))))) {
msg("sigstack malloc failed");
useSignalStack = 0;
return 0;
}
if (sigaltstack(&sigstack, 0) < 0) {
if ((sigaltstack((&sigstack), 0)) < 0) {
msg("sigaltstack install failed");
(void)free(sigstack.ss_sp);
((void) (free((sigstack.ss_sp))));
useSignalStack = 0;
return 0;
}
Expand Down Expand Up @@ -2301,7 +2299,7 @@ primitiveForwardSignalToSemaphore(void)
return;
}
handler = forwardSignaltoSemaphoreAt(sigNum, semaphoreIndex);
if (handler == (sigErrorNumber())) {
if (handler == SIG_ERR) {
primitiveFail();
return;
}
Expand Down Expand Up @@ -4772,14 +4770,14 @@ setSigChldHandler(void)


# if defined(SA_NOCLDSTOP)
sigchldHandlerAction.sa_sigaction = reapChildProcess;
sigchldHandlerAction.sa_flags = SA_NODEFER | SA_NOCLDSTOP;
(sigchldHandlerAction.sa_handler = reapChildProcess);
(sigchldHandlerAction.sa_flags = SA_NODEFER | SA_NOCLDSTOP);
if (needSigaltstack()) {
sigchldHandlerAction.sa_flags |= SA_ONSTACK;
(sigchldHandlerAction.sa_flags = ((sigchldHandlerAction.sa_flags)) | SA_ONSTACK);
}
sigemptyset(&sigchldHandlerAction.sa_mask);
if ((sigaction(SIGCHLD, &sigchldHandlerAction, 0)) == (sigErrorNumber())) {
perror("signal");
sigemptyset((&((sigchldHandlerAction.sa_mask))));
if ((sigaction(SIGCHLD, (&sigchldHandlerAction), 0)) == (((sqInt)SIG_ERR))) {
perror("sigaction");
}
# else // defined(SA_NOCLDSTOP)
setSignalNumberhandler(SIGCHLD, reapChildProcess);
Expand All @@ -4804,9 +4802,7 @@ setSigIntIgnore(void)
}


/* Set a signal handler. The C code translator will convert #sig:nal: into
'signal(parm1, parm2)'
*/
/* Set a signal handler, and answer the previous handler. */

/* UnixOSProcessPlugin>>#setSignalNumber:handler: */
static void *
Expand All @@ -4818,13 +4814,13 @@ setSignalNumberhandler(sqInt signalNumber, void *signalHandlerAddress)
if (!(needSigaltstack())) {
return signal(signalNumber, signalHandlerAddress);
}
sigHandlerAction.sa_sigaction = signalHandlerAddress;
sigHandlerAction.sa_flags = SA_ONSTACK | SA_RESTART;
sigemptyset(&sigHandlerAction.sa_mask);
if ((sigaction(signalNumber, (&sigHandlerAction), (&oldHandlerAction))) == (sigErrorNumber())) {
(sigHandlerAction.sa_handler = ((void (*)(int)) signalHandlerAddress));
(sigHandlerAction.sa_flags = SA_ONSTACK | SA_RESTART);
sigemptyset((&((sigHandlerAction.sa_mask))));
if ((sigaction(signalNumber, (&sigHandlerAction), (&oldHandlerAction))) == (((sqInt)SIG_ERR))) {
perror("signal");
}
return oldHandlerAction.sa_sigaction;
return (oldHandlerAction.sa_handler);
}

/* UnixOSProcessPlugin>>#setSigPipeDefaultHandler */
Expand Down Expand Up @@ -4932,16 +4928,6 @@ sigDefaultNumber(void)
}


/* Error return from signal() */

/* UnixOSProcessPlugin>>#sigErrorNumber */
static void *
sigErrorNumber(void)
{
return SIG_ERR;
}


/* Hold action for a signal */

/* UnixOSProcessPlugin>>#sigHoldNumber */
Expand Down

0 comments on commit 6c22cca

Please sign in to comment.