lccnet 리녹스 포팅 중의 에러

hys545의 이미지

#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#endif
#ifndef EXPORT
#define EXPORT
#endif

static char rcsid[] = "$Id: thunks.c#5 2002/08/30 14:24:46 REDMOND\\drh $";

struct thunk {
	struct thunk *link;
	void (*entrypoint)();
	unsigned char code[16];
};
static struct thunk *thunktable[237];

#define HASH(f) ((int)(((unsigned)f)>>2)%(sizeof thunktable/sizeof thunktable[0]))

static void *newthunk(void (*f)(), void *thunkcode, size_t size, size_t offset) {
	int i = HASH(f);
	struct thunk *tp = malloc(sizeof *tp);

	if (tp == NULL)
		return NULL;	/* cause an exception when dereferenced */
	tp->link = thunktable[i];
	thunktable[i] = tp;
	tp->entrypoint = f;
	memcpy(tp->code, thunkcode, size);
	*(int *)(tp->code + offset) = (char *)f - (tp->code + offset + 4);
	return tp->code;
}

#define NOP 0x90

EXPORT void *__getUMThunk(void (*f)()) {
	static struct thunkcode {		/* must be <= 16 bytes */
		unsigned char code[12];
		int offset;
	} thunkcode = {
		NOP,  NOP,  NOP,
		0x8B, 0x4C, 0x24, 0x04,		/* mov ecx,DWORD PTR [esp+4] */
		0x8B, 0x54, 0x24, 0x08,		/* mov edx,DWORD PTR [esp+8] */
		0xE9,						/* jmp rel32 */
		0
	};
	int i = HASH(f);
	struct thunk *tp = thunktable[i];

	for ( ; tp != NULL; tp = tp->link)
		if (tp->entrypoint == f)
			return tp->code;
	return newthunk(f, &thunkcode, sizeof thunkcode, offsetof(struct thunkcode,offset));
}

EXPORT void *__getMUThunk(void (*f)()) {
	static struct thunkcode {		/* must be <= 16 bytes */
		unsigned char code[4];
		int offset;
		unsigned char retcode[4];
	} thunkcode = {
		NOP,
		0x52,						/* push	edx */
		0x51,						/* push ecx */
		0xE8,						/* call rel32 */
		0,
		0x83, 0xC4, 0x08,			/* add esp,8 */
		0xC3						/* ret */
	};
	int i = HASH(f);
	struct thunk *tp = thunktable[i];

	for ( ; tp != NULL; tp = tp->link)
		if (tp->entrypoint == f)
			return tp->code;
	return newthunk(f, &thunkcode, sizeof thunkcode, offsetof(struct thunkcode,offset));
}

cc -c -o/home/hys545/tmp/build/thunks.o lib/thunks.c
lib/thunks.c: In function `newthunk':
lib/thunks.c:33: error: invalid operands to binary -
make: *** [/home/hys545/tmp/build/thunks.o] 오류 1

이런 에러가 나는데 이거 어떻게 고쳐야 하는지 궁금

doldori의 이미지

hys545 wrote:
static void *newthunk(void (*f)(), void *thunkcode, size_t size, size_t offset) {
/* ... */
	*(int *)(tp-&gt;code + offset) = (char *)f - (tp-&gt;code + offset + 4);
}
</blockquote></div>
 
여기가 문제로군요. (tp-&gt;code + offset + 4)는 unsigned char* 형이므로
char* 형과의 산술연산을 할 수 없습니다.
hys545의 이미지

doldori wrote:
hys545 wrote:
static void *newthunk(void (*f)(), void *thunkcode, size_t size, size_t offset) {
/* ... */
	*(int *)(tp-&gt;code + offset) = (char *)f - (tp-&gt;code + offset + 4);
}
</blockquote></div>
 
여기가 문제로군요. (tp-&gt;code + offset + 4)는 unsigned char* 형이므로
char* 형과의 산술연산을 할 수 없습니다.</blockquote></div>
자세하게 어떻게 고치면 되는지 알려주세여
저는 프로그래밍 초보자입니디
지금 소스 보면서 분석하는 단계

즐린

doldori의 이미지

저는 프로그램의 의도를 알 수 없고, 문제가 되는 코드는 정의되지 않은 결과를
보이므로 어떻게 하라고 말씀드리기는 힘듭니다.

*(int *)(tp->code + offset) = (unsigned char *)f - (tp->code + offset + 4); 

이렇게 하면 컴파일이야 되겠지만 결과를 보장하지는 못합니다. 함수 포인터 f를
대상체 포인터로 변환하는 결과는 정의되지 않기 때문입니다. 특정 환경에서
결과를 보장한다면 다른 문제이겠습니다만.
hys545의 이미지

이거 원래 lcc.net에 있던 겁니다
원래 윈도우 용인데
리녹스로 포팅작업중입니다
lcc를 참고해서 하는중인데.
[url=http://my.dreamwiz.com/hys545/lccnet-4.2.zip ]http://my.dreamwiz.com/hys545/lccnet-4.2.zip [/url]
이게 원본인데
분석해주시면 ㄳ

즐린

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.