⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernelapi.c

📁 上一个上传的有问题,这个是好的。visopsys包括系统内核和GUI的全部SOURCE code ,还包括一些基本的docs文档。里面src子目录对应所有SOURCE code.对于想研究操作系统的朋
💻 C
📖 第 1 页 / 共 3 页
字号:
};static kernelFunctionIndex networkFunctionIndex[] = {  // Network functions (14000-14999 range)  { _fnum_networkDeviceGetCount, kernelNetworkDeviceGetCount,    0, PRIVILEGE_USER },  { _fnum_networkDeviceGet, kernelNetworkDeviceGet, 2, PRIVILEGE_USER },  { _fnum_networkInitialized, kernelNetworkInitialized, 0, PRIVILEGE_USER },  { _fnum_networkInitialize, kernelNetworkInitialize,    0, PRIVILEGE_SUPERVISOR },  { _fnum_networkShutdown, kernelNetworkShutdown, 0, PRIVILEGE_SUPERVISOR },  { _fnum_networkOpen, kernelNetworkOpen, 3, PRIVILEGE_USER },  { _fnum_networkClose, kernelNetworkClose, 1, PRIVILEGE_USER },  { _fnum_networkCount, kernelNetworkCount, 1, PRIVILEGE_USER },  { _fnum_networkRead, kernelNetworkRead, 3, PRIVILEGE_USER },  { _fnum_networkWrite, kernelNetworkWrite, 3, PRIVILEGE_USER },  { _fnum_networkPing, kernelNetworkPing, 4, PRIVILEGE_USER }};static kernelFunctionIndex miscFunctionIndex[] = {  // Miscellaneous functions (99000-99999 range)    { _fnum_fontGetDefault, kernelFontGetDefault, 1, PRIVILEGE_USER },  { _fnum_fontSetDefault, kernelFontSetDefault, 1, PRIVILEGE_USER },  { _fnum_fontLoad, kernelFontLoad, 4, PRIVILEGE_USER },  { _fnum_fontGetPrintedWidth, kernelFontGetPrintedWidth, 2, PRIVILEGE_USER },  { _fnum_imageLoad, kernelImageLoad, 4, PRIVILEGE_USER },  { _fnum_imageSave, kernelImageSave, 3, PRIVILEGE_USER },  { _fnum_shutdown, kernelShutdown, 2, PRIVILEGE_USER },  { _fnum_version, kernelVersion, 0, PRIVILEGE_USER },  { _fnum_encryptMD5, kernelEncryptMD5, 2, PRIVILEGE_USER },  { _fnum_lockGet, kernelLockGet, 1, PRIVILEGE_USER },  { _fnum_lockRelease, kernelLockRelease, 1, PRIVILEGE_USER },  { _fnum_lockVerify, kernelLockVerify, 1, PRIVILEGE_USER },  { _fnum_variableListCreate, kernelVariableListCreate, 1, PRIVILEGE_USER },  { _fnum_variableListDestroy, kernelVariableListDestroy, 1, PRIVILEGE_USER },  { _fnum_variableListGet, kernelVariableListGet, 4, PRIVILEGE_USER },  { _fnum_variableListSet, kernelVariableListSet, 3, PRIVILEGE_USER },  { _fnum_variableListUnset, kernelVariableListUnset, 2, PRIVILEGE_USER },  { _fnum_configurationReader, kernelConfigurationReader, 2, PRIVILEGE_USER },  { _fnum_configurationWriter, kernelConfigurationWriter, 2, PRIVILEGE_USER },  { _fnum_keyboardGetMaps, kernelKeyboardGetMaps, 2, PRIVILEGE_USER },  { _fnum_keyboardSetMap, kernelKeyboardSetMap, 1, PRIVILEGE_USER },  { _fnum_deviceTreeGetCount, kernelDeviceTreeGetCount, 0, PRIVILEGE_USER },  { _fnum_deviceTreeGetRoot, kernelDeviceTreeGetRoot, 1, PRIVILEGE_USER },  { _fnum_deviceTreeGetChild, kernelDeviceTreeGetChild, 2, PRIVILEGE_USER },  { _fnum_deviceTreeGetNext, kernelDeviceTreeGetNext, 1, PRIVILEGE_USER },  { _fnum_mouseLoadPointer, kernelMouseLoadPointer, 2, PRIVILEGE_USER },  { _fnum_mouseSwitchPointer, kernelMouseSwitchPointer, 1, PRIVILEGE_USER }};static kernelFunctionIndex *functionIndex[] = {  miscFunctionIndex,  textFunctionIndex,  diskFunctionIndex,  filesystemFunctionIndex,  fileFunctionIndex,  memoryFunctionIndex,  multitaskerFunctionIndex,  loaderFunctionIndex,  rtcFunctionIndex,  randomFunctionIndex,  environmentFunctionIndex,  graphicFunctionIndex,  windowFunctionIndex,  userFunctionIndex,  networkFunctionIndex};static int processCall(unsigned *argList){  int status = 0;  int argCount = 0;  unsigned functionNumber = 0;  kernelFunctionIndex *functionEntry = NULL;  int currentProc = 0;  int currentPriv = 0;  int (*functionPointer)();  // Check arg  if (argList == NULL)    {      kernelError(kernel_error, "No args supplied to API call");      return (status = ERR_NULLPARAMETER);    }  // How many parameters are there?  argCount = argList[0];  argCount--;  if (argCount > API_MAX_ARGS)    {      kernelError(kernel_error, "Illegal number of arguments (%u) to API "		  "call", argCount);      return (status = ERR_ARGUMENTCOUNT);    }  // Which function number are we being asked to call?  functionNumber = argList[1];  if ((functionNumber / 1000) == 99)    // 'misc' functions are in spot 0    functionEntry = &functionIndex[0][functionNumber % 1000];  else    functionEntry =      &functionIndex[functionNumber / 1000][functionNumber % 1000];  // Is there such a function?  if ((functionEntry == NULL) ||      (functionEntry->functionNumber != functionNumber))    {      kernelError(kernel_error, "No such API function %d", functionNumber);      return (status = ERR_NOSUCHFUNCTION);    }  // Do the number of args match the number expected?  if (argCount != functionEntry->argCount)    {      kernelError(kernel_error, "Incorrect number of arguments (%d) to API "		  "function %u (%d)", argCount, functionEntry->functionNumber,		  functionEntry->argCount);      return (status = ERR_ARGUMENTCOUNT);    }  // Does the caller have the adequate privilege level to call this  // function?  currentProc = kernelMultitaskerGetCurrentProcessId();  currentPriv = kernelMultitaskerGetProcessPrivilege(currentProc);  if (currentPriv < 0)    {      kernelError(kernel_error, "Couldn't determine current privilege level "		  "for call to API function %d",		  functionEntry->functionNumber);      return (status = ERR_BUG);    }  else if (currentPriv > functionEntry->privilege)    {      kernelError(kernel_error, "Insufficient privilege to invoke API "		  "function %d", functionEntry->functionNumber);      return (status = ERR_PERMISSION);    }  // Make 'functionPointer' equal the address of the requested kernel  // function.  functionPointer = functionEntry->functionPointer;    // Call the function, with the appropriate number of arguments.  switch(argCount)    {    case 0:      return (functionPointer());    case 1:      return (functionPointer(argList[2]));    case 2:      return (functionPointer(argList[2], argList[3]));    case 3:      return (functionPointer(argList[2], argList[3], argList[4]));    case 4:      return (functionPointer(argList[2], argList[3], argList[4], 			      argList[5]));    case 5:      return (functionPointer(argList[2], argList[3], argList[4], 			      argList[5], argList[6]));    case 6:      return (functionPointer(argList[2], argList[3], argList[4], 			      argList[5], argList[6], argList[7]));    case 7:      return (functionPointer(argList[2], argList[3], argList[4], 			      argList[5], argList[6], argList[7],			      argList[8]));    case 8:      return (functionPointer(argList[2], argList[3], argList[4], 			      argList[5], argList[6], argList[7],			      argList[8], argList[9]));    case 9:      return (functionPointer(argList[2], argList[3], argList[4], 			      argList[5], argList[6], argList[7],			      argList[8], argList[9], argList[10]));    default:      return (status = ERR_ARGUMENTCOUNT);    }}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  Below here, the functions are exported for external use////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int kernelApi(unsigned CS, unsigned argStart){  // This is the initial entry point for the kernel's API.  This  // function will be first the recipient of all calls to the global  // call gate.  This function will pass a pointer to the rest of the  // arguments to the processCall function that does all the real work.  // This funcion does the far return.  static int status = 0;  static void *argument = 0; 	  kernelProcessorApiEnter();  // We get a pointer to the calling function's parameters differently  // depending on whether there was a privilege level switch.  Find  // out by checking the privilege of the CS register pushed as  // part of the return address.  if (CS & PRIVILEGE_USER)    // The caller is unprivileged, so its stack pointer is on our    // stack just beyond IP, CS, and the flags    argument = (void *) argStart;  else    // Privileged.  Same as above, but the first argument is on *our*    // stack.    argument = &argStart;  status = processCall(argument);  kernelProcessorApiExit(status);  // Make the compiler happy -- never reached  return (0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -