SEGV Signal 발생합니다. 도움 부탁드려요

hwangsw의 이미지

안녕하세요.
아래와 같은 소스가 있는데요.
컴파일을 하면 문제가 없으나 실행을 시키면
shmid < 0일 경우에는 "shm create OK" 로그를 찍고 Received SEGV Signal 에러가 나서 프로세스가 죽어버리고,
shmid >= 0일 경우에는 "Shared Memory Attach OK" 로그를 찍고 Received SEGV Signal 에러가 나서 프로세스가 죽어버립니다.
32bit 솔라리스에는 잘 실행되던 소스였는데 지금 aix 5.3 64비트로 포팅중인데 잘 안되고 있습니다.
도움 부탁드립니다.

#define MAX_LINE_NUM	20
 
struct test_stat
{
        int     pid;                            /* process pid           */
        int     stat;                           /* 0:전송불가 1:전송가능 */
        int     fifocnt;                        /* fifo cnt */
        char    usrid           [8];            /* user id               */
};
struct  test_stat    *op;
 
void main(int argc, char *argv[])
{
	int	line_num = 1;
        int     shmid;
        int     shmsize = sizeof(struct test_stat) * MAX_LINE_NUM;
 
        shmid = ShmGet(shmkey);
        if(shmid < 0)
        {
                shmid = ShmCreate(shmkey, shmsize, SHM_PERM | IPC_CREAT);
                if(shmid < 0)
                {
                        Log("Shared Memory Create fail (%d)\n", errno);
                        return -9;
                }
                Log("shm create OK\n");
 
                op = (struct test_stat *)ShmAttach(shmid);
                if(op == (void *)-1)
                {
                        Log("Shared Memory Attach fail (%d)\n", errno);
                        return -10;
                }
 
                memset((char*)op, 0x00, shmsize);
		Log("Initialize\n");
        }
        else
        {
                op = (struct test_stat *)ShmAttach(shmid);
                if(op == (void *)-1)
                {
                        Log("Shared Memory Attach fail (%d)\n", errno);
                        return -11;
                }
        }
        Log("Shared Memory Attach OK\n");
 
        (op+line_num-1)->pid = getpid();
        Log("test1111\n");
 
 
	return 0;
}
 
int ShmGet(key_t key)
{
        return shmget(key, 0, 0);
}
 
int ShmCreate(key_t key, size_t size, int flag)
{
    return shmget(key, size, flag);
}
 
void *ShmAttach(int shmid)
{
    return (void *)shmat(shmid, (char *)0, 0);
}
pastime의 이미지

혹시 쓰기 권한은 확인해 보셨나요?

hwangsw의 이미지

공유메모리 생성시
#define SHM_PERM 0660으로 정의해 놓았고,
ipcs -a로 확인해보면 권한이나 user는 아무 이상없어요...

shint의 이미지

dll 을 다른 버젼으로 참조하고 있었드라구요;;;;

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

hwangsw의 이미지

dll을 사용하고 있지 않구요. Cc컴파일러를 사용하고 있습니다

bacon의 이미지

위에 붙여 놓은 소스에는 ShmAttach(int shmid)프로토타입이 실제 호출된 이후에만 있는데요, 이경우 ShmAttach가 컴파일러는 int를 리턴하는 걸로 가정을 하죠. 64bit머신에서 작업하시니가 sizeof(void*) 랑 sizeof(int)가 달라서, op = (struct test_stat *)ShmAttach(shmid);
할때 주소값이 잘려 나갈거예요. 그래서 그런것 같은데... void *ShmAttach(int shmid)을 메인앞으로 옮기거나 프로토타입만이라도 main앞으로 보내면 될듯. 위의 코드만 보고 말하는거니까 틀릴수 있고요. 참고로 별건 아니지만 main은 void인데 값을 리턴하는 구문이 있군요. 컴파일러 경고레벨을 좀 올려서 사용하는것도 좋은 방법일듯요. 그랬으면 위의 문제도 경고가 되었을듯한데요.

hwangsw의 이미지

답변 감사합니다. 아직 코드를 고쳐보지 않았지만 bacon님 말씀처럼 그런듯 하네요.
ShmAttach()함수는 라이브러리 링킹하여 사용합니다. 질문을 올리기 위해서 편의상 써 놓았구요.
컴파일러 경고레벨은 어떻게 올릴수 있는지 가르쳐 주시면 감사하겠습니다.

bacon의 이미지

AIX용 XL C/C++에는 32/64비튼 관련 -qwarn64가 있네요. http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/compiler/ref/ruoptwrn.htm

gcc같으면 -Wall만 해도 왠만한건 다 경고가 됩니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.