Hi Andrew,
thanks for your reply. Since I think the whole file is quite too long
to post it here, I've cutted out the relevant pieces (or at least I
hope I did). If you need more code please tell me.
--- BEGIN CODE ---
# 1 "/usr/include/bits/select.h" 1
# 26 "/usr/include/bits/select.h"
#define __FD_ZERO(fdsp) do { int __d0, __d1; __asm__ __volatile__
("cld; rep; stosl" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof
(fd_set) / sizeof (__fd_mask)), "1" (&__FDS_BITS (fdsp)[0]) :
"memory"); } while (0)
# 37 "/usr/include/bits/select.h"
#define __FD_SET(fd,fdsp) __asm__ __volatile__ ("btsl %1,%0" :
"=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) : "r" (((int) (fd)) %
__NFDBITS) : "cc","memory")
...
#define FD_SET(fd,fdsetp) __FD_SET (fd, fdsetp)
#define FD_CLR(fd,fdsetp) __FD_CLR (fd, fdsetp)
#define FD_ISSET(fd,fdsetp) __FD_ISSET (fd, fdsetp)
#define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
...
int client_challenge(int sock, char * cert_file) {
X509 *x509 = X509_new();
RSA *rsa_pk = RSA_new();
EVP_PKEY *evp_public;
int bytes, encsize, s_res, validate;
unsigned char *rnd, *challenge, *response, a_response[1];
fd_set sockset;
struct timeval timeout;
FILE *fp;
rnd = malloc(512);
challenge = malloc(1024);
response = malloc(1024);
fp = fopen(cert_file, "r");
if (fp == ((void *)0)) {
fprintf(LOG, "%i: ERR: Error opening cerificate file: %s. Exiting.
\n", getpid(), strerror((*__errno_location ())));
exit(20);
}
if (rsa_pk == ((void *)0)) {
fprintf(LOG, "%i: ERR: Error creating RSA object: %s. Exiting.\n",
getpid(), ERR_error_string(ERR_get_error(), ((void *)0)));
exit(200);
}
x509 = PEM_read_X509(fp, ((void *)0), ((void *)0), ((void *)0));
if (x509 == ((void *)0)) {
fprintf(LOG, "%i: ERR: Error loading certificate from PEM encoded
file: %s. Exiting.\n", getpid(), ERR_error_string(ERR_get_error(),
((void *)0)));
exit(100);
}
fclose(fp);
evp_public = X509_get_pubkey(x509);
if (evp_public == ((void *)0)) {
fprintf(LOG, "%i: ERR: Error loading public key from certificate:
%s. Exiting.\n", getpid(), ERR_error_string(ERR_get_error(), ((void
*)0)));
exit(105);
}
rsa_pk = EVP_PKEY_get1_RSA(evp_public);
if (rsa_pk == ((void *)0)) {
fprintf(LOG, "%i: ERR: Error extracting public key from EVP object:
%s. Exiting.\n", getpid(), ERR_error_string(ERR_get_error(), ((void
*)0)));
exit(105);
}
if (RAND_bytes(rnd, 512) < 1) {
fprintf(LOG, "%i: ERR: Error generating random number as challenge:
%s. Exiting.\n", getpid(), ERR_error_string(ERR_get_error(), ((void
*)0)));
exit(210);
}
encsize = RSA_public_encrypt(sizeof(int), rnd, challenge, rsa_pk, 4);
if (encsize < 0) {
fprintf(LOG, "%i: ERR: Error encrypting challenge: %s. Exiting.\n",
getpid(), ERR_error_string(ERR_get_error(), ((void *)0)));
exit(201);
}
RSA_free(rsa_pk);
X509_free(x509);
bytes = write(sock, challenge, 1024);
if (bytes <= 0) {
fprintf(LOG, "%i: ERR: Error sending challenge: %s. Exiting.\n",
getpid(), strerror((*__errno_location ())));
exit(6);
}
fprintf(LOG, "%i: INFO: Wait for client response...", getpid());
do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; stosl" :
"=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof
(__fd_mask)), "1" (&((&sockset)->__fds_bits)[0]) : "memory"); } while
(0);
__asm__ __volatile__ ("btsl %1,%0" : "=m" (((&sockset)->__fds_bits)
[((sock) / (8 * sizeof (__fd_mask)))]) : "r" (((int) (sock)) % (8 *
sizeof (__fd_mask))) : "cc","memory");
timeout.tv_sec = 10;
timeout.tv_usec = 0;
s_res = select(sock + 1, &sockset, ((void *)0), ((void *)0),
&timeout);
if (s_res < 0) {
fprintf(LOG, "\n%i: ERR: Error setting timeout for socket: %s.
Exiting.\n", getpid(), strerror((*__errno_location ())));
exit(5);
} else if (!(__extension__ ({register char __result; __asm__
__volatile__ ("btl %1,%2 ; setcb %b0" : "=q" (__result) : "r" (((int)
(sock)) % (8 * sizeof (__fd_mask))), "m" (((&sockset)->__fds_bits)
[((sock) / (8 * sizeof (__fd_mask)))]) : "cc"); __result; }))) {
fprintf(LOG, " [FAILED]\n");
fprintf(LOG, "%i: ERR: Waiting for client response timed out!\n",
getpid());
return 0;
}
bytes = read(sock, response, 1024);
if (bytes < 0) {
fprintf(LOG, "%i: ERR: Error reading challenge response from
client: %s. Exiting.\n", getpid(), strerror((*__errno_location ())));
return 0;
} else if (bytes == 0) {
fprintf(LOG, " [FAILED]\n");
fprintf(LOG, "%i: ERR: Connection closed by client\n", getpid());
validate = 0;
} else {
fprintf(LOG, " [OK]\n");
if (*rnd == *response) {
validate = 1;
} else {
validate = 0;
}
bytes = write(sock, (unsigned char *) &validate, sizeof(int));
if (bytes <= 0) {
fprintf(LOG, "%i: ERR: Error contacting client: %s. Exiting.\n",
getpid(), strerror((*__errno_location ())));
exit(6);
}
}
free(rnd);
free(challenge);
free(response);
return validate;
}
--- END CODE ---
Am 12.05.2008 um 15:06 schrieb Andrew Haley:
Andrew Haley wrote:
Till Elsner wrote:
Hi,
while compiling for mips platforms i'm getting the following error:
main.c: 222: error: impossible constraint in `asm`
main.c: 214: error: can't find a register in class `COP3_REGS` while
loading `asm`
main.c: 214: error: `asm` operand has impossible contraints
error in line 222 is thrown by FD_ISSET, error in line 214 come from
FD_ZERO
Compiling and running on i368 platforms works without problems.
Whats
the problem here with mips platforms?
Show us the code. It's at main.c around line 214.
I should have said: it's the expanded source we need, generated by
gcc -Wp,-dD -save-temps. The .i file contains the info.
Andrew.