Rewrite the code that uses the try/catch paradigm implemented by
goto and abstracted by the itry, ithrow and icatch macros (among others). The problem with this code is that it doesn't compile on ia64. The compiler is sufficiently confused that it inserts a call to __ia64_save_stack_nonlock(). This is a magic function that saves enough of the stack to allow for non-local gotos, such as would be the case for nested functions. Since it's not a compiler defined function, it needs a runtime implementation. This we have not in a standalone compilation as is the kernel. There's no indication that the compiler is not confused on other platforms. It's likely that saving the stack in those cases is trivial enough that the compiler doesn't need to off-load the complexity to a runtime function. The code is believed to be correctly translated, but has not been tested. The overall structure remained the same, except that it's made explicit. The macros that implement the try/catch construct have been removed to avoid reintroduction of their use. It's not a good idea. In general the rewritten code is slightly more optimal in that it doesn't need as much stack space and generally is smaller in size. Found by: LINT
This commit is contained in:
parent
cfd5696d22
commit
e51fe8759d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=119376
@ -128,46 +128,47 @@ smb_sm_lookupint(struct smb_vcspec *vcspec, struct smb_sharespec *shspec,
|
||||
error = smb_vc_lock(vcp, LK_EXCLUSIVE, td);
|
||||
if (error)
|
||||
continue;
|
||||
itry {
|
||||
if ((vcp->obj.co_flags & SMBV_PRIVATE) ||
|
||||
!CONNADDREQ(vcp->vc_paddr, vcspec->sap) ||
|
||||
strcmp(vcp->vc_username, vcspec->username) != 0)
|
||||
ithrow(1);
|
||||
if (vcspec->owner != SMBM_ANY_OWNER) {
|
||||
if (vcp->vc_uid != vcspec->owner)
|
||||
ithrow(1);
|
||||
} else
|
||||
exact = 0;
|
||||
if (vcspec->group != SMBM_ANY_GROUP) {
|
||||
if (vcp->vc_grp != vcspec->group)
|
||||
ithrow(1);
|
||||
} else
|
||||
exact = 0;
|
||||
|
||||
if (vcspec->mode & SMBM_EXACT) {
|
||||
if (!exact ||
|
||||
(vcspec->mode & SMBM_MASK) != vcp->vc_mode)
|
||||
ithrow(1);
|
||||
}
|
||||
if (smb_vc_access(vcp, scred, vcspec->mode) != 0)
|
||||
ithrow(1);
|
||||
vcspec->ssp = NULL;
|
||||
if (shspec)
|
||||
ithrow(smb_vc_lookupshare(vcp, shspec, scred, &vcspec->ssp));
|
||||
error = 0;
|
||||
break;
|
||||
} icatch(error) {
|
||||
smb_vc_unlock(vcp, 0, td);
|
||||
} ifinally {
|
||||
} iendtry;
|
||||
if (error == 0)
|
||||
break;
|
||||
if ((vcp->obj.co_flags & SMBV_PRIVATE) ||
|
||||
!CONNADDREQ(vcp->vc_paddr, vcspec->sap) ||
|
||||
strcmp(vcp->vc_username, vcspec->username) != 0)
|
||||
goto err1;
|
||||
if (vcspec->owner != SMBM_ANY_OWNER) {
|
||||
if (vcp->vc_uid != vcspec->owner)
|
||||
goto err1;
|
||||
} else
|
||||
exact = 0;
|
||||
if (vcspec->group != SMBM_ANY_GROUP) {
|
||||
if (vcp->vc_grp != vcspec->group)
|
||||
goto err1;
|
||||
} else
|
||||
exact = 0;
|
||||
if (vcspec->mode & SMBM_EXACT) {
|
||||
if (!exact || (vcspec->mode & SMBM_MASK) !=
|
||||
vcp->vc_mode)
|
||||
goto err1;
|
||||
}
|
||||
if (smb_vc_access(vcp, scred, vcspec->mode) != 0)
|
||||
goto err1;
|
||||
vcspec->ssp = NULL;
|
||||
if (shspec) {
|
||||
error = (int)smb_vc_lookupshare(vcp, shspec, scred,
|
||||
&vcspec->ssp);
|
||||
if (error)
|
||||
goto fail;
|
||||
}
|
||||
error = 0;
|
||||
break;
|
||||
err1:
|
||||
error = 1;
|
||||
fail:
|
||||
smb_vc_unlock(vcp, 0, td);
|
||||
}
|
||||
if (vcp) {
|
||||
smb_vc_ref(vcp);
|
||||
*vcpp = vcp;
|
||||
}
|
||||
return error;
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
@ -413,39 +414,53 @@ smb_vc_create(struct smb_vcspec *vcspec,
|
||||
vcp->vc_grp = gid;
|
||||
|
||||
smb_sl_init(&vcp->vc_stlock, "vcstlock");
|
||||
error = 0;
|
||||
itry {
|
||||
vcp->vc_paddr = dup_sockaddr(vcspec->sap, 1);
|
||||
ierror(vcp->vc_paddr == NULL, ENOMEM);
|
||||
error = ENOMEM;
|
||||
|
||||
vcp->vc_laddr = dup_sockaddr(vcspec->lap, 1);
|
||||
ierror(vcp->vc_laddr == NULL, ENOMEM);
|
||||
vcp->vc_paddr = dup_sockaddr(vcspec->sap, 1);
|
||||
if (vcp->vc_paddr == NULL)
|
||||
goto fail;
|
||||
vcp->vc_laddr = dup_sockaddr(vcspec->lap, 1);
|
||||
if (vcp->vc_laddr == NULL)
|
||||
goto fail;
|
||||
vcp->vc_pass = smb_strdup(vcspec->pass);
|
||||
if (vcp->vc_pass == NULL)
|
||||
goto fail;
|
||||
vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain :
|
||||
"NODOMAIN");
|
||||
if (vcp->vc_domain == NULL)
|
||||
goto fail;
|
||||
vcp->vc_srvname = smb_strdup(vcspec->srvname);
|
||||
if (vcp->vc_srvname == NULL)
|
||||
goto fail;
|
||||
vcp->vc_username = smb_strdup(vcspec->username);
|
||||
if (vcp->vc_username == NULL)
|
||||
goto fail;
|
||||
error = (int)iconv_open("tolower", vcspec->localcs, &vcp->vc_tolower);
|
||||
if (error)
|
||||
goto fail;
|
||||
error = (int)iconv_open("toupper", vcspec->localcs, &vcp->vc_toupper);
|
||||
if (error)
|
||||
goto fail;
|
||||
if (vcspec->servercs[0]) {
|
||||
error = (int)iconv_open(vcspec->servercs, vcspec->localcs,
|
||||
&vcp->vc_toserver);
|
||||
if (error)
|
||||
goto fail;
|
||||
error = (int)iconv_open(vcspec->localcs, vcspec->servercs,
|
||||
&vcp->vc_tolocal);
|
||||
if (error)
|
||||
goto fail;
|
||||
}
|
||||
error = (int)smb_iod_create(vcp);
|
||||
if (error)
|
||||
goto fail;
|
||||
*vcpp = vcp;
|
||||
smb_co_addchild(&smb_vclist, VCTOCP(vcp));
|
||||
return (0);
|
||||
|
||||
ierror((vcp->vc_pass = smb_strdup(vcspec->pass)) == NULL, ENOMEM);
|
||||
|
||||
vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain : "NODOMAIN");
|
||||
ierror(vcp->vc_domain == NULL, ENOMEM);
|
||||
|
||||
ierror((vcp->vc_srvname = smb_strdup(vcspec->srvname)) == NULL, ENOMEM);
|
||||
ierror((vcp->vc_username = smb_strdup(vcspec->username)) == NULL, ENOMEM);
|
||||
|
||||
ithrow(iconv_open("tolower", vcspec->localcs, &vcp->vc_tolower));
|
||||
ithrow(iconv_open("toupper", vcspec->localcs, &vcp->vc_toupper));
|
||||
if (vcspec->servercs[0]) {
|
||||
ithrow(iconv_open(vcspec->servercs, vcspec->localcs,
|
||||
&vcp->vc_toserver));
|
||||
ithrow(iconv_open(vcspec->localcs, vcspec->servercs,
|
||||
&vcp->vc_tolocal));
|
||||
}
|
||||
|
||||
ithrow(smb_iod_create(vcp));
|
||||
*vcpp = vcp;
|
||||
smb_co_addchild(&smb_vclist, VCTOCP(vcp));
|
||||
} icatch(error) {
|
||||
smb_vc_put(vcp, scred);
|
||||
} ifinally {
|
||||
} iendtry;
|
||||
return error;
|
||||
fail:
|
||||
smb_vc_put(vcp, scred);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -141,29 +141,39 @@ smb_iod_connect(struct smbiod *iod)
|
||||
}
|
||||
vcp->vc_genid++;
|
||||
error = 0;
|
||||
itry {
|
||||
ithrow(SMB_TRAN_CREATE(vcp, td));
|
||||
SMBIODEBUG("tcreate\n");
|
||||
if (vcp->vc_laddr) {
|
||||
ithrow(SMB_TRAN_BIND(vcp, vcp->vc_laddr, td));
|
||||
}
|
||||
SMBIODEBUG("tbind\n");
|
||||
ithrow(SMB_TRAN_CONNECT(vcp, vcp->vc_paddr, td));
|
||||
SMB_TRAN_SETPARAM(vcp, SMBTP_SELECTID, &iod->iod_flags);
|
||||
iod->iod_state = SMBIOD_ST_TRANACTIVE;
|
||||
SMBIODEBUG("tconnect\n");
|
||||
/* vcp->vc_mid = 0;*/
|
||||
ithrow(smb_smb_negotiate(vcp, &iod->iod_scred));
|
||||
SMBIODEBUG("snegotiate\n");
|
||||
ithrow(smb_smb_ssnsetup(vcp, &iod->iod_scred));
|
||||
iod->iod_state = SMBIOD_ST_VCACTIVE;
|
||||
SMBIODEBUG("completed\n");
|
||||
smb_iod_invrq(iod);
|
||||
} icatch(error) {
|
||||
smb_iod_dead(iod);
|
||||
} ifinally {
|
||||
} iendtry;
|
||||
return error;
|
||||
|
||||
error = (int)SMB_TRAN_CREATE(vcp, td);
|
||||
if (error)
|
||||
goto fail;
|
||||
SMBIODEBUG("tcreate\n");
|
||||
if (vcp->vc_laddr) {
|
||||
error = (int)SMB_TRAN_BIND(vcp, vcp->vc_laddr, td);
|
||||
if (error)
|
||||
goto fail;
|
||||
}
|
||||
SMBIODEBUG("tbind\n");
|
||||
error = (int)SMB_TRAN_CONNECT(vcp, vcp->vc_paddr, td);
|
||||
if (error)
|
||||
goto fail;
|
||||
SMB_TRAN_SETPARAM(vcp, SMBTP_SELECTID, &iod->iod_flags);
|
||||
iod->iod_state = SMBIOD_ST_TRANACTIVE;
|
||||
SMBIODEBUG("tconnect\n");
|
||||
/* vcp->vc_mid = 0;*/
|
||||
error = (int)smb_smb_negotiate(vcp, &iod->iod_scred);
|
||||
if (error)
|
||||
goto fail;
|
||||
SMBIODEBUG("snegotiate\n");
|
||||
error = (int)smb_smb_ssnsetup(vcp, &iod->iod_scred);
|
||||
if (error)
|
||||
goto fail;
|
||||
iod->iod_state = SMBIOD_ST_VCACTIVE;
|
||||
SMBIODEBUG("completed\n");
|
||||
smb_iod_invrq(iod);
|
||||
return (0);
|
||||
|
||||
fail:
|
||||
smb_iod_dead(iod);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -86,42 +86,6 @@ void m_dumpm(struct mbuf *m);
|
||||
|
||||
#define SMB_STRFREE(p) do { if (p) smb_strfree(p); } while(0)
|
||||
|
||||
/*
|
||||
* The simple try/catch/finally interface.
|
||||
* With GCC it is possible to allow more than one try/finally block per
|
||||
* function, but we'll avoid it to maintain portability.
|
||||
*/
|
||||
#define itry { \
|
||||
__label__ _finlab, _catchlab; \
|
||||
int _tval; \
|
||||
|
||||
#define icatch(var) \
|
||||
goto _finlab; \
|
||||
(void)&&_catchlab; \
|
||||
_catchlab: \
|
||||
var = _tval;
|
||||
|
||||
#define ifinally (void)&&_finlab; \
|
||||
_finlab:
|
||||
#define iendtry }
|
||||
|
||||
#define inocatch \
|
||||
goto _finlab; \
|
||||
(void)&&_catchlab; \
|
||||
_catchlab: \
|
||||
|
||||
#define ithrow(t) do { \
|
||||
if ((_tval = (int)(t)) != 0) \
|
||||
goto _catchlab; \
|
||||
} while (0)
|
||||
|
||||
#define ierror(t,e) do { \
|
||||
if (t) { \
|
||||
_tval = e; \
|
||||
goto _catchlab; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef u_int16_t smb_unichar;
|
||||
typedef smb_unichar *smb_uniptr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user