2004-06-11 01:20:15 +04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2018-10-03 01:56:29 +03:00
|
|
|
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2004-06-11 01:20:15 +04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 02:19:02 +03:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2004-06-11 01:20:15 +04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-06 22:06:49 +04:00
|
|
|
#include "curl_setup.h"
|
2007-02-28 08:15:56 +03:00
|
|
|
|
2011-07-26 19:23:27 +04:00
|
|
|
#ifdef NETWARE /* Novell NetWare */
|
2007-07-01 00:02:51 +04:00
|
|
|
|
|
|
|
#ifdef __NOVELL_LIBC__
|
|
|
|
/* For native LibC-based NLM we need to register as a real lib. */
|
2004-06-11 01:20:15 +04:00
|
|
|
#include <library.h>
|
|
|
|
#include <netware.h>
|
|
|
|
#include <screen.h>
|
|
|
|
#include <nks/thread.h>
|
|
|
|
#include <nks/synch.h>
|
|
|
|
|
2012-11-17 03:59:42 +04:00
|
|
|
#include "curl_memory.h"
|
|
|
|
/* The last #include file should be: */
|
2013-01-04 05:50:28 +04:00
|
|
|
#include "memdebug.h"
|
2004-06-11 01:20:15 +04:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int _errno;
|
|
|
|
void *twentybytes;
|
|
|
|
} libthreaddata_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int z;
|
|
|
|
void *tenbytes;
|
|
|
|
NXKey_t perthreadkey; /* if -1, no key obtained... */
|
|
|
|
NXMutex_t *lock;
|
|
|
|
} libdata_t;
|
|
|
|
|
|
|
|
int gLibId = -1;
|
|
|
|
void *gLibHandle = (void *) NULL;
|
|
|
|
rtag_t gAllocTag = (rtag_t) NULL;
|
|
|
|
NXMutex_t *gLibLock = (NXMutex_t *) NULL;
|
|
|
|
|
|
|
|
/* internal library function prototypes... */
|
2016-04-04 00:06:23 +03:00
|
|
|
int DisposeLibraryData(void *);
|
|
|
|
void DisposeThreadData(void *);
|
|
|
|
int GetOrSetUpData(int id, libdata_t **data, libthreaddata_t **threaddata);
|
|
|
|
|
|
|
|
|
|
|
|
int _NonAppStart(void *NLMHandle,
|
|
|
|
void *errorScreen,
|
|
|
|
const char *cmdLine,
|
|
|
|
const char *loadDirPath,
|
|
|
|
size_t uninitializedDataLength,
|
|
|
|
void *NLMFileHandle,
|
|
|
|
int (*readRoutineP)(int conn,
|
|
|
|
void *fileHandle, size_t offset,
|
|
|
|
size_t nbytes,
|
|
|
|
size_t *bytesRead,
|
|
|
|
void *buffer),
|
2004-06-11 01:20:15 +04:00
|
|
|
size_t customDataOffset,
|
|
|
|
size_t customDataSize,
|
|
|
|
int messageCount,
|
2016-04-04 00:06:23 +03:00
|
|
|
const char **messages)
|
2004-06-11 01:20:15 +04:00
|
|
|
{
|
|
|
|
NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
|
2007-11-07 12:21:35 +03:00
|
|
|
|
2004-06-11 01:20:15 +04:00
|
|
|
#ifndef __GNUC__
|
|
|
|
#pragma unused(cmdLine)
|
|
|
|
#pragma unused(loadDirPath)
|
|
|
|
#pragma unused(uninitializedDataLength)
|
|
|
|
#pragma unused(NLMFileHandle)
|
|
|
|
#pragma unused(readRoutineP)
|
|
|
|
#pragma unused(customDataOffset)
|
|
|
|
#pragma unused(customDataSize)
|
|
|
|
#pragma unused(messageCount)
|
|
|
|
#pragma unused(messages)
|
|
|
|
#endif
|
|
|
|
|
2012-09-14 02:44:16 +04:00
|
|
|
/*
|
|
|
|
* Here we process our command line, post errors (to the error screen),
|
|
|
|
* perform initializations and anything else we need to do before being able
|
|
|
|
* to accept calls into us. If we succeed, we return non-zero and the NetWare
|
|
|
|
* Loader will leave us up, otherwise we fail to load and get dumped.
|
|
|
|
*/
|
2004-06-11 01:20:15 +04:00
|
|
|
gAllocTag = AllocateResourceTag(NLMHandle,
|
|
|
|
"<library-name> memory allocations",
|
|
|
|
AllocSignature);
|
|
|
|
|
2007-11-07 12:21:35 +03:00
|
|
|
if(!gAllocTag) {
|
2004-06-11 01:20:15 +04:00
|
|
|
OutputToScreen(errorScreen, "Unable to allocate resource tag for "
|
|
|
|
"library memory allocations.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gLibId = register_library(DisposeLibraryData);
|
|
|
|
|
2007-11-07 12:21:35 +03:00
|
|
|
if(gLibId < -1) {
|
2004-06-11 01:20:15 +04:00
|
|
|
OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gLibHandle = NLMHandle;
|
|
|
|
|
|
|
|
gLibLock = NXMutexAlloc(0, 0, &liblock);
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(!gLibLock) {
|
2004-06-11 01:20:15 +04:00
|
|
|
OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-09-14 02:44:16 +04:00
|
|
|
* Here we clean up any resources we allocated. Resource tags is a big part
|
|
|
|
* of what we created, but NetWare doesn't ask us to free those.
|
|
|
|
*/
|
2016-04-04 00:06:23 +03:00
|
|
|
void _NonAppStop(void)
|
2004-06-11 01:20:15 +04:00
|
|
|
{
|
|
|
|
(void) unregister_library(gLibId);
|
|
|
|
NXMutexFree(gLibLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-09-14 02:44:16 +04:00
|
|
|
* This function cannot be the first in the file for if the file is linked
|
|
|
|
* first, then the check-unload function's offset will be nlmname.nlm+0
|
|
|
|
* which is how to tell that there isn't one. When the check function is
|
|
|
|
* first in the linked objects, it is ambiguous. For this reason, we will
|
|
|
|
* put it inside this file after the stop function.
|
|
|
|
*
|
|
|
|
* Here we check to see if it's alright to ourselves to be unloaded. If not,
|
|
|
|
* we return a non-zero value. Right now, there isn't any reason not to allow
|
|
|
|
* it.
|
|
|
|
*/
|
2016-04-04 00:06:23 +03:00
|
|
|
int _NonAppCheckUnload(void)
|
2004-06-11 01:20:15 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetOrSetUpData(int id, libdata_t **appData,
|
2016-04-04 00:06:23 +03:00
|
|
|
libthreaddata_t **threadData)
|
2004-06-11 01:20:15 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
libdata_t *app_data;
|
|
|
|
libthreaddata_t *thread_data;
|
|
|
|
NXKey_t key;
|
|
|
|
NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
thread_data = (libthreaddata_t *) NULL;
|
|
|
|
|
2012-09-14 02:44:16 +04:00
|
|
|
/*
|
|
|
|
* Attempt to get our data for the application calling us. This is where we
|
|
|
|
* store whatever application-specific information we need to carry in
|
|
|
|
* support of calling applications.
|
|
|
|
*/
|
2004-06-11 01:20:15 +04:00
|
|
|
app_data = (libdata_t *) get_app_data(id);
|
|
|
|
|
2007-11-07 12:21:35 +03:00
|
|
|
if(!app_data) {
|
2012-09-14 02:44:16 +04:00
|
|
|
/*
|
|
|
|
* This application hasn't called us before; set up application AND
|
|
|
|
* per-thread data. Of course, just in case a thread from this same
|
|
|
|
* application is calling us simultaneously, we better lock our application
|
|
|
|
* data-creation mutex. We also need to recheck for data after we acquire
|
|
|
|
* the lock because WE might be that other thread that was too late to
|
|
|
|
* create the data and the first thread in will have created it.
|
|
|
|
*/
|
2004-06-11 01:20:15 +04:00
|
|
|
NXLock(gLibLock);
|
|
|
|
|
2016-12-14 03:29:44 +03:00
|
|
|
app_data = (libdata_t *) get_app_data(id);
|
|
|
|
if(!app_data) {
|
2018-04-14 23:42:04 +03:00
|
|
|
app_data = calloc(1, sizeof(libdata_t));
|
2004-06-11 01:20:15 +04:00
|
|
|
|
2007-11-07 12:21:35 +03:00
|
|
|
if(app_data) {
|
2004-06-11 01:20:15 +04:00
|
|
|
app_data->tenbytes = malloc(10);
|
|
|
|
app_data->lock = NXMutexAlloc(0, 0, &liblock);
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(!app_data->tenbytes || !app_data->lock) {
|
|
|
|
if(app_data->lock)
|
2004-06-11 01:20:15 +04:00
|
|
|
NXMutexFree(app_data->lock);
|
2018-10-03 01:56:29 +03:00
|
|
|
free(app_data->tenbytes);
|
2004-06-11 01:20:15 +04:00
|
|
|
free(app_data);
|
|
|
|
app_data = (libdata_t *) NULL;
|
|
|
|
err = ENOMEM;
|
|
|
|
}
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(app_data) {
|
2012-09-14 02:44:16 +04:00
|
|
|
/*
|
|
|
|
* Here we burn in the application data that we were trying to get
|
|
|
|
* by calling get_app_data(). Next time we call the first function,
|
|
|
|
* we'll get this data we're just now setting. We also go on here to
|
|
|
|
* establish the per-thread data for the calling thread, something
|
|
|
|
* we'll have to do on each application thread the first time
|
|
|
|
* it calls us.
|
|
|
|
*/
|
2004-06-11 01:20:15 +04:00
|
|
|
err = set_app_data(gLibId, app_data);
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(err) {
|
2018-10-03 01:56:29 +03:00
|
|
|
if(app_data->lock)
|
|
|
|
NXMutexFree(app_data->lock);
|
|
|
|
free(app_data->tenbytes);
|
2004-06-11 01:20:15 +04:00
|
|
|
free(app_data);
|
|
|
|
app_data = (libdata_t *) NULL;
|
|
|
|
err = ENOMEM;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* create key for thread-specific data... */
|
|
|
|
err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(err) /* (no more keys left?) */
|
2004-06-11 01:20:15 +04:00
|
|
|
key = -1;
|
2007-11-07 12:21:35 +03:00
|
|
|
|
2004-06-11 01:20:15 +04:00
|
|
|
app_data->perthreadkey = key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-07 12:21:35 +03:00
|
|
|
|
2004-06-11 01:20:15 +04:00
|
|
|
NXUnlock(gLibLock);
|
|
|
|
}
|
|
|
|
|
2007-11-07 12:21:35 +03:00
|
|
|
if(app_data) {
|
2004-06-11 01:20:15 +04:00
|
|
|
key = app_data->perthreadkey;
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(key != -1 /* couldn't create a key? no thread data */
|
2004-06-11 01:20:15 +04:00
|
|
|
&& !(err = NXKeyGetValue(key, (void **) &thread_data))
|
|
|
|
&& !thread_data) {
|
2012-09-14 02:44:16 +04:00
|
|
|
/*
|
|
|
|
* Allocate the per-thread data for the calling thread. Regardless of
|
|
|
|
* whether there was already application data or not, this may be the
|
|
|
|
* first call by a new thread. The fact that we allocation 20 bytes on
|
|
|
|
* a pointer is not very important, this just helps to demonstrate that
|
|
|
|
* we can have arbitrarily complex per-thread data.
|
|
|
|
*/
|
2008-09-06 09:29:05 +04:00
|
|
|
thread_data = malloc(sizeof(libthreaddata_t));
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(thread_data) {
|
2004-06-11 01:20:15 +04:00
|
|
|
thread_data->_errno = 0;
|
|
|
|
thread_data->twentybytes = malloc(20);
|
2007-11-07 12:21:35 +03:00
|
|
|
|
|
|
|
if(!thread_data->twentybytes) {
|
2004-06-11 01:20:15 +04:00
|
|
|
free(thread_data);
|
|
|
|
thread_data = (libthreaddata_t *) NULL;
|
|
|
|
err = ENOMEM;
|
|
|
|
}
|
2007-11-07 12:21:35 +03:00
|
|
|
|
2016-12-14 03:29:44 +03:00
|
|
|
err = NXKeySetValue(key, thread_data);
|
|
|
|
if(err) {
|
2004-06-11 01:20:15 +04:00
|
|
|
free(thread_data->twentybytes);
|
|
|
|
free(thread_data);
|
|
|
|
thread_data = (libthreaddata_t *) NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-07 12:21:35 +03:00
|
|
|
if(appData)
|
2004-06-11 01:20:15 +04:00
|
|
|
*appData = app_data;
|
|
|
|
|
2007-11-07 12:21:35 +03:00
|
|
|
if(threadData)
|
2004-06-11 01:20:15 +04:00
|
|
|
*threadData = thread_data;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-04-04 00:06:23 +03:00
|
|
|
int DisposeLibraryData(void *data)
|
2004-06-11 01:20:15 +04:00
|
|
|
{
|
2007-11-07 12:21:35 +03:00
|
|
|
if(data) {
|
2007-07-01 00:02:51 +04:00
|
|
|
void *tenbytes = ((libdata_t *) data)->tenbytes;
|
2007-11-07 12:21:35 +03:00
|
|
|
|
2015-03-11 19:41:01 +03:00
|
|
|
free(tenbytes);
|
2004-06-11 01:20:15 +04:00
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-04 00:06:23 +03:00
|
|
|
void DisposeThreadData(void *data)
|
2004-06-11 01:20:15 +04:00
|
|
|
{
|
2007-11-07 12:21:35 +03:00
|
|
|
if(data) {
|
2007-07-01 00:02:51 +04:00
|
|
|
void *twentybytes = ((libthreaddata_t *) data)->twentybytes;
|
2007-11-07 12:21:35 +03:00
|
|
|
|
2015-03-11 19:41:01 +03:00
|
|
|
free(twentybytes);
|
2004-06-11 01:20:15 +04:00
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
2007-02-28 08:15:56 +03:00
|
|
|
|
2007-07-01 00:02:51 +04:00
|
|
|
#else /* __NOVELL_LIBC__ */
|
|
|
|
/* For native CLib-based NLM seems we can do a bit more simple. */
|
|
|
|
#include <nwthread.h>
|
|
|
|
|
2016-12-14 01:34:59 +03:00
|
|
|
int main(void)
|
2007-07-01 00:02:51 +04:00
|
|
|
{
|
2012-09-14 02:44:16 +04:00
|
|
|
/* initialize any globals here... */
|
2007-07-01 00:02:51 +04:00
|
|
|
|
2012-09-14 02:44:16 +04:00
|
|
|
/* do this if any global initializing was done
|
|
|
|
SynchronizeStart();
|
|
|
|
*/
|
2016-12-14 01:34:59 +03:00
|
|
|
ExitThread(TSR_THREAD, 0);
|
2012-09-14 02:44:16 +04:00
|
|
|
return 0;
|
2007-07-01 00:02:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __NOVELL_LIBC__ */
|
|
|
|
|
2009-10-27 19:38:42 +03:00
|
|
|
#else /* NETWARE */
|
|
|
|
|
|
|
|
#ifdef __POCC__
|
|
|
|
# pragma warn(disable:2024) /* Disable warning #2024: Empty input file */
|
|
|
|
#endif
|
|
|
|
|
2007-02-28 18:10:20 +03:00
|
|
|
#endif /* NETWARE */
|