Skip to content

Commit

Permalink
[libcrystax] Adjust signal.h according to POSIX
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
  • Loading branch information
dmsck committed Nov 15, 2015
1 parent 2ae9960 commit b90958f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
52 changes: 52 additions & 0 deletions sources/crystax/include/signal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2011-2015 CrystaX .NET.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY CrystaX .NET ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CrystaX .NET OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of CrystaX .NET.
*/

#ifndef __CRYSTAX_SIGNAL_H_72db9f389990469a95e32248bf672022
#define __CRYSTAX_SIGNAL_H_72db9f389990469a95e32248bf672022

#include <crystax/id.h>
#include <crystax/google/signal.h>

#ifndef _STRUCT_TIMESPEC
#include <sys/_types.h>
struct timespec {
__time_t tv_sec;
long tv_nsec;
};
#define _STRUCT_TIMESPEC
#endif

__BEGIN_DECLS

int pthread_kill(pthread_t tid, int sig);
int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);

__END_DECLS

#endif /* __CRYSTAX_SIGNAL_H_72db9f389990469a95e32248bf672022 */
12 changes: 12 additions & 0 deletions sources/crystax/include/sys/_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ typedef __uint16_t __sa_family_t;

typedef long __pthread_t;

typedef struct {
__uint32_t flags;
void* stack_base;
__size_t stack_size;
__size_t guard_size;
__int32_t sched_policy;
__int32_t sched_priority;
#ifdef __LP64__
char __reserved[16];
#endif
} __pthread_attr_t;

typedef struct {
#if defined(__LP64__)
__int32_t __private[10];
Expand Down
5 changes: 5 additions & 0 deletions sources/crystax/include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ typedef __pthread_t pthread_t;
#define _PTHREAD_T_DECLARED
#endif

#ifndef _PTHREAD_ATTR_T_DECLARED
typedef __pthread_attr_t pthread_attr_t;
#define _PTHREAD_ATTR_T_DECLARED
#endif

#ifndef _PTHREAD_MUTEX_T_DECLARED
typedef __pthread_mutex_t pthread_mutex_t;
#define _PTHREAD_MUTEX_T_DECLARED
Expand Down
1 change: 1 addition & 0 deletions tests/build/crystax-test-posix-interfaces/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ SRCFILES := \
search.c \
semaphore.c \
setjmp.c \
signal.c \
spawn.c \
stdarg.c \
stdbool.c \
Expand Down
36 changes: 31 additions & 5 deletions tests/build/crystax-test-posix-interfaces/jni/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@

#include "helper.h"

extern void *memset(void *s, int c, size_t n);

#if __ANDROID__

/* https://tracker.crystax.net/issues/1158 */

void psiginfo(const siginfo_t *pinfo, const char *message)
{
(void)pinfo;
(void)message;
}

void psignal(int signum, const char *message)
{
(void)signum;
(void)message;
}

#endif /* !__ANDROID__ */

#define CHECK(type) type JOIN(signal_check_type_, __LINE__)

CHECK(pthread_t);
Expand Down Expand Up @@ -81,19 +101,21 @@ CHECK(struct sigaction)
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);

s->sa_handler = (sa_handler_t)0;
s->sa_mask = (sigset_t)0;
s->sa_flags = 0;
s->sa_sigaction = (sa_sigaction_t)0;

memset(&s->sa_mask, 0, sizeof(s->sa_mask));
}

CHECK(ucontext_t)
{
s->uc_link = (ucontext_t*)0;
s->uc_sigmask = (sigset_t)0;
s->uc_mcontext = (mcontext_t)0;

stack_t *p = &s->uc_stack;
(void)p;

memset(&s->uc_sigmask, 0, sizeof(s->uc_sigmask));
memset(&s->uc_mcontext, 0, sizeof(s->uc_mcontext));
}

CHECK(stack_t)
Expand All @@ -119,7 +141,11 @@ CHECK(siginfo_t)
(void)p;
}

void signal_check_functions(pthread_t tid, sigset_t *ss, union sigval sv)
void signal_check_functions(pthread_t tid, sigset_t *ss
#if _POSIX_REALTIME_SIGNALS > 0
, union sigval sv
#endif
)
{
typedef void (*signal_cb_t)(int );

Expand Down Expand Up @@ -153,7 +179,7 @@ void signal_check_functions(pthread_t tid, sigset_t *ss, union sigval sv)
#if _POSIX_REALTIME_SIGNALS > 0
(void)sigtimedwait((const sigset_t*)0, (siginfo_t*)0, (const struct timespec*)0);
#endif
(void)sigwait(ss, (int*)0);
(void)sigwait(ss, (int*)1234);
#if _POSIX_REALTIME_SIGNALS > 0
(void)sigwaitinfo(ss, (siginfo_t*)0);
#endif
Expand Down

0 comments on commit b90958f

Please sign in to comment.