| 1 | #define INCL_LONGLONG
|
|---|
| 2 | #define INCL_DOS
|
|---|
| 3 | #define INCL_DOSPROCESS
|
|---|
| 4 | #define INCL_DOSPROFILE
|
|---|
| 5 | #define INCL_DOSMISC
|
|---|
| 6 | #define INCL_DOSMODULEMGR
|
|---|
| 7 | //_SMB_H
|
|---|
| 8 | #include <os2.h>
|
|---|
| 9 | #include <stdio.h>
|
|---|
| 10 | #include <stdlib.h>
|
|---|
| 11 | #include <errno.h>
|
|---|
| 12 | #include <types.h>
|
|---|
| 13 | #include <InnoTekLIBC/backend.h>
|
|---|
| 14 | #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
|
|---|
| 15 | #include "local.h"
|
|---|
| 16 | #include "xfile.h"
|
|---|
| 17 | #include "pstring.h"
|
|---|
| 18 | #include "debug.h"
|
|---|
| 19 |
|
|---|
| 20 | APIRET (APIENTRY * xDosPerfSysCall)(ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL;
|
|---|
| 21 | APIRET (APIENTRY * xDosQuerySysState)(ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL;
|
|---|
| 22 | HMODULE doscalls = 0;
|
|---|
| 23 |
|
|---|
| 24 | int os2_init(void)
|
|---|
| 25 | {
|
|---|
| 26 | HMODULE dllhandle;
|
|---|
| 27 | int rc = 0;
|
|---|
| 28 | char failname[CCHMAXPATH+1];
|
|---|
| 29 | if (doscalls == 0)
|
|---|
| 30 | {
|
|---|
| 31 | rc = DosLoadModule(failname, sizeof(failname), "DOSCALL1", &doscalls);
|
|---|
| 32 | if (rc)
|
|---|
| 33 | {
|
|---|
| 34 | DEBUG(0,("Cant load DOSCALL1: %s (%d)\n", failname, rc));
|
|---|
| 35 | return rc;
|
|---|
| 36 | }
|
|---|
| 37 | rc = DosQueryProcAddr(doscalls, 976, NULL, (PFN *)&xDosPerfSysCall);
|
|---|
| 38 | if (rc)
|
|---|
| 39 | {
|
|---|
| 40 | DEBUG(0,("Cant load xDosPerfSysCall (%d)\n", rc));
|
|---|
| 41 | xDosPerfSysCall = NULL;
|
|---|
| 42 | }
|
|---|
| 43 | rc = DosQueryProcAddr(doscalls, 368, NULL, (PFN *)&xDosQuerySysState);
|
|---|
| 44 | if (rc)
|
|---|
| 45 | {
|
|---|
| 46 | DEBUG(0,("Cant load xDosQuerySysState (%d)\n", rc));
|
|---|
| 47 | xDosQuerySysState = NULL;
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | return 0;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | int os2_ftruncate(int fd, off_t size)
|
|---|
| 54 | {
|
|---|
| 55 | // We call there __libc_Back_ioFileSizeSet directly instead of
|
|---|
| 56 | // ftruncate to force it not to zero expanding files to optimize
|
|---|
| 57 | // samba performance when copying files
|
|---|
| 58 | int rc = __libc_Back_ioFileSizeSet(fd, size, 0);
|
|---|
| 59 | if (rc < 0)
|
|---|
| 60 | {
|
|---|
| 61 | errno = -rc;
|
|---|
| 62 | return -1;
|
|---|
| 63 | }
|
|---|
| 64 | return 0;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | #define CMD_KI_RDCNT (0x63)
|
|---|
| 68 |
|
|---|
| 69 | typedef struct _CPUUTIL {
|
|---|
| 70 | ULONG ulTimeLow; /* Low 32 bits of time stamp */
|
|---|
| 71 | ULONG ulTimeHigh; /* High 32 bits of time stamp */
|
|---|
| 72 | ULONG ulIdleLow; /* Low 32 bits of idle time */
|
|---|
| 73 | ULONG ulIdleHigh; /* High 32 bits of idle time */
|
|---|
| 74 | ULONG ulBusyLow; /* Low 32 bits of busy time */
|
|---|
| 75 | ULONG ulBusyHigh; /* High 32 bits of busy time */
|
|---|
| 76 | ULONG ulIntrLow; /* Low 32 bits of interrupt time */
|
|---|
| 77 | ULONG ulIntrHigh; /* High 32 bits of interrupt time */
|
|---|
| 78 | } CPUUTIL;
|
|---|
| 79 |
|
|---|
| 80 | // very simple random data gatherer derived from openssl
|
|---|
| 81 | void os2_randget(char * buffer, int length)
|
|---|
| 82 | {
|
|---|
| 83 | QWORD qwTime;
|
|---|
| 84 | ULONG SysVars[QSV_FOREGROUND_PROCESS];
|
|---|
| 85 | int done = 0;
|
|---|
| 86 |
|
|---|
| 87 | if (!buffer || length <= 0)
|
|---|
| 88 | {
|
|---|
| 89 | return;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | DosTmrQueryTime(&qwTime);
|
|---|
| 93 | memcpy(buffer, &qwTime, sizeof(qwTime) > length ? length : sizeof(qwTime));
|
|---|
| 94 | done += sizeof(qwTime);
|
|---|
| 95 | if (done >= length)
|
|---|
| 96 | {
|
|---|
| 97 | return;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | if (xDosPerfSysCall)
|
|---|
| 101 | {
|
|---|
| 102 | CPUUTIL util;
|
|---|
| 103 | if (xDosPerfSysCall(CMD_KI_RDCNT, (ULONG)&util, 0, 0) == 0)
|
|---|
| 104 | {
|
|---|
| 105 | memcpy(buffer + done, &util, sizeof(util) > length - done ? length - done : sizeof(util));
|
|---|
| 106 | done += sizeof(util);
|
|---|
| 107 | if (done >= length)
|
|---|
| 108 | {
|
|---|
| 109 | return;
|
|---|
| 110 | }
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | #if 0
|
|---|
| 115 | if (xDosQuerySysState)
|
|---|
| 116 | {
|
|---|
| 117 | char *tmp = (char *)malloc(256 * 1024);
|
|---|
| 118 | if (tmp)
|
|---|
| 119 | {
|
|---|
| 120 | if (xDosQuerySysState(0x1F, 0, 0, 0, tmp, 256 * 1024) == 0)
|
|---|
| 121 | {
|
|---|
| 122 | memcpy(buffer + done, tmp, 256 * 1024 > length - done ? length - done : 256 * 1024);
|
|---|
| 123 | done += 256 * 1024;
|
|---|
| 124 | }
|
|---|
| 125 | free(tmp);
|
|---|
| 126 | }
|
|---|
| 127 | }
|
|---|
| 128 | if (done >= length)
|
|---|
| 129 | {
|
|---|
| 130 | return;
|
|---|
| 131 | }
|
|---|
| 132 | #endif
|
|---|
| 133 |
|
|---|
| 134 | DosQuerySysInfo(1, QSV_FOREGROUND_PROCESS, SysVars, sizeof(SysVars));
|
|---|
| 135 | memcpy(buffer + done, SysVars, sizeof(SysVars) > length - done ? length - done : sizeof(SysVars));
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | #include <InnoTekLIBC/tcpip.h>
|
|---|
| 139 | #undef close
|
|---|
| 140 | int debug_close(char * file, char * function, int line, int h )
|
|---|
| 141 | {
|
|---|
| 142 | int os2socket = -1;
|
|---|
| 143 | PLIBCSOCKETFH pFHSocket = __libc_TcpipFH(h);
|
|---|
| 144 | if (pFHSocket) os2socket = pFHSocket->iSocket;
|
|---|
| 145 | DEBUG(0,("close(%d (%d)) on %s:%s(%d)\n", h, os2socket, file, function, line));
|
|---|
| 146 | return close(h);
|
|---|
| 147 | }
|
|---|